From 1a0dba4dec4b76aa3de34bdce4374c0ef11760ea Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 4 Nov 2007 14:02:36 +0000 Subject: factoids plugin: ensure that edited metadata is properly saved, and check for parseable dates --- data/rbot/plugins/factoids.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/data/rbot/plugins/factoids.rb b/data/rbot/plugins/factoids.rb index adadba31..64e4514e 100644 --- a/data/rbot/plugins/factoids.rb +++ b/data/rbot/plugins/factoids.rb @@ -219,14 +219,21 @@ class FactoidsPlugin < Plugin begin if params[:who] who = params[:who].to_s.sub(/^me$/, m.source.fullform) - debug who fact[:who] = who + @changed = true end if params[:when] - fact[:when] = Time.parse(params[:when].to_s) + dstr = params[:when].to_s + begin + fact[:when] = Time.parse(dstr, "") + @changed = true + rescue + raise ArgumentError, _("not a date '%{dstr}'" % { :dstr => dstr }) + end end if params[:where] fact[:where] = params[:where].to_s + @changed = true end rescue Exception m.reply _("couldn't change learn data for fact %{fact}: %{err}" % { @@ -249,6 +256,7 @@ plugin.map 'forget that *stuff', :auth_path => 'edit' plugin.map 'facts [about *words]' plugin.map 'fact [about *words]' plugin.map 'fact :index', :requirements => { :index => /^#?\d+$/ } + plugin.map 'fact :index :learn from *who', :action => :edit_fact, :requirements => { :learn => /^((?:is|was)\s+)?learn(ed|t)$/, :index => /^#?\d+$/ }, :auth_path => 'edit' plugin.map 'fact :index :learn on *when', :action => :edit_fact, :requirements => { :learn => /^((?:is|was)\s+)?learn(ed|t)$/, :index => /^#?\d+$/ }, :auth_path => 'edit' plugin.map 'fact :index :learn in *where', :action => :edit_fact, :requirements => { :learn => /^((?:is|was)\s+)?learn(ed|t)$/, :index => /^#?\d+$/ }, :auth_path => 'edit' -- cgit v1.2.3