From fd168425f0da4527204fd8a97f45b39db34c122f Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 3 Aug 2008 09:24:51 +0200 Subject: nickrecover plugin: improve logic to start/stop recovery --- data/rbot/plugins/nickrecover.rb | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'data/rbot') 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 -- cgit v1.2.3