summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/seen.rb
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2005-07-29 13:44:33 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2005-07-29 13:44:33 +0000
commit676dd61e6b0bea5f506d064039a685944aefd6fb (patch)
tree60fa1936a11a67d6412f9db28532d623aabed5d1 /data/rbot/plugins/seen.rb
parent438d56ceb82755961229d222d82a1c22ce04ab1d (diff)
Fri Jul 29 13:07:56 BST 2005 Tom Gilbert <tom@linuxbrit.co.uk>
* Moved some stuff out of util.rb into the plugins that actually need them. Those methods didn't belong in util as they were plugin-specific. * moved a few more plugins to use map() where appropriate * made the url plugin only store unique urls
Diffstat (limited to 'data/rbot/plugins/seen.rb')
-rw-r--r--data/rbot/plugins/seen.rb21
1 files changed, 19 insertions, 2 deletions
diff --git a/data/rbot/plugins/seen.rb b/data/rbot/plugins/seen.rb
index 6bd86a70..80d52f65 100644
--- a/data/rbot/plugins/seen.rb
+++ b/data/rbot/plugins/seen.rb
@@ -1,6 +1,23 @@
Saw = Struct.new("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
@@ -23,7 +40,7 @@ class SeenPlugin < Plugin
def listen(m)
# keep database up to date with who last said what
if m.kind_of?(PrivMessage)
- return if m.private? || m.address?
+ return if m.private?
if m.action?
@registry[m.sourcenick] = Saw.new(m.sourcenick.dup, Time.new, "ACTION",
m.target, m.message.dup)
@@ -63,7 +80,7 @@ class SeenPlugin < Plugin
if (ago.to_i == 0)
ret += "just now, "
else
- ret += Utils.secs_to_string(ago) + " ago, "
+ ret += secs_to_string(ago) + " ago, "
end
case saw.type