Send MODE before joining any channels

This commit is contained in:
Yash Karandikar 2021-11-03 17:38:00 -05:00
parent 077dfe3cb0
commit 97e1d562b8
Signed by: karx
GPG key ID: A794DA2529474BA5

View file

@ -29,6 +29,7 @@ pub enum Command {
USER(String, String, String, String),
NICK(String),
JOIN(String),
MODE(String, Option<String>),
OTHER(String),
}
@ -77,6 +78,9 @@ impl Client {
}
let config = self.config.clone();
if config.mode != "" {
self.write_command(Command::MODE(config.username, Some(config.mode)))?;
}
for channel in config.channels.iter() {
self.write_command(Command::JOIN(channel.to_string()))?;
}
@ -145,6 +149,17 @@ impl Client {
let formatted = format!("JOIN {}", channel);
Cow::Owned(formatted) as Cow<str>
}
MODE(target, mode) => {
let formatted = {
if let Some(mode) = mode {
format!("MODE {} {}", target, mode)
} else {
format!("MODE {}", target)
}
};
Cow::Owned(formatted) as Cow<str>
}
OTHER(_) => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,