X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Frbot%2Frfc2812.rb;h=bec3d322c706065e043127d92606f48443d7f179;hb=12906a51f698aebe1c9a5e19b15555ebbbcc4368;hp=1a5adb846edf3419487d21489ed55fd0bcc6c3e0;hpb=7b7f1309e8c3dbc3bb4408d56489ae5fba77d57a;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/rfc2812.rb b/lib/rbot/rfc2812.rb index 1a5adb84..bec3d322 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 @@ -882,8 +888,8 @@ module Irc data = Hash.new data[:serverstring] = serverstring - unless serverstring =~ /^(:(\S+)\s)?(\S+)(\s(.*))?/ - raise "Unparseable Server Message!!!: #{serverstring}" + unless serverstring.chomp =~ /^(:(\S+)\s)?(\S+)(\s(.*))?$/ + raise "Unparseable Server Message!!!: #{serverstring.inspect}" end prefix, command, params = $2, $3, $5 @@ -896,18 +902,19 @@ module Irc # This is not always true, though, since some servers do not send a # full hostmask for user messages. # - if prefix =~ /^(?:\S+)(?:!\S+)?@(?:\S+)$/ + if prefix =~ /^#{Regexp::Irc::BANG_AT}$/ data[:source] = @server.user(prefix) else if @server.hostname if @server.hostname != prefix - debug "Origin #{prefix} for message\n\t#{serverstring.inspect}\nis neither a user hostmask nor the server hostname, assuming it's a nick" - data[:source] = @server.user(prefix) + # TODO do we want to be able to differentiate messages that are passed on to us from /other/ servers? + debug "Origin #{prefix} for message\n\t#{serverstring.inspect}\nis neither a user hostmask nor the server hostname\nI'll pretend that it's from the server anyway" + data[:source] = @server else data[:source] = @server end else - @server.instance_variable_set(:@hostname, data[:source]) + @server.instance_variable_set(:@hostname, prefix) data[:source] = @server end end