summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2017-12-06 03:45:10 +0100
committerJokler <jokler.contact@gmail.com>2017-12-06 03:45:10 +0100
commitf716ecd319977aea7773dc689592fc8193c609f1 (patch)
treee8e96d83457d1d2a30e7ae93ac8a8f562874fdce /src/plugins
parent413f5d96e9fe4e990e5cd485abe828e0fb5c7ed4 (diff)
downloadfrippy-f716ecd319977aea7773dc689592fc8193c609f1.tar.gz
frippy-f716ecd319977aea7773dc689592fc8193c609f1.zip
Add KeepNick plugin
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/keepnick.rs51
-rw-r--r--src/plugins/mod.rs2
2 files changed, 53 insertions, 0 deletions
diff --git a/src/plugins/keepnick.rs b/src/plugins/keepnick.rs
new file mode 100644
index 0000000..5f5d92c
--- /dev/null
+++ b/src/plugins/keepnick.rs
@@ -0,0 +1,51 @@
+use irc::client::prelude::*;
+use irc::error::Error as IrcError;
+
+use plugin::*;
+
+#[derive(PluginName, Debug)]
+pub struct KeepNick;
+
+impl KeepNick {
+ pub fn new() -> KeepNick {
+ KeepNick {}
+ }
+
+ fn check_nick(&self, server: &IrcServer) -> Result<(), IrcError> {
+ let cfg_nick = match server.config().nickname {
+ Some(ref nick) => nick.clone(),
+ None => return Ok(()),
+ };
+
+ let server_nick = server.current_nickname();
+
+ if server_nick != cfg_nick {
+ info!("Trying to switch nick from {} to {}", server_nick, cfg_nick);
+ server.send(Command::NICK(cfg_nick))
+
+ } else {
+ Ok(())
+ }
+ }
+}
+
+impl Plugin for KeepNick {
+ fn is_allowed(&self, _: &IrcServer, message: &Message) -> bool {
+ match message.command {
+ Command::QUIT(_) => true,
+ _ => false,
+ }
+ }
+
+ fn execute(&self, server: &IrcServer, _: &Message) -> Result<(), IrcError> {
+ self.check_nick(server)
+ }
+
+ fn command(&self, server: &IrcServer, command: PluginCommand) -> Result<(), IrcError> {
+ server.send_notice(&command.source,
+ "This Plugin does not implement any commands.")
+ }
+}
+
+#[cfg(test)]
+mod tests {}
diff --git a/src/plugins/mod.rs b/src/plugins/mod.rs
index 0dea596..5bcb6ed 100644
--- a/src/plugins/mod.rs
+++ b/src/plugins/mod.rs
@@ -1,7 +1,9 @@
mod help;
mod emoji;
mod currency;
+mod keepnick;
pub use self::help::Help;
pub use self::emoji::Emoji;
pub use self::currency::Currency;
+pub use self::keepnick::KeepNick;