Skip to content

Instantly share code, notes, and snippets.

@Skarsnik Skarsnik/supply.p6
Created Mar 19, 2019

Embed
What would you like to do?
use API::Discord;
#use IRC::Client;
use Config::Simple;
use GithubNotif;
use HTTP::Tinyish;
my $ua = HTTP::Tinyish.new;
#https://discordapp.com/api/oauth2/authorize?client_id=555485913912836106&scope=bot&permissions=2048
my $config = Config::Simple.read("auth-token.p6");
my $discord-token = $config<discord-token>;
my $github-token = $config<github-token>;
my $discord = API::Discord.new(:token($discord-token));
await $discord.connect;
say "Connected";
await $discord.ready;
say "Ready";
await github-notif-init($github-token, $discord);
react {
whenever $discord.messages -> $message {
}
whenever supply {
loop {
my $res = $ua.get: $GITHUB_API_URL, :headers{ :Authorization("token $github-token") };
say "Getting GH notification : ", $res<success>;
#say from-json $res<content>;
$res<success> and emit (from-json $res<content>).grep: {$_<unread> == True};
sleep $res<headers><X-Poll-Interval> || 60;
}
} -> @events {
say "Notifications : ", +@events, " events";
gh-process-event($_) for @events;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.