diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-11-04 15:12:43 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-11-04 15:12:43 +0000 |
commit | 0de0f89e3e50b77e6fb9f7c400a7b41605d7bbf2 (patch) | |
tree | 3d8eecbb72e1ea200dcfb455957379b1107cf787 /data/rbot | |
parent | 98781d3240b5264d25f11ae126ae06f2b6df1fa4 (diff) |
factoids plugin: move meta display into Factoid#to_s
Diffstat (limited to 'data/rbot')
-rw-r--r-- | data/rbot/plugins/factoids.rb | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/data/rbot/plugins/factoids.rb b/data/rbot/plugins/factoids.rb index 395ca6dc..78319fdc 100644 --- a/data/rbot/plugins/factoids.rb +++ b/data/rbot/plugins/factoids.rb @@ -20,8 +20,27 @@ class FactoidsPlugin < Plugin end end - def to_s - @hash[:fact] + def to_s(opts={}) + show_meta = opts[:meta] + fact = @hash[:fact] + if !show_meta + return fact + end + meta = "" + metadata = [] + if fact[:who] + metadata << _("from %{who}" % fact.to_hash) + end + if fact[:when] + metadata << _("on %{when}" % fact.to_hash) + end + if fact[:where] + metadata << _("in %{where}" % fact.to_hash) + end + unless metadata.empty? + meta << _(" [learnt %{data}]" % {:data => metadata.join(" ")}) + end + return fact+meta end def [](*args) @@ -217,25 +236,10 @@ class FactoidsPlugin < Plugin fact = known.pick_one idx = @factoids.index(fact)+1 end - meta = nil - metadata = [] - if fact[:who] - metadata << _("from %{who}" % fact.to_hash) - end - if fact[:when] - metadata << _("on %{when}" % fact.to_hash) - end - if fact[:where] - metadata << _("in %{where}" % fact.to_hash) - end - unless metadata.empty? - meta = _(" [learnt %{data}]" % {:data => metadata.join(" ")}) - end - m.reply _("fact #%{idx} of %{total}: %{fact}%{meta}" % { + m.reply _("fact #%{idx} of %{total}: %{fact}" % { :idx => idx, :total => total, - :fact => fact, - :meta => meta + :fact => fact.to_s(:meta => true) }) end |