Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c74c58a

Browse files
committedJul 25, 2022
added /tags list & /tags view
1 parent 9adc24c commit c74c58a

File tree

9 files changed

+55
-23
lines changed

9 files changed

+55
-23
lines changed
 

‎src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/CustomTagManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ public CustomTagManager(@NotNull JDA jda, @NotNull DataSource dataSource) {
9292
boolean embed = tag.isEmbed();
9393
if (embed) {
9494
if (reply) {
95-
actions.add(event.replyEmbeds(tag.toEmbed()));
95+
actions.add(event.getHook().sendMessageEmbeds(tag.toEmbed()));
9696
} else {
9797
actions.add(event.getChannel().sendMessageEmbeds(tag.toEmbed()));
9898
}
9999
} else {
100100
if (reply) {
101-
actions.add(event.reply(tag.getResponse()).allowedMentions(List.of()));
101+
actions.add(event.getHook().sendMessage(tag.getResponse()).allowedMentions(List.of()));
102102
} else {
103103
actions.add(event.getChannel().sendMessage(tag.getResponse()).allowedMentions(List.of()));
104104
}

‎src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/CreateCustomTagSubcommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/**
2828
* Administrative Subcommand that allows to create {@link CustomTag}s.
2929
*/
30-
public class CreateCustomTagSubcommand extends CustomTagsSubcommand implements ModalHandler {
30+
public class CreateCustomTagSubcommand extends TagsSubcommand implements ModalHandler {
3131
/**
3232
* The constructor of this class, which sets the corresponding {@link SubcommandData}.
3333
*/

‎src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/DeleteCustomTagSubcommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/**
2626
* <h3>This class represents the /tag-admin delete command.</h3>
2727
*/
28-
public class DeleteCustomTagSubcommand extends CustomTagsSubcommand implements AutoCompletable {
28+
public class DeleteCustomTagSubcommand extends TagsSubcommand implements AutoCompletable {
2929
/**
3030
* The constructor of this class, which sets the corresponding {@link SubcommandData}.
3131
*/

‎src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/EditCustomTagSubcommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
/**
3636
* <h3>This class represents the /tag-admin edit command.</h3>
3737
*/
38-
public class EditCustomTagSubcommand extends CustomTagsSubcommand implements AutoCompletable, ModalHandler {
38+
public class EditCustomTagSubcommand extends TagsSubcommand implements AutoCompletable, ModalHandler {
3939
/**
4040
* The constructor of this class, which sets the corresponding {@link SubcommandData}.
4141
*/
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
44
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
55
import net.dv8tion.jda.api.interactions.commands.build.Commands;
6+
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
7+
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
68
import net.dv8tion.jda.api.utils.MarkdownUtil;
79
import net.javadiscord.javabot.data.h2db.DbHelper;
810
import net.javadiscord.javabot.systems.staff_commands.tags.dao.CustomTagRepository;
@@ -16,24 +18,22 @@
1618
/**
1719
* <h3>This class represents the /tags command.</h3>
1820
*/
19-
public class ListCustomTagsCommand extends SlashCommand {
21+
public class TagListSubcommand extends TagsSubcommand {
2022
/**
2123
* The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
2224
*/
23-
public ListCustomTagsCommand() {
24-
setSlashCommandData(Commands.slash("tags", "Lists all custom tags")
25-
.setGuildOnly(true)
26-
);
25+
public TagListSubcommand() {
26+
setSubcommandData(new SubcommandData("list", "Lists all custom tags"));
2727
}
2828

2929
@Override
30-
public void execute(@NotNull SlashCommandInteractionEvent event) {
31-
event.deferReply(false).queue();
30+
public ReplyCallbackAction handleCustomTagsSubcommand(@NotNull SlashCommandInteractionEvent event) {
3231
DbHelper.doDaoAction(CustomTagRepository::new, dao -> {
3332
List<CustomTag> tags = dao.getCustomTagsByGuildId(event.getGuild().getIdLong());
3433
String tagList = tags.stream().map(CustomTag::getName).map(MarkdownUtil::monospace).collect(Collectors.joining(", "));
3534
Responses.info(event.getHook(), "Custom Tag List",
3635
String.format(tagList.length() > 0 ? tagList : "No Custom Tags created yet.")).queue();
3736
});
37+
return event.deferReply(false);
3838
}
3939
}

‎src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/TagCommand.java renamed to ‎src/main/java/net/javadiscord/javabot/systems/staff_commands/tags/commands/TagViewSubcommand.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
99
import net.dv8tion.jda.api.interactions.commands.OptionType;
1010
import net.dv8tion.jda.api.interactions.commands.build.Commands;
11+
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
12+
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction;
1113
import net.javadiscord.javabot.Bot;
1214
import net.javadiscord.javabot.systems.staff_commands.tags.CustomTagManager;
1315
import net.javadiscord.javabot.systems.staff_commands.tags.model.CustomTag;
@@ -19,29 +21,29 @@
1921
/**
2022
* <h3>This class represents the /tag command.</h3>
2123
*/
22-
public class TagCommand extends SlashCommand implements AutoCompletable {
24+
public class TagViewSubcommand extends TagsSubcommand implements AutoCompletable {
2325
/**
2426
* The constructor of this class, which sets the corresponding {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData}.
2527
*/
26-
public TagCommand() {
27-
setSlashCommandData(Commands.slash("tag-view", "Allows to view a tag.")
28+
public TagViewSubcommand() {
29+
setSubcommandData(new SubcommandData("view", "Allows to view a tag.")
2830
.addOption(OptionType.STRING, "name", "The tag's name.", true, true)
2931
);
3032
}
3133

3234
@Override
33-
public void execute(@NotNull SlashCommandInteractionEvent event) {
35+
public ReplyCallbackAction handleCustomTagsSubcommand(@NotNull SlashCommandInteractionEvent event) {
3436
OptionMapping nameMapping = event.getOption("name");
3537
if (nameMapping == null) {
36-
Responses.replyMissingArguments(event);
37-
return;
38+
return Responses.replyMissingArguments(event);
3839
}
3940
Optional<CustomTag> tagOptional = Bot.customTagManager.getByName(event.getGuild().getIdLong(), nameMapping.getAsString());
4041
if (tagOptional.isPresent()) {
4142
CustomTagManager.handleCustomTag(event, tagOptional.get()).queue();
4243
} else {
43-
Responses.error(event.getHook(), "Could not find Custom Tag with name `%s`.", nameMapping.getAsString()).queue();
44+
Responses.error(event.getHook(), "Could not find Custom Tag with name `%s`.", nameMapping.getAsString());
4445
}
46+
return event.deferReply(false);
4547
}
4648

4749
@Override
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
/**
88
* Represents the `/tag-admin` command. This holds administrative commands for managing "Custom Tags".
99
*/
10-
public class CustomTagsAdminCommand extends SlashCommand implements CommandModerationPermissions {
10+
public class TagsAdminCommand extends SlashCommand implements CommandModerationPermissions {
1111
/**
1212
* This classes constructor which sets the {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData} and
1313
* adds the corresponding {@link net.dv8tion.jda.api.interactions.commands.Command.Subcommand}s.
1414
*/
15-
public CustomTagsAdminCommand() {
15+
public TagsAdminCommand() {
1616
setModerationSlashCommandData(Commands.slash("tag-admin", "Administrative commands for managing \"Custom Tags\"."));
1717
addSubcommands(new CreateCustomTagSubcommand(), new DeleteCustomTagSubcommand(), new EditCustomTagSubcommand());
1818
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package net.javadiscord.javabot.systems.staff_commands.tags.commands;
2+
3+
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
4+
import net.dv8tion.jda.api.interactions.commands.build.Commands;
5+
import net.javadiscord.javabot.systems.moderation.CommandModerationPermissions;
6+
7+
/**
8+
* Represents the `/tag` command. This holds commands for interacting with "Custom Tags".
9+
*/
10+
public class TagsCommand extends SlashCommand implements CommandModerationPermissions {
11+
/**
12+
* This classes constructor which sets the {@link net.dv8tion.jda.api.interactions.commands.build.SlashCommandData} and
13+
* adds the corresponding {@link net.dv8tion.jda.api.interactions.commands.Command.Subcommand}s.
14+
*/
15+
public TagsCommand() {
16+
setModerationSlashCommandData(Commands.slash("tags", "Commands for interacting with Custom Tags."));
17+
addSubcommands(new TagViewSubcommand(), new TagListSubcommand());
18+
}
19+
}
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import lombok.extern.slf4j.Slf4j;
55
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
66
import net.dv8tion.jda.api.requests.restaction.interactions.InteractionCallbackAction;
7+
import net.javadiscord.javabot.util.Checks;
78
import net.javadiscord.javabot.util.ExceptionLogger;
89
import net.javadiscord.javabot.util.Responses;
910
import org.jetbrains.annotations.NotNull;
@@ -15,13 +16,19 @@
1516
* custom-tag-related commands.
1617
*/
1718
@Slf4j
18-
public abstract class CustomTagsSubcommand extends SlashCommand.Subcommand {
19+
public abstract class TagsSubcommand extends SlashCommand.Subcommand {
20+
private boolean requireStaff = true;
21+
1922
@Override
2023
public void execute(@NotNull SlashCommandInteractionEvent event) {
21-
if (event.getGuild() == null) {
24+
if (event.getGuild() == null || event.getMember() == null) {
2225
Responses.replyGuildOnly(event).queue();
2326
return;
2427
}
28+
if (requireStaff && !Checks.hasStaffRole(event.getGuild(), event.getMember())) {
29+
Responses.replyStaffOnly(event, event.getGuild()).queue();
30+
return;
31+
}
2532
try {
2633
handleCustomTagsSubcommand(event).queue();
2734
} catch (SQLException e) {
@@ -30,5 +37,9 @@ public void execute(@NotNull SlashCommandInteractionEvent event) {
3037
}
3138
}
3239

40+
protected void setRequiredStaff(boolean requireStaff) {
41+
this.requireStaff = requireStaff;
42+
}
43+
3344
protected abstract InteractionCallbackAction<?> handleCustomTagsSubcommand(@NotNull SlashCommandInteractionEvent event) throws SQLException;
3445
}

0 commit comments

Comments
 (0)
Please sign in to comment.