4 # :title: Nick recovery
6 # Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
8 # Copyright:: (C) 2008 Giuseppe Bilotta
10 # This plugin tries to automatically recover the bot's wanted nick
11 # in case it couldn't be achieved.
13 class NickRecoverPlugin < Plugin
15 Config.register Config::BooleanValue.new('nickrecover.enabled',
16 :default => true, :requires_restart => false,
17 :desc => _("Should the bot try to recover its nick?"))
19 Config.register Config::IntegerValue.new('nickrecover.poll_time',
20 :default => 60, :valiedate => Proc.new { |v| v > 0 },
21 :on_change => Proc.new do |bot, v|
22 bot.plugin['nickrecover'].start_recovery(v)
23 end, :requires_restart => false,
24 :desc => _("Time in seconds to wait between attempts to recover the nick"))
27 @bot.config['nickrecover.enabled']
31 @bot.config['nickrecover.poll_time']
39 @bot.timer.remove(@recovery) if @recovery
42 def start_recovery(time=self.poll_time)
44 @bot.timer.reschedule(@recovery, poll_time)
46 @recovery = @bot.timer.add(time) { @bot.nickchg wanted_nick }
53 if enabled? and @bot.nick.downcase != wanted_nick
59 return unless m.address?
60 # if recovery is enabled and the nick is not the wanted nick,
61 # launch the recovery process. Stop it otherwise
62 if enabled? and m.newnick.downcase != wanted_nick.downcase
71 plugin = NickRecoverPlugin.new