Skip to content

Instantly share code, notes, and snippets.

@KamilaBorowska
Created September 3, 2012 11:10
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/3608610 to your computer and use it in GitHub Desktop.
Save KamilaBorowska/3608610 to your computer and use it in GitHub Desktop.
glitchmr@feather ~/SixtySixBot> cat lib/Net/IRC/Modules/Factoids.pm
use JSON::Tiny;
class Net::IRC::Modules::Factoids {
has $.file = 'factoids';
has %!content;
submethod BUILD {
$.file.perl.say;
%!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;
}
}
glitchmr@feather ~/SixtySixBot> perl6 sixtysix.p6
===SORRY!===
Virtual call $.file may not be used on partially constructed objects
at lib/Net/IRC/Modules/Factoids.pm:6
from sixtysix.p6:3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment