Skip to content

Commit

Permalink
handle notice in server
Browse files Browse the repository at this point in the history
  • Loading branch information
casperstorm authored and tarkah committed Jul 6, 2023
1 parent 3a59edc commit 71dabe9
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion data/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn source(message: Encoded, our_nick: NickRef) -> Option<Source> {
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 {
Expand All @@ -179,6 +179,27 @@ fn source(message: Encoded, our_nick: NickRef) -> Option<Source> {
_ => 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(_, _)
Expand Down

0 comments on commit 71dabe9

Please sign in to comment.