Last active
July 4, 2018 22:28
-
-
Save Altreus/4e151a172698ff0d08f47a7d33ef5cbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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