commit 85c6ff1a8e6d5678135a269faff7d913b3895ab8
Author: Daniel Pérez <steew@psi.my.domain>
Date: Wed Jan 07 19:56:02 2026 +0000
diff --git a/src/main.rs b/src/main.rs
index e559a45..8509a0e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -569 +566 @@ async fn main() {
- let webhook = Webhook::from_url(&shared_http,
- "").await.unwrap();
-
@@ -8913 +8628 @@ async fn main() {
- assoc.bridge_assoc.insert(ChannelId::new(chid), ircs);
+ assoc.bridge_assoc.insert(ChannelId::new(chid), ircs.clone());
+
+ // find the webhook urls now
+ match ini.section(Some("webhook")) {
+ Some(section_contents) => {
+ for (chid_str, webhook_url) in section_contents.iter() {
+ let chid = u64::from_str(chid_str).expect("Channel ID is not valid! {chid_str}");
+ let webhook_url = String::from_str(webhook_url).expect("Webhook URL is not valid! {webhook_url}");
+ assoc.chid_webhook_assoc.insert(ChannelId::new(chid), webhook_url);
+ }
+ },
+ None => { panic!("Expected a [webhook] section with webhook associations.") },
+ }
+
+ println!("Webhooks:");
+ println!("{:?}", assoc.chid_webhook_assoc.keys());
@@ -10410 +11611 @@ async fn main() {
- webhook,
+
+ loop {}
}
diff --git a/src/relay.rs b/src/relay.rs
index b6ebad5..ab7048c 100644
--- a/src/relay.rs
+++ b/src/relay.rs
@@ -207 +207 @@ pub enum RelayDirection {
pub struct RelayMessage {
- pub author: String,
+ pub author: String
}
pub struct MessageBuffer {
@@ -466 +4628 @@ pub struct RelayAssoc {
}
+impl RelayAssoc {
+ pub fn find_target(&self, source: RelayDirection) -> RelayDirection {
+ match source {
+ RelayDirection::IRC2DIS(chan) => {
+ for (chid, chan_vec) in self.bridge_assoc.iter() {
+ for c in chan_vec.iter() {
+ if c.eq_ignore_ascii_case(&chan) { return RelayDirection::DIS2IRC(*chid) };
+ }
+ }
+ return RelayDirection::INVALID;
+ },
+ RelayDirection::DIS2IRC(chan) => {
+ if let Some(target) = self.bridge_assoc.get(&chan) {
+ let irc_target = target.first().unwrap();
+ return RelayDirection::IRC2DIS(irc_target.clone());
+ } else { return RelayDirection::INVALID }
+ },
+ _ => { panic!("Invalid source of message! {source:?}") }
+ }
+ }
+}
+
impl Default for RelayAssoc {
@@ -867 +1086 @@ pub async fn relay_consumer(
- webhook: Webhook,
) {
@@ -10619 +12736 @@ pub async fn relay_consumer(
- let builder = ExecuteWebhook::new().content(pending.contents).username(pending.author);
- webhook.execute(&http, false, builder).await.expect("Could not execute webhook.");
+ let target = assoc.find_target(RelayDirection::IRC2DIS(chan));
+ match target {
+ RelayDirection::DIS2IRC(t) => {
+ let webhook = Webhook::from_url(&http, assoc.chid_webhook_assoc.get(&t).expect("Expected a webhook url for channel {t.get()}")).await.unwrap();
+ let builder = ExecuteWebhook::new().content(pending.contents).username(pending.author);
+ webhook.execute(&http, false, builder).await.expect("Could not execute webhook.");
+ },
+ _ => { panic!("Found no target to send the message to!") }
+ }
+ unpingable_name.push(char::from_u32(0x03).unwrap());
+ unpingable_name.push_str("04");
+ unpingable_name.push(char::from_u32(0x03).unwrap());
- let response = format!("<{}>: {}", unpingable_name, pending.contents);
- sender.send_privmsg("##steew", response).unwrap();
+ let target = assoc.find_target(RelayDirection::DIS2IRC(chan));
+
+ match target {
+ RelayDirection::IRC2DIS(t) => {
+ let response = format!("<{}>: {}", unpingable_name, pending.contents);
+ sender.send_privmsg(t, response).unwrap();
+ },
+ _ => { panic!("Found no target to send the message to!") }
+ }