From 71dabe96cc8939b8acc4d679de88c6dda7d33d14 Mon Sep 17 00:00:00 2001 From: Casper Rogild Storm Date: Thu, 6 Jul 2023 22:57:49 +0200 Subject: [PATCH] handle notice in server --- data/src/message.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/data/src/message.rs b/data/src/message.rs index adc15ab3..182b9a7c 100644 --- a/data/src/message.rs +++ b/data/src/message.rs @@ -158,7 +158,7 @@ fn source(message: Encoded, our_nick: NickRef) -> Option { let channel = params.get(1)?.clone(); Some(Source::Channel(channel, Sender::Server)) } - proto::Command::PRIVMSG(target, text) | proto::Command::NOTICE(target, text) => { + proto::Command::PRIVMSG(target, text) => { let is_action = is_action(&text); let sender = |user| { if is_action { @@ -179,6 +179,27 @@ fn source(message: Encoded, our_nick: NickRef) -> Option { _ => None, } } + proto::Command::NOTICE(target, text) => { + let is_action = is_action(&text); + let sender = |user| { + if is_action { + Sender::Action + } else { + Sender::User(user) + } + }; + + match (target.is_channel_name(), user) { + (true, Some(user)) => Some(Source::Channel(target, sender(user))), + (false, Some(user)) => { + let target = User::try_from(target.as_str()).ok()?; + + (target.nickname() == our_nick) + .then(|| Source::Query(user.nickname().to_owned(), sender(user))) + } + _ => Some(Source::Server), + } + } // Server proto::Command::SANICK(_, _)