Created
July 24, 2016 20:04
Star
You must be signed in to star a gist
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
| use IRC::Client; | |
| use Pastebin::Shadowcat; | |
| use Mojo::UserAgent:from<Perl5>; | |
| 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<MahBot> | |
| :host<irc.freenode.net> | |
| :channels<#perl6> | |
| :debug | |
| :plugins(Bash.new) | |
| :filters( | |
| -> $text where .lines > 5 or .chars > 300 { | |
| Pastebin::Shadowcat.new.paste: $text | |
| } | |
| ) |
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
| use IRC::Client; | |
| use Mojo::UserAgent:from<Perl5>; | |
| class Bash { | |
| constant $BASH_URL = 'http://bash.org/?random1'; | |
| has $!ua = Mojo::UserAgent.new; | |
| has @!quotes; | |
| 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<MahBot> | |
| :host<irc.freenode.net> | |
| :channels<#perl6> | |
| :debug | |
| :plugins(Bash.new) |
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
| use IRC::Client; | |
| use HTTP::Tinyish; | |
| use JSON::Fast; | |
| class GitHub::Notifications does IRC::Client::Plugin { | |
| has Str $.token = %*ENV<GITHUB_TOKEN>; | |
| has $!ua = HTTP::Tinyish.new; | |
| constant $API_URL = 'https://api.github.com/notifications'; | |
| method irc-connected ($) { | |
| react { | |
| whenever self!notification.grep(* > 0) -> $num { | |
| $.irc.send: :where<Zoffix> | |
| :text("You have $num unread notifications!") | |
| :notice; | |
| } | |
| } | |
| } | |
| method !notification { | |
| supply { | |
| loop { | |
| my $res = $!ua.get: $API_URL, :headers{ :Authorization("token $!token") }; | |
| $res<success> and emit +grep *.<unread>, |from-json $res<content>; | |
| sleep $res<headers><X-Poll-Interval> || 60; | |
| } | |
| } | |
| } | |
| } | |
| .run with IRC::Client.new: | |
| :nick<MahBot> | |
| :host<irc.freenode.net> | |
| :channels<#perl6> | |
| :debug | |
| :plugins(GitHub::Notifications.new) |
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
| use IRC::Client; | |
| class Trickster { | |
| multi method irc-to-me ($ where /time/) { DateTime.now } | |
| multi method irc-to-me ($ where /temp \s+ $<temp>=\d+ $<unit>=[F|C]/) { | |
| $<unit> eq 'F' ?? "That's {($<temp> - 32) × .5556}°C" | |
| !! "That's { $<temp> × 1.8 + 32 }°F" | |
| } | |
| } | |
| class BFF { method irc-to-me ($ where /'♥'/) { 'I ♥ YOU!' } } | |
| .run with IRC::Client.new: | |
| :nick<MahBot> | |
| :host<irc.freenode.net> | |
| :channels<#perl6> | |
| :debug | |
| :plugins(Trickster, BFF) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment