From: Giuseppe Bilotta Date: Sun, 4 Nov 2007 00:26:32 +0000 (+0000) Subject: keywords plugin: export data to flat factoids file X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=3082ad5836b0babea7db5cde2eac1f59c3fdd667;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git keywords plugin: export data to flat factoids file --- 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+(.+)$/