From 2b07807fbed45fdeb6ca4f0e22f6fe64dd8bd339 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Wed, 30 Jul 2008 20:01:12 +0200 Subject: nickrecover plugin: initial commit --- data/rbot/plugins/nickrecover.rb | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 data/rbot/plugins/nickrecover.rb (limited to 'data/rbot/plugins') 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 +# +# 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 + -- cgit v1.2.3