summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/nickrecover.rb
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-08-03 09:24:51 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-08-03 09:24:51 +0200
commitfd168425f0da4527204fd8a97f45b39db34c122f (patch)
treeb9247577c4b0abfa6e9614e7da55ab6171f37e22 /data/rbot/plugins/nickrecover.rb
parent58e65601becf1d3a1febf1d6067cd66754711c8b (diff)
nickrecover plugin: improve logic to start/stop recovery
Diffstat (limited to 'data/rbot/plugins/nickrecover.rb')
-rw-r--r--data/rbot/plugins/nickrecover.rb23
1 files changed, 20 insertions, 3 deletions
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