Skip to content

Instantly share code, notes, and snippets.

@Altreus
Last active July 4, 2018 22:28
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 Altreus/4e151a172698ff0d08f47a7d33ef5cbb to your computer and use it in GitHub Desktop.
Save Altreus/4e151a172698ff0d08f47a7d33ef5cbb to your computer and use it in GitHub Desktop.
unit module API::Discord;
use Cro::WebSocket::Client;
use Cro::WebSocket::Client::Connection;
class API::Discord::Connection {...}
class API::Discord is export {
has Cro::WebSocket::Client $!cli;
has API::Discord::Connection $!conn;
has $.version = 6;
method connect() returns Promise {
$!cli = Cro::WebSocket::Client.new: :json;
my $c = $!cli.connect("wss://gateway.discord.gg/?v={$.v}&encoding=json");
my $p = Promise.new;
$c.then({ $p.keep(API::Discord::Connection.new(cro-conn => $^a)) });
return $p;
}
}
class API::Discord::Connection is export {
has Cro::WebSocket::Client::Connection $!cro-conn;
has $!token;
submethod TWEAK() {
# setup heartbeat
}
method auth ($token?) {
$!token = $token if $token;
die "No token" if not $!token;
$!cro-conn.send({
op => 2,
d => {
token => $!token,
properties => {
'$os' => $*PERL,
'$browser' => 'API::Discord',
'$device' => 'API::Discord',
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment