Skip to content

Commit 5bc27d6

Browse files
committed
Added more command stuff to EmojiCommand
1 parent 55e2e2a commit 5bc27d6

File tree

3 files changed

+94
-4
lines changed

3 files changed

+94
-4
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ dependencies {
7272
testImplementation 'org.junit.jupiter:junit-jupiter'
7373

7474
installer('org.mangorage:installer:4.0.3')
75-
bot('org.mangorage:mangobot:12.0.+')
75+
bot('org.mangorage:mangobot:12.0.28')
7676

7777
library('org.luaj:luaj-jse:3.0.1')
7878

src/main/java/org/mangorage/mangobotplugin/commands/internal/EmojiCommand.java

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,86 @@
55
import net.dv8tion.jda.api.entities.Message;
66
import net.dv8tion.jda.api.entities.emoji.CustomEmoji;
77
import 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;
811
import org.mangorage.commonutils.misc.Arguments;
912
import org.mangorage.mangobotcore.jda.command.api.CommandResult;
1013
import org.mangorage.mangobotcore.jda.command.api.ICommand;
11-
12-
import java.io.IOException;
1314
import java.util.List;
14-
import java.util.concurrent.ExecutionException;
1515

1616
public 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
}

src/main/java/org/mangorage/mangobotplugin/entrypoint/MangoBot.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.mangorage.commonutils.config.ISetting;
1414
import org.mangorage.commonutils.jda.ButtonActionRegistry;
1515
import org.mangorage.commonutils.jda.MessageSettings;
16+
import org.mangorage.commonutils.jda.slash.command.Command;
1617
import org.mangorage.mangobotcore.jda.command.api.CommandManager;
1718
import org.mangorage.mangobotcore.plugin.api.MangoBotPlugin;
1819
import org.mangorage.mangobotcore.plugin.api.Plugin;
@@ -119,6 +120,11 @@ public void load() {
119120

120121
getJDA().addEventListener(new BotEventListener(this));
121122

123+
jda.updateCommands()
124+
.addCommands(
125+
Command.globalCommands
126+
).queue();
127+
122128
System.out.println("Launched");
123129
}
124130

0 commit comments

Comments
 (0)