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::IntegerValue.new('irc.nick_retry',
16 :default => 60, :valiedate => Proc.new { |v| v >= 0 },
17 :on_change => Proc.new do |bot, v|
19 bot.plugin['nickrecover'].start_recovery(v)
21 bot.plugin['nickrecover'].stop_recovery
23 end, :requires_restart => false,
24 :desc => _("Time in seconds to wait between attempts to recover the nick. set to 0 to disable nick recovery."))
26 def help(plugin,topic="")
28 _("the nickrecover plugin takes care of recovering the bot nick by trying to change nick until it succeeds."),
29 _("the plugin waits irc.nick_retry seconds between attempts."),
30 _("set irc.nick_retry to 0 to disable it.")
35 @bot.config['irc.nick_retry'] > 0
39 @bot.config['irc.nick_retry']
47 @bot.nick.downcase == wanted_nick.downcase
51 @bot.nickchg wanted_nick
55 @bot.timer.remove(@recovery) if @recovery
58 def start_recovery(time=self.poll_time)
60 @bot.timer.reschedule(@recovery, poll_time)
62 @recovery = @bot.timer.add(time) do
63 has_nick? ? stop_recovery : recover
75 start_recovery unless has_nick?
80 return unless m.address?
81 # if recovery is enabled and the nick is not the wanted nick,
82 # launch the recovery process. Stop it otherwise
83 if enabled? and m.newnick.downcase != wanted_nick.downcase
96 plugin = NickRecoverPlugin.new