Skip to content

Commit

Permalink
Added KeyValueStore plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pistos committed May 5, 2010
1 parent 6d33b3d commit 8574341
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/mathetes/plugins/key-value-store.rb
@@ -0,0 +1,35 @@
require 'mutex-pstore'

module Mathetes; module Plugins

class KeyValueStore

def initialize( mathetes )
@h = MuPStore.new( "key-value.pstore" )
mathetes.hook_privmsg( :regexp => /^!i(nfo)?\b/ ) do |message|
if message.text =~ /^\S+\s+(.+?)=(.+)/
key, value = $1.strip, $2.strip
@h.transaction {
@h[ { :channel => message.channel.to_s, :key => key }.inspect ] = value
}
message.answer "Set '#{key}'."
elsif message.text =~ /^\S+\s+(.+)/
key = $1.strip
value = nil
@h.transaction {
value = @h[ { :channel => message.channel.to_s, :key => key }.inspect ]
}
if value
message.answer value
else
message.answer "No value for key '#{key}'."
end
else
message.answer "Usage: !i key = value !i key"
end
end
end

end

end; end

0 comments on commit 8574341

Please sign in to comment.