summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorRaine Virta <rane@kapsi.fi>2009-02-22 18:14:36 +0200
committerRaine Virta <rane@kapsi.fi>2009-02-26 01:09:20 +0200
commiteec8d96e5c8f0c44148cc97a40b75a57e399cf6e (patch)
treea56d8f1c13a60b8194230b2f1e4a0f9e13e29a87 /data
parent0357b6c268f8763b7c72276c5fdad4abd69b395f (diff)
seen: cyclically store two of the users' latest actions in the registry
Diffstat (limited to 'data')
-rw-r--r--data/rbot/plugins/seen.rb49
1 files changed, 35 insertions, 14 deletions
diff --git a/data/rbot/plugins/seen.rb b/data/rbot/plugins/seen.rb
index 1a1681fb..078ed94a 100644
--- a/data/rbot/plugins/seen.rb
+++ b/data/rbot/plugins/seen.rb
@@ -49,33 +49,38 @@ class SeenPlugin < Plugin
when PrivMessage
return if m.private?
type = m.action? ? 'ACTION' : 'PUBLIC'
- @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, now, type,
- m.target.to_s, m.message.dup)
+ store m, Saw.new(m.sourcenick.dup, now, type,
+ m.target.to_s, m.message.dup)
when QuitMessage
return if m.address?
- @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, now, "QUIT",
- nil, m.message.dup)
+ store m, Saw.new(m.sourcenick.dup, now, "QUIT",
+ nil, m.message.dup)
when NickMessage
return if m.address?
- saw = Saw.new(m.oldnick, now, "NICK", nil, m.newnick)
- @registry[m.oldnick] = saw
- @registry[m.newnick] = saw
+ store m, Saw.new(m.oldnick, now, "NICK", nil, m.newnick)
when PartMessage
return if m.address?
- @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "PART",
- m.target.to_s, m.message.dup)
+ store m, Saw.new(m.sourcenick.dup, Time.new, "PART",
+ m.target.to_s, m.message.dup)
when JoinMessage
return if m.address?
- @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "JOIN",
- m.target.to_s, m.message.dup)
+ store m, Saw.new(m.sourcenick.dup, Time.new, "JOIN",
+ m.target.to_s, m.message.dup)
when TopicMessage
return if m.address? or m.info_or_set == :info
- @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "TOPIC",
- m.target.to_s, m.message.dup)
+ store m, Saw.new(m.sourcenick.dup, Time.new, "TOPIC",
+ m.target.to_s, m.message.dup)
end
end
- def seen(saw)
+ def seen(reg)
+ saw = case reg
+ when Struct::Saw
+ reg # for backwards compatibility
+ when Array
+ reg.last
+ end
+
ret = "#{saw.nick} was last seen "
ago = Time.new - saw.time
@@ -103,6 +108,22 @@ class SeenPlugin < Plugin
end
end
+ def store(m, saw)
+ reg = @registry[saw.nick]
+
+ if reg && reg.is_a?(Array)
+ reg.shift if reg.size > 1
+ reg.push(saw)
+ else
+ reg = [saw]
+ end
+
+ if m.is_a? NickMessage
+ @registry[m.newnick] = reg
+ end
+
+ @registry[saw.nick] = reg
+ end
end
plugin = SeenPlugin.new
plugin.register("seen")