summaryrefslogtreecommitdiff
path: root/data/rbot/plugins
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-07-30 20:01:12 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-07-30 20:01:12 +0200
commit2b07807fbed45fdeb6ca4f0e22f6fe64dd8bd339 (patch)
tree156ea0f190173ce34546fee4c4f708172a08e445 /data/rbot/plugins
parent9769ffed13b4174ad0a0b51dc1afd3c9fd5cef8c (diff)
nickrecover plugin: initial commit
Diffstat (limited to 'data/rbot/plugins')
-rw-r--r--data/rbot/plugins/nickrecover.rb72
1 files changed, 72 insertions, 0 deletions
diff --git a/data/rbot/plugins/nickrecover.rb b/data/rbot/plugins/nickrecover.rb
new file mode 100644
index 00000000..24b41a04
--- /dev/null
+++ b/data/rbot/plugins/nickrecover.rb
@@ -0,0 +1,72 @@
+#-- vim:sw=2:et
+#++
+#
+# :title: Nick recovery
+#
+# Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
+#
+# Copyright:: (C) 2008 Giuseppe Bilotta
+#
+# This plugin tries to automatically recover the bot's wanted nick
+# in case it couldn't be achieved.
+
+class NickRecoverPlugin < Plugin
+
+ Config.register Config::BooleanValue.new('nickrecover.enabled',
+ :default => true, :requires_restart => false,
+ :desc => _("Should the bot try to recover its nick?"))
+
+ Config.register Config::IntegerValue.new('nickrecover.poll_time',
+ :default => 60, :valiedate => Proc.new { |v| v > 0 },
+ :on_change => Proc.new do |bot, v|
+ bot.plugin['nickrecover'].start_recovery(v)
+ end, :requires_restart => false,
+ :desc => _("Time in seconds to wait between attempts to recover the nick"))
+
+ def enabled?
+ @bot.config['nickrecover.enabled']
+ end
+
+ def poll_time
+ @bot.config['nickrecover.poll_time']
+ end
+
+ def wanted_nick
+ @bot.wanted_nick
+ end
+
+ def stop_recovery
+ @bot.timer.remove(@recovery) if @recovery
+ end
+
+ def start_recovery(time=self.poll_time)
+ if @recovery
+ @bot.timer.reschedule(@recovery, poll_time)
+ else
+ @recovery = @bot.timer.add(time) { @bot.nickchg wanted_nick }
+ end
+ end
+
+ def initialize
+ super
+ @recovery = nil
+ if enabled? and @bot.nick.downcase != wanted_nick
+ start_recovery
+ end
+ end
+
+ def nick(m)
+ return unless m.address?
+ # if recovery is enabled and the nick is not the wanted nick,
+ # launch the recovery process. Stop it otherwise
+ if enabled? and m.newnick.downcase != wanted_nick.downcase
+ start_recovery
+ else
+ stop_recovery
+ end
+ end
+
+end
+
+plugin = NickRecoverPlugin.new
+