examples/modal.pl

filter: Statementstmt 100% 30 / 30 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 97.5% 40 / 41 CC 1 SCAR 0.0
CC
1
Cov
97%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« examples/components.pl ↑ Summary blib/lib/Discord/Client/REST/Error.pm »
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 1 ▶use Discord::Client::UI qw(text_input modal);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Configure a bot with a feedback form.
11 my $bot = Discord::Client->new(
12 token => $ENV{DISCORD_BOT_TOKEN},
13 1 intents => ['GUILDS'],
14 );
15  
16 # Opening the form acknowledges the slash command.
17 $bot->command(
18 feedback => (
19 description => 'Send feedback',
20 1 ▶ handler => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
21 1 my ($interaction) = @_;
22  
23 # Declare the field once; its ID is also used when reading the submission.
24 1 return $interaction->modal(
25 modal(
26 'feedback_form',
27 title => 'Feedback',
28 fields => [
29 text_input(
30 'note',
31 label => 'Your note',
32 style => 'paragraph',
33 min_length => 1,
34 max_length => 1000,
35 ),
36 ],
37 )
38 );
39 },
40 1 ),
41 );
42  
43 # Read the submitted input by name without walking Discord's component tree.
44 $bot->component(
45 1 ▶ feedback_form => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
46 1 my ($interaction) = @_;
47  
48 # Read the submitted field by its declared ID, independently of the component layout.
49 1 my $note = $interaction->field('note');
50  
51 # Echo the note privately and disable mentions in user-supplied text.
52 1 return $interaction->reply(
53 {
54 content => "Thanks for your feedback: $note",
55 allowed_mentions => { parse => [] },
56 },
57 ephemeral => 1
58 );
59 }
60 1 );
61  
62 # Run the bot, or expose its declarations to the deployment script.
63 1 ▶$bot->run unless caller;
Branch: 1 branch
BranchTrueFalseTotal
unless caller 0 1 1
64 1 $bot;
« examples/components.pl ↑ Summary blib/lib/Discord/Client/REST/Error.pm »