aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/keepnick.rs
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-03-12 16:02:51 +0100
committerJokler <jokler.contact@gmail.com>2018-03-12 16:02:51 +0100
commit909cabe9280722e43c5fb283f768051bb85e1890 (patch)
tree506ac34b7e22cdb95568cef9e649ee64cb3b0fdb /src/plugins/keepnick.rs
parent15e855ddecfdac31ddda26b12fcfd1a142a0ec21 (diff)
parent8e40e919aca8b8592be43e2c5bbcc0717bf14a6b (diff)
downloadfrippy-909cabe9280722e43c5fb283f768051bb85e1890.tar.gz
frippy-909cabe9280722e43c5fb283f768051bb85e1890.zip
Merge branch 'dev'
Diffstat (limited to 'src/plugins/keepnick.rs')
-rw-r--r--src/plugins/keepnick.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/plugins/keepnick.rs b/src/plugins/keepnick.rs
new file mode 100644
index 0000000..58ac167
--- /dev/null
+++ b/src/plugins/keepnick.rs
@@ -0,0 +1,70 @@
+use irc::client::prelude::*;
+
+use plugin::*;
+
+use error::FrippyError;
+use error::ErrorKind as FrippyErrorKind;
+use failure::ResultExt;
+
+#[derive(PluginName, Default, Debug)]
+pub struct KeepNick;
+
+impl KeepNick {
+ pub fn new() -> KeepNick {
+ KeepNick {}
+ }
+
+ fn check_nick(&self, client: &IrcClient, leaver: &str) -> ExecutionStatus {
+ let cfg_nick = match client.config().nickname {
+ Some(ref nick) => nick.clone(),
+ None => return ExecutionStatus::Done,
+ };
+
+ if leaver != cfg_nick {
+ return ExecutionStatus::Done;
+ }
+
+ let client_nick = client.current_nickname();
+
+ if client_nick != cfg_nick {
+ info!("Trying to switch nick from {} to {}", client_nick, cfg_nick);
+ match client
+ .send(Command::NICK(cfg_nick))
+ .context(FrippyErrorKind::Connection)
+ {
+ Ok(_) => ExecutionStatus::Done,
+ Err(e) => ExecutionStatus::Err(e.into()),
+ }
+ } else {
+ ExecutionStatus::Done
+ }
+ }
+}
+
+impl Plugin for KeepNick {
+ fn execute(&self, client: &IrcClient, message: &Message) -> ExecutionStatus {
+ match message.command {
+ Command::QUIT(ref nick) => {
+ self.check_nick(client, &nick.clone().unwrap_or_else(String::new))
+ }
+ _ => ExecutionStatus::Done,
+ }
+ }
+
+ fn execute_threaded(&self, _: &IrcClient, _: &Message) -> Result<(), FrippyError> {
+ panic!("Tell should not use threading")
+ }
+
+ fn command(&self, client: &IrcClient, command: PluginCommand) -> Result<(), FrippyError> {
+ Ok(client
+ .send_notice(
+ &command.source,
+ "This Plugin does not implement any commands.",
+ )
+ .context(FrippyErrorKind::Connection)?)
+ }
+
+ fn evaluate(&self, _: &IrcClient, _: PluginCommand) -> Result<String, String> {
+ Err(String::from("This Plugin does not implement any commands."))
+ }
+}