Skip to content

Instantly share code, notes, and snippets.

@Skarsnik
Created March 19, 2019 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skarsnik/36d62955b18fdb82ab5cb8feaaaa7a20 to your computer and use it in GitHub Desktop.
Save Skarsnik/36d62955b18fdb82ab5cb8feaaaa7a20 to your computer and use it in GitHub Desktop.
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