X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fnickrecover.rb;h=02def493f77c94e2ad7134d6d8683c521455aadb;hb=22e6cefa54de681b131ecb97fc9383ff5e990dfe;hp=b6d8e61e10e13cbfe2e8667e7d7673c139fb7481;hpb=d3883617a4ceaf6fbf88620a00000e4909c78c14;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/nickrecover.rb b/data/rbot/plugins/nickrecover.rb index b6d8e61e..02def493 100644 --- a/data/rbot/plugins/nickrecover.rb +++ b/data/rbot/plugins/nickrecover.rb @@ -21,7 +21,15 @@ class NickRecoverPlugin < Plugin bot.plugin['nickrecover'].stop_recovery end end, :requires_restart => false, - :desc => _("Time in seconds to wait between attempts to recover the nick")) + :desc => _("Time in seconds to wait between attempts to recover the nick. set to 0 to disable nick recovery.")) + + def help(plugin,topic="") + [ + _("the nickrecover plugin takes care of recovering the bot nick by trying to change nick until it succeeds."), + _("the plugin waits irc.nick_retry seconds between attempts."), + _("set irc.nick_retry to 0 to disable it.") + ].join(' ') + end def enabled? @bot.config['irc.nick_retry'] > 0 @@ -35,6 +43,14 @@ class NickRecoverPlugin < Plugin @bot.wanted_nick end + def has_nick? + @bot.nick.downcase == wanted_nick.downcase + end + + def recover + @bot.nickchg wanted_nick + end + def stop_recovery @bot.timer.remove(@recovery) if @recovery end @@ -43,15 +59,20 @@ class NickRecoverPlugin < Plugin if @recovery @bot.timer.reschedule(@recovery, poll_time) else - @recovery = @bot.timer.add(time) { @bot.nickchg wanted_nick } + @recovery = @bot.timer.add(time) do + has_nick? ? stop_recovery : recover + end end end def initialize super @recovery = nil - if enabled? and @bot.nick.downcase != wanted_nick - start_recovery + end + + def connect + if enabled? + start_recovery unless has_nick? end end @@ -66,6 +87,10 @@ class NickRecoverPlugin < Plugin end end + def cleanup + stop_recovery + end + end plugin = NickRecoverPlugin.new