forked from Pistos/Mathetes
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pistos
committed
May 5, 2010
1 parent
6d33b3d
commit 8574341
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |