Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created July 24, 2016 20:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save zoffixznet/ae146b8fc8fc1f153ba75da5d52e25b2 to your computer and use it in GitHub Desktop.
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
}
)
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)
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)
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