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/05-bash-bot-with-filter.p6 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/05-bash-bot-with-filter.p6 (limited to 'examples/05-bash-bot-with-filter.p6') diff --git a/examples/05-bash-bot-with-filter.p6 b/examples/05-bash-bot-with-filter.p6 new file mode 100644 index 0000000..f3f2c3b --- /dev/null +++ b/examples/05-bash-bot-with-filter.p6 @@ -0,0 +1,30 @@ +use lib ; + +use IRC::Client; +use Pastebin::Shadowcat; +use Mojo::UserAgent:from; + +class Bash { + has @!quotes; + has $!ua = Mojo::UserAgent.new; + constant $BASH_URL = 'http://bash.org/?random1'; + + method irc-to-me ($ where /bash/) { + start self!fetch-quotes and @!quotes.shift; + } + method !fetch-quotes { + @!quotes ||= $!ua.get($BASH_URL).res.dom.find('.qt').each».all_text; + } +} + +.run with IRC::Client.new: + :nick + :host + :channels<#zofbot> + :debug + :plugins(Bash.new) + :filters( + -> $text where .lines > 1 || .chars > 300 { + Pastebin::Shadowcat.new.paste: $text.lines.join: "\n"; + } + ) -- cgit v1.1