diff options
| author | Jokler <jokler.contact@gmail.com> | 2018-02-12 19:16:59 +0100 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2018-02-12 19:16:59 +0100 |
| commit | da5c2c8e4893bfb095a8e2122b943c4dca61c41d (patch) | |
| tree | 3bf1e64c4a128e6b0cb5d5172daf1e3398406715 /src/plugins/keepnick.rs | |
| parent | ddf42bc0292b0befe2b2f47f3284d9ffeaf6f4b4 (diff) | |
| download | frippy-da5c2c8e4893bfb095a8e2122b943c4dca61c41d.tar.gz frippy-da5c2c8e4893bfb095a8e2122b943c4dca61c41d.zip | |
Replace is_allowed with a single-threaded execute function
The old execute got renamed to exeute_threaded.
Diffstat (limited to 'src/plugins/keepnick.rs')
| -rw-r--r-- | src/plugins/keepnick.rs | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/plugins/keepnick.rs b/src/plugins/keepnick.rs index 4a40e8f..e973769 100644 --- a/src/plugins/keepnick.rs +++ b/src/plugins/keepnick.rs @@ -11,47 +11,47 @@ impl KeepNick { KeepNick {} } - fn check_nick(&self, server: &IrcClient, leaver: &str) -> Result<(), IrcError> { - let cfg_nick = match server.config().nickname { + fn check_nick(&self, client: &IrcClient, leaver: &str) -> ExecutionStatus { + let cfg_nick = match client.config().nickname { Some(ref nick) => nick.clone(), - None => return Ok(()), + None => return ExecutionStatus::Done, }; if leaver != cfg_nick { - return Ok(()); + return ExecutionStatus::Done; } - let server_nick = server.current_nickname(); + let client_nick = client.current_nickname(); - if server_nick != cfg_nick { - info!("Trying to switch nick from {} to {}", server_nick, cfg_nick); - server.send(Command::NICK(cfg_nick)) + if client_nick != cfg_nick { + info!("Trying to switch nick from {} to {}", client_nick, cfg_nick); + match client.send(Command::NICK(cfg_nick)) { + Ok(_) => ExecutionStatus::Done, + Err(e) => ExecutionStatus::Err(e), + } } else { - Ok(()) + ExecutionStatus::Done } } } impl Plugin for KeepNick { - fn is_allowed(&self, _: &IrcClient, message: &Message) -> bool { - match message.command { - Command::QUIT(_) => true, - _ => false, - } - } - - fn execute(&self, server: &IrcClient, message: &Message) -> Result<(), IrcError> { + fn execute(&self, client: &IrcClient, message: &Message) -> ExecutionStatus { match message.command { Command::QUIT(ref nick) => { - self.check_nick(server, &nick.clone().unwrap_or_else(|| String::new())) + self.check_nick(client, &nick.clone().unwrap_or_else(String::new)) } - _ => Ok(()), + _ => ExecutionStatus::Done, } } - fn command(&self, server: &IrcClient, command: PluginCommand) -> Result<(), IrcError> { - server.send_notice(&command.source, + fn execute_threaded(&self, _: &IrcClient, _: &Message) -> Result<(), IrcError> { + panic!("Tell should not use threading") + } + + fn command(&self, client: &IrcClient, command: PluginCommand) -> Result<(), IrcError> { + client.send_notice(&command.source, "This Plugin does not implement any commands.") } |
