aboutsummaryrefslogtreecommitdiff
path: root/examples/04-bash-bot.p6
diff options
context:
space:
mode:
Diffstat (limited to 'examples/04-bash-bot.p6')
-rw-r--r--examples/04-bash-bot.p626
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/04-bash-bot.p6 b/examples/04-bash-bot.p6
new file mode 100644
index 0000000..d3aaa4c
--- /dev/null
+++ b/examples/04-bash-bot.p6
@@ -0,0 +1,26 @@
+use lib <lib>;
+
+use IRC::Client;
+use Mojo::UserAgent:from<Perl5>;
+
+class Bash {
+ constant $BASH_URL = 'http://bash.org/?random1';
+ constant $cache = Channel.new;
+ has $!ua = Mojo::UserAgent.new;
+
+ multi method irc-to-me ($ where /bash/) {
+ start $cache.poll or do { self!fetch-quotes; $cache.poll };
+ }
+
+ method !fetch-quotes {
+ $cache.send: $_
+ for $!ua.get($BASH_URL).res.dom.find('.qt').each».all_text.lines.join: ' ';
+ }
+}
+
+.run with IRC::Client.new:
+ :nick<MahBot>
+ :host<irc.freenode.net>
+ :channels<#zofbot>
+ :debug
+ :plugins(Bash.new);