summaryrefslogtreecommitdiff
path: root/rbot/plugins/seen.rb
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2004-10-09 01:51:05 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2004-10-09 01:51:05 +0000
commit0f3e302547363ea237454dda891ddb5de1be4476 (patch)
treeec45be24a669ee28b5e2da4ff65e39265a418e0b /rbot/plugins/seen.rb
initial import of rbot
Diffstat (limited to 'rbot/plugins/seen.rb')
-rw-r--r--rbot/plugins/seen.rb89
1 files changed, 89 insertions, 0 deletions
diff --git a/rbot/plugins/seen.rb b/rbot/plugins/seen.rb
new file mode 100644
index 00000000..6bd86a70
--- /dev/null
+++ b/rbot/plugins/seen.rb
@@ -0,0 +1,89 @@
+Saw = Struct.new("Saw", :nick, :time, :type, :where, :message)
+
+class SeenPlugin < Plugin
+ def help(plugin, topic="")
+ "seen <nick> => have you seen, or when did you last see <nick>"
+ end
+
+ def privmsg(m)
+ unless(m.params =~ /^(\S)+$/)
+ m.reply "incorrect usage: " + help(m.plugin)
+ return
+ end
+
+ m.params.gsub!(/\?$/, "")
+
+ if @registry.has_key?(m.params)
+ m.reply seen(@registry[m.params])
+ else
+ m.reply "nope!"
+ end
+ end
+
+ def listen(m)
+ # keep database up to date with who last said what
+ if m.kind_of?(PrivMessage)
+ return if m.private? || m.address?
+ if m.action?
+ @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "ACTION",
+ m.target, m.message.dup)
+ else
+ @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "PUBLIC",
+ m.target, m.message.dup)
+ end
+ elsif m.kind_of?(QuitMessage)
+ return if m.address?
+ @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "QUIT",
+ nil, m.message.dup)
+ elsif m.kind_of?(NickMessage)
+ return if m.address?
+ @registry[m.message] = Saw.new(m.sourcenick.dup, Time.new, "NICK",
+ nil, m.message.dup)
+ @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "NICK",
+ nil, m.message.dup)
+ elsif m.kind_of?(PartMessage)
+ return if m.address?
+ @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "PART",
+ m.target, m.message.dup)
+ elsif m.kind_of?(JoinMessage)
+ return if m.address?
+ @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "JOIN",
+ m.target, m.message.dup)
+ elsif m.kind_of?(TopicMessage)
+ return if m.address?
+ @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "TOPIC",
+ m.target, m.message.dup)
+ end
+ end
+
+ def seen(saw)
+ ret = "#{saw.nick} was last seen "
+ ago = Time.new - saw.time
+
+ if (ago.to_i == 0)
+ ret += "just now, "
+ else
+ ret += Utils.secs_to_string(ago) + " ago, "
+ end
+
+ case saw.type
+ when "PUBLIC"
+ ret += "saying #{saw.message}"
+ when "ACTION"
+ ret += "doing #{saw.nick} #{saw.message}"
+ when "NICK"
+ ret += "changing nick from #{saw.nick} to #{saw.message}"
+ when "PART"
+ ret += "leaving #{saw.where}"
+ when "JOIN"
+ ret += "joining #{saw.where}"
+ when "QUIT"
+ ret += "quiting IRC (#{saw.message})"
+ when "TOPIC"
+ ret += "changing the topic of #{saw.where} to #{saw.message}"
+ end
+ end
+
+end
+plugin = SeenPlugin.new
+plugin.register("seen")