summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/rbot/ircbot.rb49
-rw-r--r--lib/rbot/rfc2812.rb8
2 files changed, 33 insertions, 24 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index bc6cf760..57dd8927 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -534,6 +534,8 @@ class Bot
@last_ping = nil
}
@client[:nick] = proc {|data|
+ # debug "Message source is #{data[:source].inspect}"
+ # debug "Bot is #{myself.inspect}"
source = data[:source]
old = data[:oldnick]
new = data[:newnick]
@@ -753,18 +755,13 @@ class Bot
exit 2
end
- stop_server_pings
- server.clear
- if @socket.connected?
- @socket.clearq
- @socket.shutdown
- end
+ disconnect
- log "disconnected"
+ log "\n\nDisconnected\n\n"
quit if $interrupted > 0
- log "waiting to reconnect"
+ log "\n\nWaiting to reconnect\n\n"
sleep @config['server.reconnect_wait']
end
end
@@ -961,6 +958,26 @@ class Bot
sendq "TOPIC #{where} :#{topic}", where, 2
end
+ def disconnect(message = nil)
+ message = @lang.get("quit") if (message.nil? || message.empty?)
+ if @socket.connected?
+ debug "Clearing socket"
+ @socket.clearq
+ debug "Sending quit message"
+ @socket.emergency_puts "QUIT :#{message}"
+ debug "Flushing socket"
+ @socket.flush
+ debug "Shutting down socket"
+ @socket.shutdown
+ end
+ debug "Logging quits"
+ server.channels.each { |ch|
+ irclog "@ quit (#{message})", ch
+ }
+ stop_server_pings
+ @client.reset
+ end
+
# disconnect from the server and cleanup all plugins and modules
def shutdown(message = nil)
@quit_mutex.synchronize do
@@ -973,21 +990,7 @@ class Bot
# rescue => e
# debug "failed to restore signals: #{e.inspect}\nProbably running on windows?"
# end
- message = @lang.get("quit") if (message.nil? || message.empty?)
- if @socket.connected?
- debug "Clearing socket"
- @socket.clearq
- debug "Sending quit message"
- @socket.emergency_puts "QUIT :#{message}"
- debug "Flushing socket"
- @socket.flush
- debug "Shutting down socket"
- @socket.shutdown
- end
- debug "Logging quits"
- server.channels.each { |ch|
- irclog "@ quit (#{message})", ch
- }
+ disconnect
debug "Saving"
save
debug "Cleaning up"
diff --git a/lib/rbot/rfc2812.rb b/lib/rbot/rfc2812.rb
index 1a5adb84..5dec464c 100644
--- a/lib/rbot/rfc2812.rb
+++ b/lib/rbot/rfc2812.rb
@@ -821,7 +821,7 @@ module Irc
# create a new Client instance
def initialize
@server = Server.new # The Server
- @user = @server.user("") # The User representing the client on this Server
+ @user = @server.user("") # The User representing the client on this Server
@handlers = Hash.new
@@ -830,6 +830,12 @@ module Irc
@tmpusers = []
end
+ # clear the server and reset the User
+ def reset
+ @server.clear
+ @user = @server.user("")
+ end
+
# key:: server event to handle
# value:: proc object called when event occurs
# set a handler for a server event