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
| 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