Implement PART update, check, and ban

This commit is contained in:
Yash Karandikar 2022-07-18 20:23:09 -05:00
parent ae984af15b
commit 603b7ec20b
Signed by: karx
GPG key ID: A794DA2529474BA5

View file

@ -59,7 +59,9 @@ async fn main() -> anyhow::Result<()> {
match message.command {
Command::JOIN(ref channel, _, _) => {
let users = unwrap_or_continue!(channel_users.get_mut(channel));
users.insert(nick.to_string(), Status::TimeoutCount(0));
if !users.contains_key(nick) {
users.insert(nick.to_string(), Status::TimeoutCount(0));
}
}
Command::PRIVMSG(ref channel, ref message) => {
if message.starts_with("!dbg") {
@ -69,6 +71,26 @@ async fn main() -> anyhow::Result<()> {
)?;
}
}
Command::PART(ref channel, Some(ref message)) => {
if message == &conf.quit_message {
let users = unwrap_or_continue!(channel_users.get_mut(channel));
let user = unwrap_or_continue!(users.get_mut(nick));
*user = match user {
Status::TimeoutCount(count) => Status::TimeoutCount(*count + 1),
_ => *user,
};
if let Status::TimeoutCount(count) = user {
if *count > conf.timeout_limit.unwrap_or(1) {
let mode = Mode::Plus(ChannelMode::Ban, Some(format!("{}!*@*", nick)));
client.send_mode(channel, &[mode])?;
*user = Status::Banned;
}
}
}
}
_ => {}
}
}