Skip to content

Commit 6b15baf

Browse files
authored
Merge pull request #339 from Java-Discord/moon/self-role-remove
Added `/self-role remove`
2 parents 9e2e7be + 6d2b56d commit 6b15baf

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

src/main/java/net/javadiscord/javabot/systems/staff_commands/self_roles/ChangeSelfRoleStatusSubcommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.time.Instant;
1818

1919
/**
20-
* Subcommand that disables all Elements on an ActionRow.
20+
* Subcommand that disables all Elements on all ActionRows.
2121
*/
2222
public class ChangeSelfRoleStatusSubcommand extends SlashCommand.Subcommand {
2323
/**
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package net.javadiscord.javabot.systems.staff_commands.self_roles;
2+
3+
import com.dynxsty.dih4jda.interactions.commands.SlashCommand;
4+
import net.dv8tion.jda.api.EmbedBuilder;
5+
import net.dv8tion.jda.api.entities.Message;
6+
import net.dv8tion.jda.api.entities.MessageEmbed;
7+
import net.dv8tion.jda.api.entities.User;
8+
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
9+
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
10+
import net.dv8tion.jda.api.interactions.commands.OptionType;
11+
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
12+
import net.javadiscord.javabot.systems.notification.GuildNotificationService;
13+
import net.javadiscord.javabot.util.Responses;
14+
import org.jetbrains.annotations.NotNull;
15+
16+
import java.time.Instant;
17+
18+
/**
19+
* Subcommands that removes all Elements on all ActionRows.
20+
*/
21+
public class RemoveSelfRolesSubcommand extends SlashCommand.Subcommand {
22+
23+
public RemoveSelfRolesSubcommand() {
24+
setSubcommandData(new SubcommandData("remove-all", "Removes all Self-Roles from a specified message.")
25+
.addOption(OptionType.STRING, "message-id", "Id of the message.", true));
26+
}
27+
28+
@Override
29+
public void execute(SlashCommandInteractionEvent event) {
30+
OptionMapping idMapping = event.getOption("message-id");
31+
if (idMapping == null) {
32+
Responses.replyMissingArguments(event).queue();
33+
return;
34+
}
35+
event.deferReply(true).queue();
36+
event.getChannel().retrieveMessageById(idMapping.getAsLong()).queue(message -> {
37+
message.editMessageComponents().queue();
38+
MessageEmbed embed = buildSelfRoleDeletedEmbed(event.getUser(), message);
39+
new GuildNotificationService(event.getGuild()).sendLogChannelNotification(embed);
40+
event.getHook().sendMessageEmbeds(embed).setEphemeral(true).queue();
41+
}, e -> Responses.error(event.getHook(), e.getMessage()));
42+
}
43+
44+
private @NotNull MessageEmbed buildSelfRoleDeletedEmbed(@NotNull User changedBy, @NotNull Message message) {
45+
return new EmbedBuilder()
46+
.setAuthor(changedBy.getAsTag(), message.getJumpUrl(), changedBy.getEffectiveAvatarUrl())
47+
.setTitle("Self Roles Removed")
48+
.setColor(Responses.Type.DEFAULT.getColor())
49+
.addField("Channel", message.getChannel().getAsMention(), true)
50+
.addField("Message", String.format("[Jump to Message](%s)", message.getJumpUrl()), true)
51+
.setTimestamp(Instant.now())
52+
.build();
53+
}
54+
}

src/main/java/net/javadiscord/javabot/systems/staff_commands/self_roles/SelfRoleCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public SelfRoleCommand() {
1717
.setDefaultPermissions(DefaultMemberPermissions.DISABLED)
1818
.setGuildOnly(true)
1919
);
20-
addSubcommands(new CreateSelfRoleSubcommand(), new ChangeSelfRoleStatusSubcommand());
20+
addSubcommands(new CreateSelfRoleSubcommand(), new ChangeSelfRoleStatusSubcommand(), new RemoveSelfRolesSubcommand());
2121
}
2222
}
2323

0 commit comments

Comments
 (0)