Discord.pm

filter: Statementstmt 66.6% 545 / 818 Branchbran 14.2% 45 / 316 Conditioncond 7.2% 4 / 55 MC/DCmcdc 6.9% 2 / 29 Subroutinesub 81.6% 142 / 174 Podpod n/a totaltotal 53.0% 738 / 1392 CC 182 SCAR 32.7
CC
182
Cov
50%
_event_guild_create
110.9
_discord_api
73.5
__ANON__
72.0
CRAP 26.3
↑ Summary Discord/Payload.pm »
1 package AnyEvent::Discord;
2 4 ▶use v5.14;
Subroutine __ANON__: called CC=1 SCAR=0.0
3 4 ▶use Moops;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 4  
5 4 ▶class AnyEvent::Discord 0.7 {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: called CC=1 SCAR=1.2
6 4 ▶ use Algorithm::Backoff::Exponential;
Subroutine __ANON__: called CC=1 SCAR=0.0
7 4 ▶ use AnyEvent::Discord::Payload;
Subroutine __ANON__: called CC=1 SCAR=0.0
8 1 ▶ use AnyEvent::WebSocket::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
9 1 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
10 1 ▶ use JSON qw(decode_json encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
11 1 ▶ use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
12 1 ▶ use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
13 1 ▶ use HTTP::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
14  
15 1 our $VERSION = '0.7';
16 1 has version => ( is => 'ro', isa => Str, default => $VERSION );
17  
18 1 has token => ( is => 'rw', isa => Str, required => 1 );
19 1 has base_uri => ( is => 'rw', isa => Str, default => 'https://discordapp.com/api' );
20 1 ▶ has socket_options => ( is => 'rw', isa => HashRef, default => sub { { max_payload_size => 1024 * 1024 } } );
Subroutine __ANON__: called CC=1 SCAR=0.0
21 1 has verbose => ( is => 'rw', isa => Num, default => 0 );
22 1 ▶ has user_agent => ( is => 'rw', isa => Str, default => sub { 'Perl-AnyEventDiscord/' . shift->VERSION } );
Subroutine __ANON__: called CC=1 SCAR=0.0
23  
24 1 ▶ has guilds => ( is => 'ro', isa => HashRef, default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
25 1 ▶ has channels => ( is => 'ro', isa => HashRef, default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
26 1 ▶ has users => ( is => 'ro', isa => HashRef, default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
27  
28 # UserAgent
29 1 ▶ has _ua => ( is => 'rw', default => sub { LWP::UserAgent->new() } );
Subroutine __ANON__: called CC=1 SCAR=0.0
30 # Caller-defined event handlers
31 1 ▶ has _events => ( is => 'ro', isa => HashRef, default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
32 # Internal-defined event handlers
33 1 has _internal_events => ( is => 'ro', isa => HashRef, builder => '_build_internal_events' );
34 # WebSocket
35 1 has _socket => ( is => 'rw' );
36 # Heartbeat timer
37 1 has _heartbeat => ( is => 'rw' );
38 # Last Sequence
39 1 has _sequence => ( is => 'rw', isa => Num, default => 0 );
40 # True if caller manually disconnected, to avoid reconnection
41 1 has _force_disconnect => ( is => 'rw', isa => Bool, default => 0 );
42 # Host the backoff algorithm for reconnection
43 1 ▶ has _backoff => ( is => 'ro', default => sub { Algorithm::Backoff::Exponential->new( initial_delay => 1 ) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
44  
45 1 ▶ method _build_internal_events() {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _build_internal_events: called CC=3 SCAR=12.3
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 3 0 3
if @_ != 0 0 3 3
46 return {
47 0 ▶ 'guild_create' => [sub { $self->_event_guild_create(@_); }],
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 0 ▶ 'guild_delete' => [sub { $self->_event_guild_delete(@_); }],
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 0 ▶ 'channel_create' => [sub { $self->_event_channel_create(@_); }],
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 ▶ 'channel_delete' => [sub { $self->_event_channel_delete(@_); }],
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 0 ▶ 'guild_member_create' => [sub { $self->_event_guild_member_create(@_); }],
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 0 ▶ 'guild_member_remove' => [sub { $self->_event_guild_member_remove(@_); }]
Subroutine __ANON__: not called CC=1 SCAR=1.2
53 };
54 }
55  
56 1 ▶ method on(Str $event_type, CodeRef $handler) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine on: called CC=11 SCAR=24.2
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 8 branches
BranchTrueFalseTotal
@_ ? : 5 0 5
if @_ != 2 0 5 5
$#_ >= 0 ? : 5 0 5
if ($#_ >= 0) 5 0 5
Type::Tiny::XS::Str($event_type) or _failed_check(9, "Str", $event_type, "exception_class", "Error::TypeTiny::Assertion") 5 0 5
$#_ >= 1 ? : 5 0 5
if ($#_ >= 1) 5 0 5
Ref::Util::XS::is_plain_coderef($handler) or _failed_check(17, "CodeRef", $handler, "exception_class", "Error::TypeTiny::Assertion") 5 0 5
57 5 $event_type = lc($event_type);
58 5 $self->_debug('Requesting attach of handler ' . $handler . ' to event ' . $event_type);
59  
60 5 ▶ $self->_events->{$event_type} //= [];
Condition100%2/2
$self->_events->{$event_type} //= []
l!l
23
MC/DC100%1/1
$self->_events->{$event_type} //= []
$self->_events->{$event_type}
Truth table100%2/2
A
A= $self->_events->{$event_type}
Aresult
11
00
61 5 ▶ return if (scalar(grep { $_ eq $handler } @{$self->_events->{$event_type}}) > 0);
Branch: 1 branch
BranchTrueFalseTotal
if scalar grep({$_ eq $handler;} @{$self->_events->{$event_type};}) > 0 1 4 5
62  
63 4 $self->_debug('Attaching handler ' . $handler . ' to event ' . $event_type);
64 4 push( @{$self->_events->{$event_type}}, $handler );
65 }
66  
67 1 ▶ method off(Str $event_type, CodeRef $handler?) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine off: called CC=15 SCAR=27.2
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 9 branches
BranchTrueFalseTotal
@_ ? : 3 0 3
if @_ < 1 0 3 3
if @_ > 2 0 3 3
$#_ >= 0 ? : 3 0 3
if ($#_ >= 0) 3 0 3
Type::Tiny::XS::Str($event_type) or _failed_check(9, "Str", $event_type, "exception_class", "Error::TypeTiny::Assertion") 3 0 3
$#_ >= 1 ? : 2 1 3
if ($#_ >= 1) 2 1 3
Ref::Util::XS::is_plain_coderef($handler) or _failed_check(17, "CodeRef", $handler, "exception_class", "Error::TypeTiny::Assertion") 2 0 2
68 3 $event_type = lc($event_type);
69 3 ▶ $self->_debug('Requesting detach of handler ' . ($handler or 'n/a') . ' from event ' . $event_type);
Condition100%2/2
$handler || 'n/a'
l!l
21
MC/DC100%1/1
$handler || 'n/a'
$handler
Truth table100%2/2
A
A= $handler
Aresult
11
00
70 3 ▶ if ($self->_events->{$event_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_events->{$event_type}) 3 0 3
71 3 ▶ if ($handler) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler) { } 2 1 3
72 2 my $index = 0;
73 2 ▶ while ($index < scalar(@{$self->_events->{$event_type}})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < scalar @{$self->_events->{$event_type};}) 2 2 4
74 2 ▶ if ($self->_events->{$event_type}->[$index] eq $handler) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_events->{$event_type}[$index] eq $handler) 1 1 2
75 1 $self->_debug('Detaching handler ' . $handler . ' from event ' . $event_type);
76 1 splice( @{$self->_events->{$event_type}}, $index, 1 );
77 }
78 2 $index++;
79 }
80 } else {
81 1 $self->_debug('Detaching ' . scalar(@{$self->_events->{$event_type}}) . ' handler(s) from event ' . $event_type);
82 1 delete($self->_events->{$event_type});
83 }
84 }
85 }
86  
87 0 ▶ method connect() {
Subroutine BEGIN: called CC=1 SCAR=1.0
Subroutine connect: not called CC=3 SCAR=22.7
Subroutine __ANON__: called CC=1 SCAR=1.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
88 0 my $gateway = $self->_lookup_gateway();
89  
90 0 $self->_debug('Connecting to ' . $gateway);
91  
92 0 my $ws = AnyEvent::WebSocket::Client->new($self->socket_options);
93 0 ▶ $ws->connect($gateway)->cb(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
94 0 my $socket = eval { shift->recv };
95 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
96 0 $self->_debug('Received error connecting: ' . $@);
97 0 $self->_handle_internal_event('error', $@);
98 0 return;
99 }
100 0 $self->_debug('Connected to ' . $gateway);
101  
102 0 $self->_socket($socket);
103
104 # If we send malformed content, bail out
105 0 ▶ $socket->on('parse_error', sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
106 0 my ($c, $error) = @_;
107 0 $self->_debug(Data::Dumper::Dumper($error));
108 0 die $error;
109 0 });
110  
111 # Handle reconnection
112 0 ▶ $socket->on('finish', sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
113 0 my ($c) = @_;
114 0 $self->_debug('Received disconnect');
115 0 $self->_handle_internal_event('disconnected');
116 0 ▶ unless ($self->_force_disconnect()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_force_disconnect) 0 0 0
117 0 my $seconds = $self->_backoff->failure();
118 0 $self->_debug('Reconnecting in ' . $seconds);
119 0 my $reconnect;
120 $reconnect = AnyEvent->timer(
121 after => $seconds,
122 0 ▶ cb => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
123 0 $self->connect();
124 0 $reconnect = undef;
125 0 AnyEvent->condvar->send();
126 }
127 0 );
128 }
129 0 });
130  
131 # Event handler
132 0 ▶ $socket->on('each_message', sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
133 0 my ($c, $message) = @_;
134 0 $self->_trace('ws in: ' . $message->{'body'});
135 0 my $payload;
136 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
137 0 $payload = AnyEvent::Discord::Payload->from_json($message->{'body'});
138 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
139 0 $self->_debug($_);
140 0 return;
141 0 };
142 0 ▶ unless ($payload and defined $payload->op) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($payload and defined $payload->op) 0 0 0
Condition0%0/3
$payload and defined $payload->op
!ll&&!rl&&r
000
MC/DC0%0/2
$payload and defined $payload->op
$payload defined $payload->op
Truth table0%0/3
A and B
A= $payloadB= defined $payload->op
ABresult
0X0
100
111
143 0 $self->_debug('Invalid payload received from Discord: ' . $message->{'body'});
144 0 return;
145 }
146 0 ▶ $self->_sequence(0 + $payload->s) if ($payload->s and $payload->s > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $payload->s and $payload->s > 0 0 0 0
Condition0%0/3
$payload->s and $payload->s > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$payload->s and $payload->s > 0
$payload->s $payload->s > 0
Truth table0%0/3
A and B
A= $payload->sB= $payload->s > 0
ABresult
0X0
100
111
147  
148 0 ▶ if ($payload->op == 10) {
Branch: 2 branches
BranchTrueFalseTotal
if ($payload->op == 10) { } 0 0 0
elsif ($payload->d) { } 0 0 0
149 0 $self->_event_hello($payload);
150 } elsif ($payload->d) {
151 0 ▶ if ($payload->d->{'author'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($payload->d->{"author"}) 0 0 0
152 0 my $user = $payload->d->{'author'};
153 0 $self->users->{$user->{'id'}} = $user->{'username'};
154 }
155 0 $self->_handle_event($payload);
156 }
157 0 });
158  
159 0 $self->_discord_identify();
160 0 $self->_debug('Completed connection sequence');
161 0 $self->_backoff->success();
162 0 AnyEvent->condvar->send();
163 0 });
164 }
165  
166 0 ▶ method send($channel_id, $content) {
Subroutine BEGIN: called CC=1 SCAR=2.1
Subroutine send: not called CC=5 SCAR=24.4
Subroutine __ANON__: called CC=1 SCAR=2.1
Branch: 4 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 2 0 0 0
$#_ >= 0 ? : 0 0 0
$#_ >= 1 ? : 0 0 0
167 0 return $self->_discord_api('POST', 'channels/' . $channel_id . '/messages', encode_json({content => $content}));
168 }
169  
170 0 ▶ method typing($channel_id) {
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine typing: not called CC=4 SCAR=20.5
Subroutine __ANON__: called CC=1 SCAR=1.6
Branch: 3 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
171 return AnyEvent->timer(
172 after => 0,
173 interval => 5,
174 0 ▶ cb => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
175 0 $self->_discord_api('POST', 'channels/' . $channel_id . '/typing');
176 0 AnyEvent->condvar->send();
177 },
178 0 );
179 }
180  
181 0 ▶ method close() {
Subroutine BEGIN: called CC=1 SCAR=1.0
Subroutine close: not called CC=3 SCAR=15.6
Subroutine __ANON__: called CC=1 SCAR=1.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
182 0 $self->_force_disconnect(1);
183 0 $self->{'_heartbeat'} = undef;
184 0 $self->{'_sequence'} = undef;
185 0 $self->_socket->close();
186 }
187  
188 # Make an HTTP request to the Discord API
189 0 ▶ method _discord_api(Str $method, Str $path, $payload?) {
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine _discord_api: not called CC=13 SCAR=43.0
Subroutine __ANON__: called CC=1 SCAR=2.3
Subroutine __ANON__: called CC=1 SCAR=2.3
Subroutine __ANON__: called CC=1 SCAR=2.3
Branch: 10 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ < 2 0 0 0
if @_ > 3 0 0 0
$#_ >= 0 ? : 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($method) or _failed_check(9, "Str", $method, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 1 ? : 0 0 0
if ($#_ >= 1) 0 0 0
Type::Tiny::XS::Str($path) or _failed_check(9, "Str", $path, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 2 ? : 0 0 0
190 0 my $headers = HTTP::Headers->new(
191 Authorization => 'Bot ' . $self->token,
192 User_Agent => $self->user_agent,
193 Content_Type => 'application/json',
194 );
195 0 my $request = HTTP::Request->new(
196 uc($method),
197 join('/', $self->base_uri, $path),
198 $headers,
199 $payload,
200 );
201 0 $self->_trace('api req: ' . $request->as_string());
202 0 my $res = $self->_ua->request($request);
203 0 $self->_trace('api res: ' . $res->as_string());
204 0 ▶ if ($res->is_success()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) 0 0 0
205 0 ▶ if ($res->header('Content-Type') eq 'application/json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->header('Content-Type') eq 'application/json') { } 0 0 0
206 0 return decode_json($res->decoded_content());
207 } else {
208 0 return $res->decoded_content();
209 }
210 }
211 0 return;
212 }
213  
214 # Send the 'identify' event to the Discord websocket
215 0 ▶ method _discord_identify() {
Subroutine BEGIN: called CC=1 SCAR=1.0
Subroutine _discord_identify: not called CC=3 SCAR=14.7
Subroutine __ANON__: called CC=1 SCAR=1.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
216 0 $self->_debug('Sending identify');
217 0 $self->_ws_send_payload(AnyEvent::Discord::Payload->from_hashref({
218 op => 2,
219 d => {
220 token => $self->token,
221 compress => JSON::false,
222 large_threshold => 250,
223 shard => [0, 1],
224 properties => {
225 '$os' => 'linux',
226 '$browser' => $self->user_agent(),
227 '$device' => $self->user_agent(),
228 }
229 }
230 }));
231 }
232  
233 # Send a payload to the Discord websocket
234 0 ▶ method _ws_send_payload(AnyEvent::Discord::Payload $payload) {
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine _ws_send_payload: not called CC=7 SCAR=30.2
Subroutine __ANON__: called CC=1 SCAR=1.6
Subroutine __ANON__: called CC=1 SCAR=1.6
Branch: 5 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::AUTO::TC2($payload) or _failed_check(81, "InstanceOf[\"AnyEvent::Discord::Payload\"]", $payload, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
235 0 ▶ unless ($self->_socket) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_socket) 0 0 0
236 0 $self->_debug('Attempted to send payload to disconnected socket');
237 0 return;
238 }
239 0 my $msg = $payload->as_json;
240 0 $self->_trace('ws out: ' . $msg);
241 0 $self->_socket->send($msg);
242 }
243  
244 # Look up the gateway endpoint using the Discord API
245 0 ▶ method _lookup_gateway() {
Subroutine BEGIN: called CC=1 SCAR=1.0
Subroutine _lookup_gateway: not called CC=7 SCAR=33.0
Subroutine __ANON__: called CC=1 SCAR=1.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
246 0 my $payload = $self->_discord_api('GET', 'gateway');
247 0 ▶ die 'Invalid gateway returned by API' unless ($payload and $payload->{url} and $payload->{url} =~ /^wss/);
Branch: 1 branch
BranchTrueFalseTotal
unless $payload and $payload->{"url"} and $payload->{"url"} =~ /^wss/u 0 0 0
Condition0%0/6
$payload and $payload->{"url"} and $payload->{"url"} =~ /^wss/u
!ll&&!rl&&r
000
$payload and $payload->{"url"}
!ll&&!rl&&r
000
MC/DC0%0/3
$payload and $payload->{"url"} and $payload->{"url"} =~ /^wss/u
$payload $payload->{"url"} $payload->{"url"} =~ /^wss/u
Truth table0%0/4
A and B and C
A= $payloadB= $payload->{"url"}C= $payload->{"url"} =~ /^wss/u
ABCresult
0XX0
10X0
1100
1111
248  
249 # Add the requested version and encoding to the provided URL
250 0 my $gateway = $payload->{url};
251 0 ▶ $gateway .= '/' unless ($gateway =~/\/$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $gateway =~ m[/$]u 0 0 0
252 0 $gateway .= '?v=6&encoding=json';
253 0 return $gateway;
254 }
255  
256 # Dispatch an internal event type
257 0 ▶ method _handle_internal_event(Str $type) {
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine _handle_internal_event: not called CC=9 SCAR=35.0
Subroutine __ANON__: called CC=1 SCAR=1.6
Subroutine __ANON__: called CC=1 SCAR=1.6
Branch: 5 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($type) or _failed_check(9, "Str", $type, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
258 0 foreach my $event_source (qw(_internal_events _events)) {
259 0 ▶ if ($self->{$event_source}->{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{$event_source}{$type}) 0 0 0
260 map {
261 0 ▶ $self->_debug('Sending ' . ( $event_source =~ /internal/ ? 'internal' : 'caller' ) . ' event ' . $type);
Branch: 1 branch
BranchTrueFalseTotal
$event_source =~ /internal/u ? : 0 0 0
262 0 $_->($self);
263 0 } @{ $self->{$event_source}->{$type} };
264 }
265 }
266 }
267  
268 # Dispatch a Discord event type
269 1 ▶ method _handle_event(AnyEvent::Discord::Payload $payload) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _handle_event: called CC=9 SCAR=22.1
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 5 branches
BranchTrueFalseTotal
@_ ? : 4 0 4
if @_ != 1 0 4 4
$#_ >= 0 ? : 4 0 4
if ($#_ >= 0) 4 0 4
Type::Tiny::XS::AUTO::TC2($payload) or _failed_check(81, "InstanceOf[\"AnyEvent::Discord::Payload\"]", $payload, "exception_class", "Error::TypeTiny::Assertion") 4 0 4
270 4 my $type = lc($payload->t);
271 4 $self->_debug('Got event ' . $type);
272 4 foreach my $event_source (qw(_internal_events _events)) {
273 8 ▶ if ($self->{$event_source}->{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{$event_source}{$type}) 4 4 8
274 map {
275 4 ▶ $self->_debug('Sending ' . ( $event_source =~ /internal/ ? 'internal' : 'caller' ) . ' event ' . $type);
Branch: 1 branch
BranchTrueFalseTotal
$event_source =~ /internal/u ? : 2 2 4
276 4 $_->($self, $payload->d, $payload->op);
277 4 } @{ $self->{$event_source}->{$type} };
278 }
279 }
280 }
281  
282 # Send debug messages to console if verbose is >=1
283 1 ▶ method _debug(Str $message) {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine _debug: called CC=7 SCAR=19.8
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 5 branches
BranchTrueFalseTotal
@_ ? : 22 0 22
if @_ != 1 0 22 22
$#_ >= 0 ? : 22 0 22
if ($#_ >= 0) 22 0 22
Type::Tiny::XS::Str($message) or _failed_check(9, "Str", $message, "exception_class", "Error::TypeTiny::Assertion") 22 0 22
284 22 ▶ say time . ' ' . $message if ($self->verbose);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 22 22
285 }
286  
287 # Send trace messages to console if verbose is 2
288 0 ▶ method _trace(Str $message) {
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine _trace: not called CC=8 SCAR=31.8
Subroutine __ANON__: called CC=1 SCAR=1.6
Subroutine __ANON__: called CC=1 SCAR=1.6
Branch: 5 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::Str($message) or _failed_check(9, "Str", $message, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
289 0 ▶ say time . ' ' . $message if ($self->verbose and $self->verbose == 2);
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose and $self->verbose == 2 0 0 0
Condition0%0/3
$self->verbose and $self->verbose == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$self->verbose and $self->verbose == 2
$self->verbose $self->verbose == 2
Truth table0%0/3
A and B
A= $self->verboseB= $self->verbose == 2
ABresult
0X0
100
111
290 }
291  
292 # Called when Discord provides the 'hello' event
293 0 ▶ method _event_hello(AnyEvent::Discord::Payload $payload) {
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine BEGIN: called CC=1 SCAR=1.6
Subroutine _event_hello: not called CC=6 SCAR=27.4
Subroutine __ANON__: called CC=1 SCAR=1.6
Subroutine __ANON__: called CC=1 SCAR=1.6
Branch: 5 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 1 0 0 0
$#_ >= 0 ? : 0 0 0
if ($#_ >= 0) 0 0 0
Type::Tiny::XS::AUTO::TC2($payload) or _failed_check(81, "InstanceOf[\"AnyEvent::Discord::Payload\"]", $payload, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
294 0 $self->_debug('Received hello event');
295 0 my $interval = $payload->d->{'heartbeat_interval'};
296 my $timer = AnyEvent->timer(
297 after => $interval * rand() / 1000,
298 interval => $interval / 1000,
299 0 ▶ cb => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
300 0 $self->_debug('Heartbeat');
301 0 $self->_ws_send_payload(AnyEvent::Discord::Payload->from_hashref({
302 op => 1,
303 d => $self->_sequence()
304 }));
305 0 AnyEvent->condvar->send();
306 }
307 0 );
308 0 $self->_heartbeat($timer);
309 }
310  
311 # GUILD_CREATE event
312 0 ▶ method _event_guild_create($client, HashRef $data, Num $opcode?) {
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine _event_guild_create: not called CC=16 SCAR=47.1
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Branch: 10 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ < 2 0 0 0
if @_ > 3 0 0 0
$#_ >= 0 ? : 0 0 0
$#_ >= 1 ? : 0 0 0
if ($#_ >= 1) 0 0 0
Ref::Util::XS::is_plain_hashref($data) or _failed_check(22, "HashRef", $data, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 2 ? : 0 0 0
if ($#_ >= 2) 0 0 0
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode) or _failed_check(12, "Num", $opcode, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/6
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode)
!ll&&!rl&&r
000
defined $opcode and not ref $opcode
!ll&&!rl&&r
000
MC/DC0%0/3
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode)
defined $opcode not ref $opcode &Scalar::Util::looks_like_number($opcode)
Truth table0%0/4
A and not(B) and C
A= defined $opcodeB= not ref $opcodeC= &Scalar::Util::looks_like_number($opcode)
ABCresult
0XX0
10X0
1100
1111
313 0 $self->guilds->{$data->{'id'}} = $data->{'name'};
314  
315 # We get channel and user information along with the guild, populate those
316 # at the same time
317 0 foreach my $channel (@{$data->{'channels'}}) {
318 0 ▶ if ($channel->{'type'} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($channel->{"type"} == 0) 0 0 0
319 0 $self->channels->{$channel->{'id'}} = $channel->{'name'};
320 }
321 }
322 0 foreach my $user (@{$data->{'members'}}) {
323 0 $self->users->{$user->{'user'}->{'id'}} = $user->{'user'}->{'username'};
324 }
325 }
326  
327 # GUILD_DELETE event
328 0 ▶ method _event_guild_delete($client, HashRef $data, Num $opcode?) {
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine _event_guild_delete: not called CC=13 SCAR=41.8
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Branch: 10 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ < 2 0 0 0
if @_ > 3 0 0 0
$#_ >= 0 ? : 0 0 0
$#_ >= 1 ? : 0 0 0
if ($#_ >= 1) 0 0 0
Ref::Util::XS::is_plain_hashref($data) or _failed_check(22, "HashRef", $data, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 2 ? : 0 0 0
if ($#_ >= 2) 0 0 0
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode) or _failed_check(12, "Num", $opcode, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/6
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode)
!ll&&!rl&&r
000
defined $opcode and not ref $opcode
!ll&&!rl&&r
000
MC/DC0%0/3
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode)
defined $opcode not ref $opcode &Scalar::Util::looks_like_number($opcode)
Truth table0%0/4
A and not(B) and C
A= defined $opcodeB= not ref $opcodeC= &Scalar::Util::looks_like_number($opcode)
ABCresult
0XX0
10X0
1100
1111
329 0 delete($self->guilds->{$data->{'id'}});
330 }
331  
332 # CHANNEL_CREATE event
333 0 ▶ method _event_channel_create($client, HashRef $data, Num $opcode?) {
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine _event_channel_create: not called CC=13 SCAR=41.8
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Branch: 10 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ < 2 0 0 0
if @_ > 3 0 0 0
$#_ >= 0 ? : 0 0 0
$#_ >= 1 ? : 0 0 0
if ($#_ >= 1) 0 0 0
Ref::Util::XS::is_plain_hashref($data) or _failed_check(22, "HashRef", $data, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 2 ? : 0 0 0
if ($#_ >= 2) 0 0 0
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode) or _failed_check(12, "Num", $opcode, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/6
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode)
!ll&&!rl&&r
000
defined $opcode and not ref $opcode
!ll&&!rl&&r
000
MC/DC0%0/3
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode)
defined $opcode not ref $opcode &Scalar::Util::looks_like_number($opcode)
Truth table0%0/4
A and not(B) and C
A= defined $opcodeB= not ref $opcodeC= &Scalar::Util::looks_like_number($opcode)
ABCresult
0XX0
10X0
1100
1111
334 0 $self->channels->{$data->{'id'}} = $data->{'name'};
335 }
336  
337 # CHANNEL_DELETE event
338 0 ▶ method _event_channel_delete($client, HashRef $data, Num $opcode?) {
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine _event_channel_delete: not called CC=13 SCAR=41.8
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Branch: 10 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ < 2 0 0 0
if @_ > 3 0 0 0
$#_ >= 0 ? : 0 0 0
$#_ >= 1 ? : 0 0 0
if ($#_ >= 1) 0 0 0
Ref::Util::XS::is_plain_hashref($data) or _failed_check(22, "HashRef", $data, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 2 ? : 0 0 0
if ($#_ >= 2) 0 0 0
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode) or _failed_check(12, "Num", $opcode, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/6
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode)
!ll&&!rl&&r
000
defined $opcode and not ref $opcode
!ll&&!rl&&r
000
MC/DC0%0/3
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode)
defined $opcode not ref $opcode &Scalar::Util::looks_like_number($opcode)
Truth table0%0/4
A and not(B) and C
A= defined $opcodeB= not ref $opcodeC= &Scalar::Util::looks_like_number($opcode)
ABCresult
0XX0
10X0
1100
1111
339 0 delete($self->channels->{$data->{'id'}});
340 }
341  
342 # GUILD_MEMBER_CREATE event
343 0 ▶ method _event_guild_member_create($client, HashRef $data, Num $opcode?) {
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine _event_guild_member_create: not called CC=13 SCAR=41.8
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Branch: 10 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ < 2 0 0 0
if @_ > 3 0 0 0
$#_ >= 0 ? : 0 0 0
$#_ >= 1 ? : 0 0 0
if ($#_ >= 1) 0 0 0
Ref::Util::XS::is_plain_hashref($data) or _failed_check(22, "HashRef", $data, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 2 ? : 0 0 0
if ($#_ >= 2) 0 0 0
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode) or _failed_check(12, "Num", $opcode, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/6
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode)
!ll&&!rl&&r
000
defined $opcode and not ref $opcode
!ll&&!rl&&r
000
MC/DC0%0/3
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode)
defined $opcode not ref $opcode &Scalar::Util::looks_like_number($opcode)
Truth table0%0/4
A and not(B) and C
A= defined $opcodeB= not ref $opcodeC= &Scalar::Util::looks_like_number($opcode)
ABCresult
0XX0
10X0
1100
1111
344 0 $self->users->{$data->{'id'}} = $data->{'username'};
345 }
346  
347 # GUILD_MEMBER_REMOVE event
348 0 ▶ method _event_guild_member_remove($client, HashRef $data, Num $opcode?) {
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine BEGIN: called CC=1 SCAR=2.7
Subroutine _event_guild_member_remove: not called CC=13 SCAR=41.8
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Subroutine __ANON__: called CC=1 SCAR=2.7
Branch: 10 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ < 2 0 0 0
if @_ > 3 0 0 0
$#_ >= 0 ? : 0 0 0
$#_ >= 1 ? : 0 0 0
if ($#_ >= 1) 0 0 0
Ref::Util::XS::is_plain_hashref($data) or _failed_check(22, "HashRef", $data, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
$#_ >= 2 ? : 0 0 0
if ($#_ >= 2) 0 0 0
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode) or _failed_check(12, "Num", $opcode, "exception_class", "Error::TypeTiny::Assertion") 0 0 0
Condition0%0/6
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode)
!ll&&!rl&&r
000
defined $opcode and not ref $opcode
!ll&&!rl&&r
000
MC/DC0%0/3
defined $opcode and not ref $opcode and &Scalar::Util::looks_like_number($opcode)
defined $opcode not ref $opcode &Scalar::Util::looks_like_number($opcode)
Truth table0%0/4
A and not(B) and C
A= defined $opcodeB= not ref $opcodeC= &Scalar::Util::looks_like_number($opcode)
ABCresult
0XX0
10X0
1100
1111
349 0 delete($self->users->{$data->{'id'}});
350 }
351 }
352  
353 4 1;
354  
355 =pod
356  
357 =head1 NAME
358  
359 AnyEvent::Discord - Provides an AnyEvent interface to the Discord bot API
360  
361 =head1 SYNOPSIS
362  
363 use AnyEvent::Discord;
364 my $client = AnyEvent::Discord->new({ token => 'mydiscordbottoken' });
365 $client->on('ready', sub { warn 'Connected'; });
366 $client->on('message_create', sub {
367 my ($client, $data) = @_;
368 warn '[' . $client->channels->{$data->{channel_id}} . ']' .
369 '(' . $data->{author}->{username} . ') - ' .
370 $data->{content};
371 });
372 $client->connect();
373 AnyEvent->condvar->recv;
374  
375 =head1 DESCRIPTION
376  
377 This module provides an AnyEvent interface for the Discord API over the REST
378 and WebSocket APIs. It is designed to be somewhat similar to the SlackRTM and
379 XMPP modules, with a subset of their far more mature functionality.
380  
381 To get started, one needs to create a new application in the Discord Developer
382 Portal (https://discord.com/developers). Once an application is created, a token
383 can be captured by navigating to the "Bot" tab on the left side and selecting
384 'Click to Reveal Token'. That generated token is the same token required by this
385 module.
386  
387 =head1 CONFIGURATION ACCESSORS
388  
389 =over 4
390  
391 =item token (String) (required)
392  
393 The token generated by the Discord Application portal, under Bot.
394  
395 =item base_uri (String) (optional)
396  
397 The base URI for communicating with the Discord API.
398  
399 =item socket_options (HashRef) (optional)
400  
401 Used to override options to sent to AnyEvent::WebSocket::Client, if needed.
402  
403 =item verbose (Num) (defaults to 0)
404  
405 Verbose output, writes internal debug information at 1, additionally writes
406 network conversation at 2.
407  
408 =back
409  
410 =head1 DATA ACCESSORS
411  
412 =over 4
413  
414 =item guilds
415  
416 Available/created/seen guilds, as a hashmap of id => name
417  
418 =item channels
419  
420 Available/created/seen channels, as a hashmap of id => name
421  
422 =item users
423  
424 Available/created/seen users, as a hashmap of id => name
425  
426 =back
427  
428 =head1 PUBLIC METHODS
429  
430 =over 4
431  
432 =item new(\%arguments)
433  
434 Instantiate the AnyEvent::Discord client. The hashref of arguments matches the
435 configuration accessors listed above. A common invocation looks like:
436  
437 my $client = AnyEvent::Discord->new({ token => 'ABCDEF' });
438  
439 =item on($event_type, \&handler)
440  
441 Attach an event handler to a defined event type. If an invalid event type is
442 specified, no error will occur -- this is mostly to be able to handle events
443 that are created after this module is published. This is an append method, so
444 calling on() for an event multiple times will call each callback assigned. If
445 the handler already exists for an event, no error will be returned, but the
446 handler will not be called twice.
447  
448 Discord event types: https://discord.com/developers/docs/topics/gateway#list-of-intents
449  
450 Opcodes: https://discord.com/developers/docs/topics/opcodes-and-status-codes#gateway-opcodes
451  
452 These events receive the parameters client, data object (d) and the opcode (op).
453 The $client variable is this instance of AnyEvent::Discord, and the contents of
454 $data and $op are dependent on the event type.
455  
456 sub event_responder {
457 my ($client, $data, $opcode) = @_;
458 return;
459 }
460  
461 Internal event types:
462  
463 =over 4
464  
465 =item disconnected
466  
467 Receives no parameters, just notifies a disconnection will occur. It will
468 auto reconnect.
469  
470 =item error
471  
472 Receives an error message as a parameter, allows internal handling of errors
473 that are not a hard failure.
474  
475 =back
476  
477 =item off($event_type, \&handler?)
478  
479 Detach an event handler from a defined event type. If the handler does not
480 exist for the event, no error will be returned. If no handler is provided, all
481 handlers for the event type will be removed.
482  
483 =item connect()
484  
485 Start connecting to the Discord API and return immediately. In a new AnyEvent
486 application, this would come before executing "AnyEvent->condvar->recv". This
487 method will retrieve the available gateway endpoint, create a connection,
488 identify itself, begin a heartbeat, and once complete, Discord will fire a
489 'ready' event to the handler.
490  
491 =item send($channel_id, $content)
492  
493 Send a message to the provided channel.
494  
495 =item typing($channel_id)
496  
497 Starts the "typing..." indicator in the provided channel. This method issues the
498 typing request, and starts a timer on the caller's behalf to keep the indicator
499 active. Returns an instance of that timer to allow the caller to undef it when
500 the typing indicator should be stopped.
501  
502 my $instance = $client->typing($channel);
503 # ... perform some actions
504 $instance = undef;
505 # typing indicator disappears
506  
507 =item close()
508  
509 Close the connection to the server.
510  
511 =back
512  
513 =head1 CAVEATS
514  
515 This is incredibly unfinished.
516  
517 =head1 AUTHOR
518  
519 Nick Melnick <nmelnick@cpan.org>
520  
521 =head1 COPYRIGHT AND LICENSE
522  
523 This software is copyright (c) 2021, Nick Melnick.
524  
525 This is free software; you can redistribute it and/or modify it under the same
526 terms as the Perl 5 programming language system itself.
527  
528 =cut
↑ Summary Discord/Payload.pm »