examples/messages.pl

filter: Statementstmt 100% 25 / 25 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 94.8% 37 / 39 CC 3 SCAR 5.1
CC
3
Cov
97%
respond_to_message
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« blib/lib/Discord/Client/Model/Guild.pm ↑ Summary examples/channels.pl »
1 #!/usr/bin/env perl
2 1 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use lib "$FindBin::Bin/../lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Discord::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # Enable Message Content in the Developer Portal before running this example.
10 my $bot = Discord::Client->new(
11 token => $ENV{DISCORD_BOT_TOKEN},
12 1 intents => [ 'GUILDS', 'GUILD_MESSAGES', 'DIRECT_MESSAGES', 'MESSAGE_CONTENT' ],
13 );
14  
15 # A message already knows how to reply and which channel it belongs to.
16 3 ▶sub respond_to_message {
Subroutine respond_to_message: called CC=3 SCAR=11.0
Pod undocumented
17 3 my ( $message, $bot ) = @_;
18  
19 # Ignore other bots before checking the command to avoid automated reply loops.
20 3 ▶ return if $message->is_from_bot;
Branch: 1 branch
BranchTrueFalseTotal
if $message->is_from_bot 1 2 3
21 2 ▶ return unless $message->content eq '!ping';
Branch: 1 branch
BranchTrueFalseTotal
unless $message->content eq "!ping" 1 1 2
22  
23 # Return the pending reply so the client can track it and cancel it during shutdown.
24 1 return $message->reply('Pong!');
25 }
26 1 $bot->on_message( \&respond_to_message );
27  
28 # Run the bot; message events need no application-command deployment.
29 1 ▶$bot->run unless caller;
Branch: 1 branch
BranchTrueFalseTotal
unless caller 0 1 1
30 1 $bot;
« blib/lib/Discord/Client/Model/Guild.pm ↑ Summary examples/channels.pl »