-Saw = Struct.new("Saw", :nick, :time, :type, :where, :message)
+define_structure :Saw, :nick, :time, :type, :where, :message
class SeenPlugin < Plugin
- # turn a number of seconds into a human readable string, e.g
- # 2 days, 3 hours, 18 minutes, 10 seconds
- def secs_to_string(secs)
- ret = ""
- days = (secs / (60 * 60 * 24)).to_i
- secs = secs % (60 * 60 * 24)
- hours = (secs / (60 * 60)).to_i
- secs = (secs % (60 * 60))
- mins = (secs / 60).to_i
- secs = (secs % 60).to_i
- ret += "#{days} days, " if days > 0
- ret += "#{hours} hours, " if hours > 0 || days > 0
- ret += "#{mins} minutes and " if mins > 0 || hours > 0 || days > 0
- ret += "#{secs} seconds"
- return ret
- end
-
def help(plugin, topic="")
"seen <nick> => have you seen, or when did you last see <nick>"
end
end
def listen(m)
+ return if m.sourcenick.nil?
# keep database up to date with who last said what
if m.kind_of?(PrivMessage)
return if m.private?
if (ago.to_i == 0)
ret += "just now, "
else
- ret += secs_to_string(ago) + " ago, "
+ ret += Utils.secs_to_string(ago) + " ago, "
end
- case saw.type
- when "PUBLIC"
+ case saw.type.to_sym
+ when :PUBLIC
ret += "saying #{saw.message}"
- when "ACTION"
+ when :ACTION
ret += "doing #{saw.nick} #{saw.message}"
- when "NICK"
+ when :NICK
ret += "changing nick from #{saw.nick} to #{saw.message}"
- when "PART"
+ when :PART
ret += "leaving #{saw.where}"
- when "JOIN"
+ when :JOIN
ret += "joining #{saw.where}"
- when "QUIT"
- ret += "quiting IRC (#{saw.message})"
- when "TOPIC"
+ when :QUIT
+ ret += "quitting IRC (#{saw.message})"
+ when :TOPIC
ret += "changing the topic of #{saw.where} to #{saw.message}"
end
end