X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fnickrecover.rb;h=02def493f77c94e2ad7134d6d8683c521455aadb;hb=22e6cefa54de681b131ecb97fc9383ff5e990dfe;hp=e6e56b8754bddd4611d65a38ea15c5393221c57e;hpb=965785ca3a01229f996583a677d06a2087590530;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/nickrecover.rb b/data/rbot/plugins/nickrecover.rb index e6e56b87..02def493 100644 --- a/data/rbot/plugins/nickrecover.rb +++ b/data/rbot/plugins/nickrecover.rb @@ -43,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 @@ -51,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 @@ -74,6 +87,10 @@ class NickRecoverPlugin < Plugin end end + def cleanup + stop_recovery + end + end plugin = NickRecoverPlugin.new