summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-08-11 08:49:35 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2008-08-11 08:49:35 +0200
commit0bcb22bf7f4574a9697dddbacc0a23dae618b5a0 (patch)
tree3ebbc43766c910c55efc42e039276d287d9ae2a0 /lib
parent0a900b044b1920942ef99be800d7cd9bd8b60f5c (diff)
rfc2812: create channels and users for al commands when needed
Always create a user or channel when we receive information about it. This makes server message parsing much more robust (no more crashes about NilClass not having user/channel methods) but has a few subtle implications about the server state: for example, channels may exist in the Server object even when the bot is not in the channel itself.
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/rfc2812.rb30
1 files changed, 12 insertions, 18 deletions
diff --git a/lib/rbot/rfc2812.rb b/lib/rbot/rfc2812.rb
index d781c0f1..38ce64ca 100644
--- a/lib/rbot/rfc2812.rb
+++ b/lib/rbot/rfc2812.rb
@@ -1155,11 +1155,7 @@ module Irc
data[:channeltype] = argv[1]
data[:channel] = argv[2]
- chan = @server.get_channel(data[:channel])
- unless chan
- warning "Received names #{data[:topic].inspect} for channel #{data[:channel].inspect} I was not on"
- return
- end
+ chan = @server.channel(data[:channel])
users = []
argv[3].scan(/\S+/).each { |u|
@@ -1247,7 +1243,7 @@ module Irc
when RPL_AWAY
data[:nick] = argv[1]
data[:message] = argv[-1]
- user = @server.get_user(data[:nick])
+ user = @server.user(data[:nick])
user.away = data[:message]
handle(:away, data)
when RPL_WHOREPLY
@@ -1268,7 +1264,7 @@ module Irc
end
data[:hopcount], data[:real_name] = argv[7].split(" ", 2)
- user = @server.get_user(data[:nick])
+ user = @server.user(data[:nick])
user.user = data[:user]
user.host = data[:host]
@@ -1278,7 +1274,7 @@ module Irc
# TODO hopcount
user.real_name = data[:real_name]
- channel = @server.get_channel(data[:channel])
+ channel = @server.channel(data[:channel])
channel.add_user(user, :silent=>true)
data[:modes].map { |mode|
@@ -1295,7 +1291,7 @@ module Irc
@whois[:host] = argv[3]
@whois[:real_name] = argv[-1]
- user = @server.get_user(@whois[:nick])
+ user = @server.user(@whois[:nick])
user.user = @whois[:user]
user.host = @whois[:host]
user.real_name = @whois[:real_name]
@@ -1313,7 +1309,7 @@ module Irc
when RPL_WHOISIDLE
@whois ||= Hash.new
@whois[:nick] = argv[1]
- user = @server.get_user(@whois[:nick])
+ user = @server.user(@whois[:nick])
@whois[:idle] = argv[2].to_i
user.idle_since = Time.now - @whois[:idle]
if argv[-1] == 'seconds idle, signon time'
@@ -1330,17 +1326,15 @@ module Irc
@whois ||= Hash.new
@whois[:nick] = argv[1]
@whois[:channels] = []
- user = @server.get_user(@whois[:nick])
+ user = @server.user(@whois[:nick])
argv[-1].split.each do |prechan|
pfx = prechan.scan(/[#{@server.supports[:prefix][:prefixes].join}]/)
modes = pfx.map { |p| @server.mode_for_prefix p }
chan = prechan[pfx.length..prechan.length]
- channel = @server.get_channel(chan)
- if channel
- channel.add_user(user, :silent => true)
- modes.map { |mode| channel.mode[mode].set(user) }
- end
+ channel = @server.channel(chan)
+ channel.add_user(user, :silent => true)
+ modes.map { |mode| channel.mode[mode].set(user) }
@whois[:channels] << [chan, modes]
end
@@ -1350,12 +1344,12 @@ module Irc
when RPL_CREATIONTIME
data[:channel] = argv[1]
data[:time] = Time.at(argv[2].to_i)
- @server.get_channel(data[:channel]).creation_time=data[:time]
+ @server.channel(data[:channel]).creation_time=data[:time]
handle(:creationtime, data)
when RPL_CHANNEL_URL
data[:channel] = argv[1]
data[:url] = argv[2]
- @server.get_channel(data[:channel]).url=data[:url].dup
+ @server.channel(data[:channel]).url=data[:url].dup
handle(:channel_url, data)
else
warning "Unknown message #{serverstring.inspect}"