use lib ; use IRC::Client; use HTTP::Tinyish; use JSON::Fast; class GitHub::Notifications does IRC::Client::Plugin { has Str:D $.token = %*ENV; has $!ua = HTTP::Tinyish.new; constant $API_URL = 'https://api.github.com/notifications'; method irc-connected ($) { start react { whenever self!notification.grep(* > 0) -> $num { $.irc.send: :where :text("You have $num unread notifications!") :notice; } } } method !notification { supply { loop { my $res = $!ua.get: $API_URL, :headers{ :Authorization("token $!token") }; $res and emit +grep *., |from-json $res; sleep $res || 60; } } } } .run with IRC::Client.new: :nick :host(%*ENV // 'irc.freenode.net') :channels<#zofbot> :debug :plugins(GitHub::Notifications.new)