diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-01-15 04:32:56 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-01-15 04:48:23 +0100 |
commit | 37f2e09f71f53226ccc167a485ffc7286324cdcb (patch) | |
tree | 82da5a484951b914324ee8d4aeab4670ef9c14dc /lib/rbot | |
parent | 3e096c573329c71e77baaf3f2e3524c372f65a8f (diff) |
ircbot: refactor reconnection into its own method
Diffstat (limited to 'lib/rbot')
-rw-r--r-- | lib/rbot/ircbot.rb | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index f8dbc501..0ae1bce0 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -872,14 +872,28 @@ class Bot myself.user = @config['irc.user'] end + # disconnect the bot from IRC, if connected, and then connect (again) + def reconnect(message=nil, too_fast=false) + if @socket.connected? + disconnect(message) + + log "\n\nDisconnected\n\n" + + quit if $interrupted > 0 + + log "\n\nWaiting to reconnect\n\n" + sleep @config['server.reconnect_wait'] + sleep 10*@config['server.reconnect_wait'] if too_fast + end + connect + end + # begin event handling loop def mainloop while true too_fast = false begin quit if $interrupted > 0 - connect - quit_msg = nil while @socket.connected? quit if $interrupted > 0 @@ -925,16 +939,7 @@ class Bot log_session_end exit 2 end - - disconnect(quit_msg) - - log "\n\nDisconnected\n\n" - - quit if $interrupted > 0 - - log "\n\nWaiting to reconnect\n\n" - sleep @config['server.reconnect_wait'] - sleep 10*@config['server.reconnect_wait'] if too_fast + reconnect(quit_msg, too_fast) end end |