Skip to content

Instantly share code, notes, and snippets.

@KamilaBorowska
Created September 3, 2012 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KamilaBorowska/3608585 to your computer and use it in GitHub Desktop.
Save KamilaBorowska/3608585 to your computer and use it in GitHub Desktop.
use JSON::Tiny;
class Net::IRC::Modules::Factoids {
has $.file;
has %!content = try { from-json slurp $.file } // {};
multi method said ( $ev where {.what ~~ / ^ \! add \s+ (\w+) \s* (.+) $ /} ) {
%!content{$0} = ~$1;
self!save;
}
multi method said ( $ev where {.what ~~ / ^ \! (\w+) /}) {
if %!content{$0} {
$ev.msg("{$ev.who}: %!content{$0}")
}
}
method !save {
spurt $.file, to-json %!content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment