1 Saw = Struct.new("Saw", :nick, :time, :type, :where, :message)
3 class SeenPlugin < Plugin
4 def help(plugin, topic="")
5 "seen <nick> => have you seen, or when did you last see <nick>"
9 unless(m.params =~ /^(\S)+$/)
10 m.reply "incorrect usage: " + help(m.plugin)
14 m.params.gsub!(/\?$/, "")
16 if @registry.has_key?(m.params)
17 m.reply seen(@registry[m.params])
24 return if m.sourcenick.nil?
25 # keep database up to date with who last said what
26 if m.kind_of?(PrivMessage)
29 @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "ACTION",
30 m.target, m.message.dup)
32 @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "PUBLIC",
33 m.target, m.message.dup)
35 elsif m.kind_of?(QuitMessage)
37 @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "QUIT",
39 elsif m.kind_of?(NickMessage)
41 @registry[m.message] = Saw.new(m.sourcenick.dup, Time.new, "NICK",
43 @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "NICK",
45 elsif m.kind_of?(PartMessage)
47 @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "PART",
48 m.target, m.message.dup)
49 elsif m.kind_of?(JoinMessage)
51 @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "JOIN",
52 m.target, m.message.dup)
53 elsif m.kind_of?(TopicMessage)
55 @registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "TOPIC",
56 m.target, m.message.dup)
61 ret = "#{saw.nick} was last seen "
62 ago = Time.new - saw.time
67 ret += Utils.secs_to_string(ago) + " ago, "
72 ret += "saying #{saw.message}"
74 ret += "doing #{saw.nick} #{saw.message}"
76 ret += "changing nick from #{saw.nick} to #{saw.message}"
78 ret += "leaving #{saw.where}"
80 ret += "joining #{saw.where}"
82 ret += "quitting IRC (#{saw.message})"
84 ret += "changing the topic of #{saw.where} to #{saw.message}"
89 plugin = SeenPlugin.new
90 plugin.register("seen")