diff --git a/src/main.rs b/src/main.rs index b419990..79272a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,21 +34,20 @@ impl EventHandler for Handler { } }; - let (http, channel_id, user_id) = { + let (user_id, sender) = { let data = ctx.data.read().await; - let http = data.get::().unwrap().to_owned(); - let channel_id = data.get::().unwrap().to_owned(); let user_id = data.get::().unwrap().to_owned(); + let sender = data.get::().unwrap().to_owned(); - (http, channel_id, user_id) + (user_id, sender) }; - - // if user_id != msg.author.id && !msg.author.bot { - // send_message(&http, &channel_id, &format!("{}: {}", nick, msg.content)) - // .await - // .unwrap(); - // } + + if user_id != msg.author.id && !msg.author.bot { + send_irc_message(&sender, &format!("<{}> {}", nick, msg.content)) + .await + .unwrap(); + } } async fn ready(&self, ctx: Context, info: Ready) { @@ -100,14 +99,12 @@ async fn main() -> anyhow::Result<()> { ..Config::default() }; - let mut irc_client = IrcClient::from_config(config).await?; + let irc_client = IrcClient::from_config(config).await?; let http = discord_client.cache_and_http.http.clone(); { let mut data = discord_client.data.write().await; - data.insert::(http.clone()); - data.insert::(channel_id); data.insert::(irc_client.sender()); } @@ -119,6 +116,11 @@ async fn main() -> anyhow::Result<()> { Ok(()) } +async fn send_irc_message(sender: &Sender, content: &str) -> anyhow::Result<()> { + sender.send_privmsg("#no-normies", content)?; + Ok(()) +} + async fn irc_loop( mut client: IrcClient, http: Arc, @@ -128,7 +130,7 @@ async fn irc_loop( let mut stream = client.stream()?; while let Some(orig_message) = stream.next().await.transpose()? { print!("{}", orig_message); - if let Command::PRIVMSG(ref channel, ref message) = orig_message.command { + if let Command::PRIVMSG(_, ref message) = orig_message.command { let nickname = orig_message.source_nickname().unwrap(); channel_id .say(&http, format!("{}: {}", nickname, message))