From e3c619494601a8628b8a27bd855fa9b1506c0728 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Fri, 29 Jul 2016 19:21:20 -0400 Subject: Add examples; fix up docs --- examples/04-bash-bot.p6 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/04-bash-bot.p6 (limited to 'examples/04-bash-bot.p6') 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 ; + +use IRC::Client; +use Mojo::UserAgent:from; + +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 + :host + :channels<#zofbot> + :debug + :plugins(Bash.new); -- cgit v1.1