summaryrefslogtreecommitdiff
path: root/lib/rbot/ircbot.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbot/ircbot.rb')
-rw-r--r--lib/rbot/ircbot.rb29
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