forked from karx/dircord
Refactor if-let chain and support NOTICEs
This commit is contained in:
parent
f5705ed296
commit
d547d12925
|
@ -100,7 +100,9 @@ pub async fn irc_loop(
|
|||
if option_env!("DIRCORD_POLARIAN_MODE").is_some() {
|
||||
nickname = "polarbear";
|
||||
}
|
||||
if let Command::PRIVMSG(ref channel, ref message) = orig_message.command {
|
||||
match orig_message.command {
|
||||
Command::PRIVMSG(ref channel, ref message)
|
||||
| Command::NOTICE(ref channel, ref message) => {
|
||||
let channel_id = ChannelId::from(*unwrap_or_continue!(mapping.get(channel)));
|
||||
|
||||
if channels_cache.is_none() || guild.is_none() || emoji_cache.is_empty() {
|
||||
|
@ -168,7 +170,8 @@ pub async fn irc_loop(
|
|||
message: format!("<{nickname}>, {computed}"),
|
||||
})?;
|
||||
}
|
||||
} else if let Command::JOIN(ref channel, _, _) = orig_message.command {
|
||||
}
|
||||
Command::JOIN(ref channel, _, _) => {
|
||||
let channel_id = ChannelId::from(*unwrap_or_continue!(mapping.get(channel)));
|
||||
let users = unwrap_or_continue!(channel_users.get_mut(channel));
|
||||
|
||||
|
@ -179,7 +182,8 @@ pub async fn irc_loop(
|
|||
http: http.clone(),
|
||||
message: format!("*{nickname}* has joined the channel"),
|
||||
})?;
|
||||
} else if let Command::PART(ref channel, ref reason) = orig_message.command {
|
||||
}
|
||||
Command::PART(ref channel, ref reason) => {
|
||||
let users = unwrap_or_continue!(channel_users.get_mut(channel));
|
||||
let channel_id = ChannelId::from(*unwrap_or_continue!(mapping.get(channel)));
|
||||
let pos = unwrap_or_continue!(users.iter().position(|u| u == nickname));
|
||||
|
@ -193,7 +197,8 @@ pub async fn irc_loop(
|
|||
http: http.clone(),
|
||||
message: format!("*{nickname}* has quit ({reason})"),
|
||||
})?;
|
||||
} else if let Command::QUIT(ref reason) = orig_message.command {
|
||||
}
|
||||
Command::QUIT(ref reason) => {
|
||||
for (channel, users) in &mut channel_users {
|
||||
let channel_id = ChannelId::from(*unwrap_or_continue!(mapping.get(channel)));
|
||||
let pos = unwrap_or_continue!(users.iter().position(|u| u == nickname));
|
||||
|
@ -208,7 +213,8 @@ pub async fn irc_loop(
|
|||
message: format!("*{nickname}* has quit ({reason})"),
|
||||
})?;
|
||||
}
|
||||
} else if let Command::NICK(ref new_nick) = orig_message.command {
|
||||
}
|
||||
Command::NICK(ref new_nick) => {
|
||||
for (channel, users) in &mut channel_users {
|
||||
let channel_id = ChannelId::from(*unwrap_or_continue!(mapping.get(channel)));
|
||||
let pos = unwrap_or_continue!(users.iter().position(|u| u == nickname));
|
||||
|
@ -221,11 +227,13 @@ pub async fn irc_loop(
|
|||
message: format!("*{nickname}* is now known as *{new_nick}*"),
|
||||
})?;
|
||||
}
|
||||
} else if let Command::TOPIC(ref channel, ref topic) = orig_message.command {
|
||||
}
|
||||
Command::TOPIC(ref channel, ref topic) => {
|
||||
let topic = unwrap_or_continue!(topic.as_ref());
|
||||
let channel_id = ChannelId::from(*unwrap_or_continue!(mapping.get(channel)));
|
||||
channel_id.edit(&http, |c| c.topic(topic)).await?;
|
||||
} else if let Command::KICK(ref channel, ref user, ref reason) = orig_message.command {
|
||||
}
|
||||
Command::KICK(ref channel, ref user, ref reason) => {
|
||||
let channel_id = ChannelId::from(*unwrap_or_continue!(mapping.get(channel)));
|
||||
let reason = reason.as_deref().unwrap_or("None");
|
||||
|
||||
|
@ -235,6 +243,8 @@ pub async fn irc_loop(
|
|||
message: format!("*{nickname}* has kicked *{user}* ({reason})"),
|
||||
})?;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue