Skip to content

Commit 3a835c3

Browse files
committed
Fixed issues after rebase
1 parent 9b0045a commit 3a835c3

File tree

5 files changed

+55
-52
lines changed

5 files changed

+55
-52
lines changed

application/src/main/java/org/togetherjava/tjbot/commands/SlashCommand.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package org.togetherjava.tjbot.commands;
22

33
import net.dv8tion.jda.api.entities.Emoji;
4-
import net.dv8tion.jda.api.events.interaction.ButtonClickEvent;
5-
import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent;
6-
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
4+
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
5+
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
6+
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
77
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
8-
import net.dv8tion.jda.api.interactions.components.ButtonStyle;
8+
import net.dv8tion.jda.api.interactions.commands.build.Commands;
9+
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
910
import net.dv8tion.jda.api.interactions.components.ComponentInteraction;
11+
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
1012
import org.jetbrains.annotations.NotNull;
1113
import org.togetherjava.tjbot.commands.componentids.ComponentId;
1214
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
@@ -28,9 +30,9 @@
2830
* is then to be returned by {@link #getData()} where the system will then pick it up from.
2931
* <p>
3032
* After registration, the system will notify a command whenever one of its corresponding slash
31-
* commands ({@link #onSlashCommand(SlashCommandEvent)}), buttons
32-
* ({@link #onButtonClick(ButtonClickEvent, List)}) or menus
33-
* ({@link #onSelectionMenu(SelectionMenuEvent, List)}) have been triggered.
33+
* commands ({@link #onSlashCommand(SlashCommandInteractionEvent)}), buttons
34+
* ({@link #onButtonClick(ButtonInteractionEvent, List)}) or menus
35+
* ({@link #onSelectionMenu(SelectMenuInteractionEvent, List)}) have been triggered.
3436
* <p>
3537
* <p>
3638
* Some example commands are available in {@link org.togetherjava.tjbot.commands.basic}.
@@ -40,7 +42,7 @@ public interface SlashCommand extends UserInteractor {
4042
/**
4143
* Gets the description of the command.
4244
* <p>
43-
* Requirements for this are documented in {@link CommandData#CommandData(String, String)}.
45+
* Requirements for this are documented in {@link Commands#slash(String, String)}.
4446
* <p>
4547
* <p>
4648
* After registration of the command, the description must not change anymore.
@@ -76,7 +78,7 @@ public interface SlashCommand extends UserInteractor {
7678
* @return the command data of this command
7779
*/
7880
@NotNull
79-
CommandData getData();
81+
SlashCommandData getData();
8082

8183
/**
8284
* Triggered by the core system when a slash command corresponding to this implementation (based
@@ -91,8 +93,8 @@ public interface SlashCommand extends UserInteractor {
9193
* <p>
9294
* Buttons or menus have to be created with a component ID (see
9395
* {@link ComponentInteraction#getComponentId()},
94-
* {@link net.dv8tion.jda.api.interactions.components.Button#of(ButtonStyle, String, Emoji)}) in
95-
* a very specific format, otherwise the core system will fail to identify the command that
96+
* {@link net.dv8tion.jda.api.interactions.components.buttons.Button#of(ButtonStyle, String, Emoji)})
97+
* in a very specific format, otherwise the core system will fail to identify the command that
9698
* corresponded to the button or menu click event and is unable to route it back.
9799
* <p>
98100
* The component ID has to be a UUID-string (see {@link java.util.UUID}), which is associated to
@@ -102,8 +104,8 @@ public interface SlashCommand extends UserInteractor {
102104
* given to {@link #acceptComponentIdGenerator(ComponentIdGenerator)} during system setup. The
103105
* required {@link ComponentId} instance accepts optional extra arguments, which, if provided,
104106
* can be picked up during the corresponding event (see
105-
* {@link #onButtonClick(ButtonClickEvent, List)},
106-
* {@link #onSelectionMenu(SelectionMenuEvent, List)}).
107+
* {@link #onButtonClick(ButtonInteractionEvent, List)},
108+
* {@link #onSelectionMenu(SelectMenuInteractionEvent, List)}).
107109
* <p>
108110
* Alternatively, if {@link SlashCommandAdapter} has been extended, it also offers a handy
109111
* {@link SlashCommandAdapter#generateComponentId(String...)} method to ease the flow.
@@ -116,5 +118,5 @@ public interface SlashCommand extends UserInteractor {
116118
*
117119
* @param event the event that triggered this
118120
*/
119-
void onSlashCommand(@NotNull SlashCommandEvent event);
121+
void onSlashCommand(@NotNull SlashCommandInteractionEvent event);
120122
}

application/src/main/java/org/togetherjava/tjbot/commands/UserInteractor.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.togetherjava.tjbot.commands;
22

3-
import net.dv8tion.jda.api.events.interaction.ButtonClickEvent;
4-
import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent;
5-
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
6-
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
3+
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
4+
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
5+
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
76
import org.jetbrains.annotations.NotNull;
87
import org.togetherjava.tjbot.commands.componentids.ComponentIdGenerator;
98

@@ -20,7 +19,8 @@ public interface UserInteractor extends Feature {
2019
/**
2120
* Gets the name of the interactor.
2221
* <p>
23-
* Requirements for this are documented in {@link CommandData#CommandData(String, String)}.
22+
* Requirements for this are documented in
23+
* {@link net.dv8tion.jda.api.interactions.commands.build.Commands#slash(String, String)}.
2424
* <p>
2525
* <p>
2626
* After registration of the interactor, the name must not change anymore.
@@ -46,10 +46,10 @@ public interface UserInteractor extends Feature {
4646
*
4747
* @param event the event that triggered this
4848
* @param args the arguments transported with the button, see
49-
* {@link SlashCommand#onSlashCommand(SlashCommandEvent)} for details on how these are
50-
* created
49+
* {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)} for details on how
50+
* these are created
5151
*/
52-
void onButtonClick(@NotNull ButtonClickEvent event, @NotNull List<String> args);
52+
void onButtonClick(@NotNull ButtonInteractionEvent event, @NotNull List<String> args);
5353

5454
/**
5555
* Triggered by the core system when a selection menu corresponding to this implementation
@@ -67,16 +67,17 @@ public interface UserInteractor extends Feature {
6767
*
6868
* @param event the event that triggered this
6969
* @param args the arguments transported with the selection menu, see
70-
* {@link SlashCommand#onSlashCommand(SlashCommandEvent)} for details on how these are
71-
* created
70+
* {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)} for details on how
71+
* these are created
7272
*/
73-
void onSelectionMenu(@NotNull SelectionMenuEvent event, @NotNull List<String> args);
73+
void onSelectionMenu(@NotNull SelectMenuInteractionEvent event, @NotNull List<String> args);
7474

7575
/**
7676
* Triggered by the core system during its setup phase. It will provide the interactor a
7777
* component id generator through this method, which can be used to generate component ids, as
7878
* used for button or selection menus. See
79-
* {@link SlashCommand#onSlashCommand(SlashCommandEvent)} for details on how to use this.
79+
* {@link SlashCommand#onSlashCommand(SlashCommandInteractionEvent)} for details on how to use
80+
* this.
8081
*
8182
* @param generator the provided component id generator
8283
*/

application/src/main/java/org/togetherjava/tjbot/commands/mathcommands/TeXCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
44
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
55
import net.dv8tion.jda.api.interactions.commands.OptionType;
6-
import net.dv8tion.jda.api.interactions.components.Button;
6+
import net.dv8tion.jda.api.interactions.components.buttons.Button;
77
import org.jetbrains.annotations.NotNull;
88
import org.scilab.forge.jlatexmath.ParseException;
99
import org.scilab.forge.jlatexmath.TeXConstants;

application/src/main/java/org/togetherjava/tjbot/commands/moderation/scam/ScamBlocker.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import net.dv8tion.jda.api.JDA;
55
import net.dv8tion.jda.api.MessageBuilder;
66
import net.dv8tion.jda.api.entities.*;
7-
import net.dv8tion.jda.api.events.interaction.ButtonClickEvent;
8-
import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent;
9-
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
7+
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
8+
import net.dv8tion.jda.api.events.interaction.component.SelectMenuInteractionEvent;
9+
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
1010
import net.dv8tion.jda.api.exceptions.ErrorHandler;
1111
import net.dv8tion.jda.api.interactions.components.ActionRow;
12-
import net.dv8tion.jda.api.interactions.components.Button;
13-
import net.dv8tion.jda.api.interactions.components.ButtonStyle;
12+
import net.dv8tion.jda.api.interactions.components.buttons.Button;
13+
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
1414
import net.dv8tion.jda.api.requests.ErrorResponse;
1515
import org.jetbrains.annotations.NotNull;
1616
import org.jetbrains.annotations.Nullable;
@@ -89,7 +89,8 @@ public ScamBlocker(@NotNull ModerationActionsStore actionsStore,
8989
}
9090

9191
@Override
92-
public void onSelectionMenu(@NotNull SelectionMenuEvent event, @NotNull List<String> args) {
92+
public void onSelectionMenu(@NotNull SelectMenuInteractionEvent event,
93+
@NotNull List<String> args) {
9394
throw new UnsupportedOperationException("Not used");
9495
}
9596

@@ -99,7 +100,7 @@ public void acceptComponentIdGenerator(@NotNull ComponentIdGenerator generator)
99100
}
100101

101102
@Override
102-
public void onMessageReceived(@NotNull GuildMessageReceivedEvent event) {
103+
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
103104
if (event.getAuthor().isBot() || event.isWebhookMessage()) {
104105
return;
105106
}
@@ -122,7 +123,7 @@ public void onMessageReceived(@NotNull GuildMessageReceivedEvent event) {
122123
takeAction(event);
123124
}
124125

125-
private void takeActionWasAlreadyReported(@NotNull GuildMessageReceivedEvent event) {
126+
private void takeActionWasAlreadyReported(@NotNull MessageReceivedEvent event) {
126127
// The user recently send the same scam already, and that was already reported and handled
127128
addScamToHistory(event);
128129

@@ -132,7 +133,7 @@ private void takeActionWasAlreadyReported(@NotNull GuildMessageReceivedEvent eve
132133
}
133134
}
134135

135-
private void takeAction(@NotNull GuildMessageReceivedEvent event) {
136+
private void takeAction(@NotNull MessageReceivedEvent event) {
136137
switch (mode) {
137138
case OFF -> throw new AssertionError(
138139
"The OFF-mode should be detected earlier already to prevent expensive computation");
@@ -145,26 +146,25 @@ private void takeAction(@NotNull GuildMessageReceivedEvent event) {
145146
}
146147
}
147148

148-
private void takeActionLogOnly(@NotNull GuildMessageReceivedEvent event) {
149+
private void takeActionLogOnly(@NotNull MessageReceivedEvent event) {
149150
addScamToHistory(event);
150151
logScamMessage(event);
151152
}
152153

153-
private void takeActionApproveFirst(@NotNull GuildMessageReceivedEvent event) {
154+
private void takeActionApproveFirst(@NotNull MessageReceivedEvent event) {
154155
addScamToHistory(event);
155156
logScamMessage(event);
156157
reportScamMessage(event, "Is this scam?", createConfirmDialog(event));
157158
}
158159

159-
private void takeActionAutoDeleteButApproveQuarantine(
160-
@NotNull GuildMessageReceivedEvent event) {
160+
private void takeActionAutoDeleteButApproveQuarantine(@NotNull MessageReceivedEvent event) {
161161
addScamToHistory(event);
162162
logScamMessage(event);
163163
deleteMessage(event);
164164
reportScamMessage(event, "Is this scam? (already deleted)", createConfirmDialog(event));
165165
}
166166

167-
private void takeActionAutoDeleteAndQuarantine(@NotNull GuildMessageReceivedEvent event) {
167+
private void takeActionAutoDeleteAndQuarantine(@NotNull MessageReceivedEvent event) {
168168
addScamToHistory(event);
169169
logScamMessage(event);
170170
deleteMessage(event);
@@ -173,21 +173,21 @@ private void takeActionAutoDeleteAndQuarantine(@NotNull GuildMessageReceivedEven
173173
reportScamMessage(event, "Detected and handled scam", null);
174174
}
175175

176-
private void addScamToHistory(@NotNull GuildMessageReceivedEvent event) {
176+
private void addScamToHistory(@NotNull MessageReceivedEvent event) {
177177
scamHistoryStore.addScam(event.getMessage(), MODES_WITH_IMMEDIATE_DELETION.contains(mode));
178178
}
179179

180-
private void logScamMessage(@NotNull GuildMessageReceivedEvent event) {
180+
private void logScamMessage(@NotNull MessageReceivedEvent event) {
181181
logger.warn("Detected a scam message ('{}') from user '{}' in channel '{}' of guild '{}'.",
182182
event.getMessageId(), event.getAuthor().getId(), event.getChannel().getId(),
183183
event.getGuild().getId());
184184
}
185185

186-
private void deleteMessage(@NotNull GuildMessageReceivedEvent event) {
186+
private void deleteMessage(@NotNull MessageReceivedEvent event) {
187187
event.getMessage().delete().queue();
188188
}
189189

190-
private void quarantineAuthor(@NotNull GuildMessageReceivedEvent event) {
190+
private void quarantineAuthor(@NotNull MessageReceivedEvent event) {
191191
quarantineAuthor(event.getGuild(), event.getMember(), event.getJDA().getSelfUser());
192192
}
193193

@@ -205,8 +205,8 @@ private void quarantineAuthor(@NotNull Guild guild, @NotNull Member author,
205205
.queue();
206206
}
207207

208-
private void reportScamMessage(@NotNull GuildMessageReceivedEvent event,
209-
@NotNull String reportTitle, @Nullable ActionRow confirmDialog) {
208+
private void reportScamMessage(@NotNull MessageReceivedEvent event, @NotNull String reportTitle,
209+
@Nullable ActionRow confirmDialog) {
210210
Guild guild = event.getGuild();
211211
Optional<TextChannel> reportChannel = getReportChannel(guild);
212212
if (reportChannel.isEmpty()) {
@@ -231,7 +231,7 @@ private void reportScamMessage(@NotNull GuildMessageReceivedEvent event,
231231
reportChannel.orElseThrow().sendMessage(message).queue();
232232
}
233233

234-
private void dmUser(@NotNull GuildMessageReceivedEvent event) {
234+
private void dmUser(@NotNull MessageReceivedEvent event) {
235235
dmUser(event.getGuild(), event.getAuthor().getIdLong(), event.getJDA());
236236
}
237237

@@ -255,7 +255,7 @@ If you think this was a mistake (for example, your account was hacked, but you g
255255
return guild.getTextChannelCache().stream().filter(isReportChannel).findAny();
256256
}
257257

258-
private @NotNull ActionRow createConfirmDialog(@NotNull GuildMessageReceivedEvent event) {
258+
private @NotNull ActionRow createConfirmDialog(@NotNull MessageReceivedEvent event) {
259259
ComponentIdArguments args = new ComponentIdArguments(mode, event.getGuild().getIdLong(),
260260
event.getChannel().getIdLong(), event.getMessageIdLong(),
261261
event.getAuthor().getIdLong(),
@@ -271,7 +271,8 @@ If you think this was a mistake (for example, your account was hacked, but you g
271271
}
272272

273273
@Override
274-
public void onButtonClick(@NotNull ButtonClickEvent event, @NotNull List<String> argsRaw) {
274+
public void onButtonClick(@NotNull ButtonInteractionEvent event,
275+
@NotNull List<String> argsRaw) {
275276
ComponentIdArguments args = ComponentIdArguments.fromList(argsRaw);
276277
if (event.getMember().getRoles().stream().map(Role::getName).noneMatch(hasRequiredRole)) {
277278
event.reply(

application/src/main/java/org/togetherjava/tjbot/commands/system/ReloadCommand.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public void onSlashCommand(@NotNull SlashCommandInteractionEvent event) {
6969

7070
event.reply(
7171
"Are you sure? You can only reload commands a few times each day, so do not overdo this.")
72-
.addActionRow(
73-
Button.success(generateComponentId(member.getId()), "Yes"),
72+
.addActionRow(Button.success(generateComponentId(member.getId()), "Yes"),
7473
Button.danger(generateComponentId(member.getId()), "No"))
7574
.queue();
7675
}

0 commit comments

Comments
 (0)