55import net .dv8tion .jda .api .entities .Message ;
66import net .dv8tion .jda .api .entities .emoji .CustomEmoji ;
77import net .dv8tion .jda .api .entities .emoji .Emoji ;
8+ import net .dv8tion .jda .api .interactions .commands .OptionType ;
9+ import org .mangorage .commonutils .jda .slash .command .Command ;
10+ import org .mangorage .commonutils .jda .slash .command .CommandOption ;
811import org .mangorage .commonutils .misc .Arguments ;
912import org .mangorage .mangobotcore .jda .command .api .CommandResult ;
1013import org .mangorage .mangobotcore .jda .command .api .ICommand ;
11-
12- import java .io .IOException ;
1314import java .util .List ;
14- import java .util .concurrent .ExecutionException ;
1515
1616public final class EmojiCommand implements ICommand {
17+
18+ public static String getInfo (final CustomEmoji emoji ) {
19+ return """
20+ URL: %s
21+ Id: %s
22+ Name: %s
23+ Created: %s
24+ Formatted: %s
25+ Reaction Code: %s
26+ Mention: %s
27+ """
28+ .formatted (
29+ emoji .getImageUrl (),
30+ emoji .getId (),
31+ emoji .getName (),
32+ emoji .getTimeCreated ().toString (),
33+ emoji .getFormatted (),
34+ emoji .getAsReactionCode (),
35+ emoji .getAsMention ()
36+ );
37+ }
38+
39+ public EmojiCommand () {
40+ Command .slash ("emoji" , "Useful emoji Comamnd" )
41+ .addSubCommand ("info" , "Get info about Emoji" )
42+ .addOption (
43+ new CommandOption (OptionType .STRING , "emoji" , "The Emoji" , true )
44+ )
45+ .executes (e -> {
46+ final var valueOption = e .getInteraction ().getOption ("emoji" );
47+ if (valueOption != null ) {
48+ final var emoji = Emoji .fromFormatted (valueOption .getAsString ()).asCustom ();
49+ e .reply (getInfo (emoji )).queue ();
50+ }
51+ })
52+ .build ()
53+ .addSubCommand ("create" , "Create an Emoji" )
54+ .addOptions (
55+ new CommandOption (OptionType .STRING , "name" , "The Name for the emoji you are creating" , true ),
56+ new CommandOption (OptionType .STRING , "emoji" , "The Actual Emoji you are wanting" , true )
57+ )
58+ .executes (e -> {
59+ if (!e .getMember ().hasPermission (Permission .ADMINISTRATOR )) {
60+ e .reply ("Insufficient Permissions!" ).setEphemeral (true ).queue ();
61+ } else {
62+ final var name = e .getInteraction ().getOption ("name" );
63+ final var emoji = e .getInteraction ().getOption ("emoji" );
64+ if (name == null || emoji == null ) {
65+ e .reply ("Incomplete Command" ).setEphemeral (true ).queue ();
66+ } else {
67+ final var ce = Emoji .fromFormatted (emoji .getAsString ()).asCustom ();
68+
69+ try {
70+ e .getGuild ().createEmoji (
71+ name .getAsString (),
72+ Icon .from (ce .getImage ().download ().get ())
73+ ).queue ();
74+
75+ e .reply ("Created Emoji!" ).setEphemeral (true ).queue ();
76+ } catch (Throwable ignored ) {
77+ e .reply ("Failed to create Emoji!" ).setEphemeral (true ).queue ();
78+ }
79+
80+ }
81+ }
82+ })
83+ .build ()
84+ .buildAndRegister ();
85+ }
86+
87+
1788 @ Override
1889 public String id () {
1990 return "emoji" ;
@@ -31,6 +102,9 @@ public String usage() {
31102
32103 !emoji create <name/id> <emoji>
33104 !emoji create <name/id> <emojiName> <emojiId>
105+
106+ !emoji send <emoji>
107+ !emoji send <emojiName> <emojiId>
34108 """ ;
35109 }
36110
@@ -72,6 +146,16 @@ public CommandResult execute(Message message, Arguments arguments) {
72146
73147 return CommandResult .PASS ;
74148 }
149+ } else if (sub_cmd .contains ("info" )) {
150+ if (arguments .getArgs ().length == 3 ) {
151+ var ce = Emoji .fromFormatted ("<:" + arguments .get (1 ) + ":" + arguments .get (2 ) + ">" );
152+ message .reply (getInfo (ce .asCustom ())).queue ();
153+ } else if (arguments .getArgs ().length == 2 ) {
154+ var ce = Emoji .fromFormatted (arguments .get (1 ));
155+ message .reply (getInfo (ce .asCustom ())).queue ();
156+ } else {
157+ message .reply ("Improper Usage" ).queue ();
158+ }
75159 }
76160 return CommandResult .PASS ;
77161 }
0 commit comments