diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-11-04 00:26:32 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-11-04 00:26:32 +0000 |
commit | 3082ad5836b0babea7db5cde2eac1f59c3fdd667 (patch) | |
tree | 9a7179d59e8fcfe62929091398a302ce77c8bf99 | |
parent | 2541e09611bfb631c1d0859e117ef237aa264704 (diff) |
keywords plugin: export data to flat factoids file
-rw-r--r-- | data/rbot/plugins/keywords.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/data/rbot/plugins/keywords.rb b/data/rbot/plugins/keywords.rb index 5daff9f6..424df874 100644 --- a/data/rbot/plugins/keywords.rb +++ b/data/rbot/plugins/keywords.rb @@ -28,6 +28,16 @@ class Keyword end end + # return an array of all the possible values + def to_factoids(key) + ar = Array.new + @values.each { |val| + debug "key #{key}, value #{val}" + ar << "%s %s %s" % [key, @type, val] + } + return ar + end + # describe the keyword (show all values without interpolation) def desc @values.join(" | ") @@ -436,11 +446,41 @@ class Keywords < Plugin end end + # export keywords to factoids file + def keyword_factoids_export + ar = Array.new + + debug @keywords.keys + + @keywords.each { |k, val| + next unless val + kw = Keyword.restore(val) + ar |= kw.to_factoids(k) + } + + # TODO check factoids config + # also TODO: runtime export + dir = File.join(@bot.botclass,"factoids") + fname = File.join(dir,"keyword_factoids.rbot") + + Dir.mkdir(dir) unless FileTest.directory?(dir) + Utils.safe_save(fname) do |file| + file.puts ar + end + end + # privmsg handler def privmsg(m) case m.plugin when "keyword" case m.params + when /^export$/ + begin + keyword_factoids_export + m.okay + rescue + m.reply _("failed to export keywords as factoids (%{err})" % {:err => $!}) + end when /^set\s+(.+?)\s+(is|are)\s+(.+)$/ keyword_command(m, $1, $2, $3) if @bot.auth.allow?('keycmd', m.source, m.replyto) when /^forget\s+(.+)$/ |