summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-02-20 08:46:00 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-02-20 08:46:00 +0000
commitceebd54c0a6b769d2a278967fc00c1b05c8cca37 (patch)
tree51a8146c7b574a261bea2f7580df8b0f99d495e8 /lib/rbot
parentbae0027e9c1b9ff2526022c63b984710605ffc12 (diff)
New IRC Framework: bot now keeps track of his nick correctly across disconnects
Diffstat (limited to 'lib/rbot')
-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