Skip to content

Commit 935316b

Browse files
committed
Update JDA to alpha 4
1 parent ac1eb59 commit 935316b

File tree

9 files changed

+70
-60
lines changed

9 files changed

+70
-60
lines changed

application/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ shadowJar {
4545
dependencies {
4646
implementation project(':database')
4747

48-
implementation 'net.dv8tion:JDA:4.4.0_352'
48+
implementation 'net.dv8tion:JDA:5.0.0-alpha.4'
4949

5050
implementation 'org.apache.logging.log4j:log4j-core:2.16.0'
5151
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j18-impl:2.16.0'
@@ -71,4 +71,4 @@ dependencies {
7171

7272
application {
7373
mainClass = 'org.togetherjava.tjbot.BootstrapLauncher'
74-
}
74+
}

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

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

3-
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
4-
import net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent;
3+
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
4+
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
55
import org.jetbrains.annotations.NotNull;
66

77
import java.util.regex.Pattern;
@@ -38,7 +38,7 @@ public interface MessageReceiver extends Feature {
3838
* @param event the event that triggered this, containing information about the corresponding
3939
* message that was sent and received
4040
*/
41-
void onMessageReceived(@NotNull GuildMessageReceivedEvent event);
41+
void onMessageReceived(@NotNull MessageReceivedEvent event);
4242

4343
/**
4444
* Triggered by the core system whenever an existing message was edited in a text channel of a
@@ -47,5 +47,5 @@ public interface MessageReceiver extends Feature {
4747
* @param event the event that triggered this, containing information about the corresponding
4848
* message that was edited
4949
*/
50-
void onMessageUpdated(@NotNull GuildMessageUpdateEvent event);
51-
}
50+
void onMessageUpdated(@NotNull MessageUpdateEvent event);
51+
}

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

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

3-
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
4-
import net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent;
3+
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
4+
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
55
import org.jetbrains.annotations.NotNull;
66

77
import java.util.regex.Pattern;
@@ -10,8 +10,8 @@
1010
* Adapter implementation of a {@link MessageReceiver}. A new receiver can then be registered by
1111
* adding it to {@link Features}.
1212
* <p>
13-
* {@link #onMessageReceived(GuildMessageReceivedEvent)} and
14-
* {@link #onMessageUpdated(GuildMessageUpdateEvent)} can be overridden if desired. The default
13+
* {@link #onMessageReceived(MessageReceivedEvent)} and
14+
* {@link #onMessageUpdated(MessageUpdateEvent)} can be overridden if desired. The default
1515
* implementation is empty, the adapter will not react to such events.
1616
*/
1717
public abstract class MessageReceiverAdapter implements MessageReceiver {
@@ -35,13 +35,13 @@ protected MessageReceiverAdapter(@NotNull Pattern channelNamePattern) {
3535

3636
@SuppressWarnings("NoopMethodInAbstractClass")
3737
@Override
38-
public void onMessageReceived(@NotNull GuildMessageReceivedEvent event) {
38+
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
3939
// Adapter does not react by default, subclasses may change this behavior
4040
}
4141

4242
@SuppressWarnings("NoopMethodInAbstractClass")
4343
@Override
44-
public void onMessageUpdated(@NotNull GuildMessageUpdateEvent event) {
44+
public void onMessageUpdated(@NotNull MessageUpdateEvent event) {
4545
// Adapter does not react by default, subclasses may change this behavior
4646
}
47-
}
47+
}

application/src/main/java/org/togetherjava/tjbot/commands/basic/VcActivityCommand.java

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

33
import net.dv8tion.jda.api.Permission;
4-
import net.dv8tion.jda.api.entities.GuildVoiceState;
5-
import net.dv8tion.jda.api.entities.Invite;
6-
import net.dv8tion.jda.api.entities.Member;
7-
import net.dv8tion.jda.api.entities.VoiceChannel;
4+
import net.dv8tion.jda.api.entities.*;
85
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
96
import net.dv8tion.jda.api.interactions.commands.Command;
107
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
@@ -129,15 +126,22 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) {
129126
GuildVoiceState voiceState = Objects.requireNonNull(member.getVoiceState(),
130127
"Voicestates aren't being cached, check the JDABuilder");
131128

132-
if (!voiceState.inVoiceChannel()) {
129+
if (!voiceState.inAudioChannel()) {
133130
event.reply("You need to be in a voicechannel to run this command!")
134131
.setEphemeral(true)
135132
.queue();
136133

137134
return;
138135
}
139136

140-
VoiceChannel voiceChannel = Objects.requireNonNull(voiceState.getChannel());
137+
AudioChannel audioChannel = Objects.requireNonNull(voiceState.getChannel());
138+
139+
if (!(audioChannel instanceof VoiceChannel voiceChannel)) {
140+
event.reply("You've to be in a voicechannel, not a stage channel!")
141+
.setEphemeral(true)
142+
.queue();
143+
return;
144+
}
141145

142146
Member selfMember = Objects.requireNonNull(event.getGuild()).getSelfMember();
143147
if (!selfMember.hasPermission(Permission.CREATE_INSTANT_INVITE)) {
@@ -217,7 +221,7 @@ private static void handleErrors(@NotNull SlashCommandEvent event,
217221

218222
/**
219223
* Interprets the given option as integer. Throws if the option is not an integer.
220-
*
224+
*
221225
* @param option the option that contains the integer to extract, or null if not present
222226
* @return the extracted integer if present, null otherwise
223227
**/
@@ -227,4 +231,4 @@ private static void handleErrors(@NotNull SlashCommandEvent event,
227231
return option == null ? null : Math.toIntExact(option.getAsLong());
228232

229233
}
230-
}
234+
}

application/src/main/java/org/togetherjava/tjbot/commands/free/ChannelMonitor.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void addChannelForStatus(@NotNull final TextChannel channel) {
6464
* This method tests whether a guild id is configured for monitoring in the free command system.
6565
* To add a guild for monitoring see {@link org.togetherjava.tjbot.config.FreeCommandConfig} or
6666
* {@link #addChannelForStatus(TextChannel)}.
67-
*
67+
*
6868
* @param guildId the id of the guild to test.
6969
* @return whether the guild is configured in the free command system or not.
7070
*/
@@ -77,7 +77,7 @@ public boolean isMonitoringGuild(final long guildId) {
7777
* system. To add a channel for monitoring see
7878
* {@link org.togetherjava.tjbot.config.FreeCommandConfig} or
7979
* {@link #addChannelToMonitor(long)}.
80-
*
80+
*
8181
* @param channelId the id of the channel to test.
8282
* @return {@code true} if the channel is configured in the system, {@code false} otherwise.
8383
*/
@@ -136,7 +136,7 @@ public boolean isChannelInactive(@NotNull final TextChannel channel) {
136136
/**
137137
* This method sets the channel's status to 'busy' see {@link ChannelStatus#setBusy(long)} for
138138
* details.
139-
*
139+
*
140140
* @param channelId the id for the channel status to modify.
141141
* @param userId the id of the user changing the status to busy.
142142
* @throws IllegalArgumentException if the channel passed is not monitored. See
@@ -149,7 +149,7 @@ public void setChannelBusy(final long channelId, final long userId) {
149149
/**
150150
* This method sets the channel's status to 'free', see {@link ChannelStatus#setFree()} for
151151
* details.
152-
*
152+
*
153153
* @param channelId the id for the channel status to modify.
154154
* @throws IllegalArgumentException if the channel passed is not monitored. See
155155
* {@link #addChannelToMonitor(long)}
@@ -171,7 +171,7 @@ public void setChannelFree(final long channelId) {
171171
/**
172172
* This method provides a stream of the id's for channels where statuses are displayed. This is
173173
* streamed purely as a simple method of encapsulation.
174-
*
174+
*
175175
* @return a stream of channel id's
176176
*/
177177
public @NotNull Stream<Long> statusIds() {
@@ -194,7 +194,7 @@ public void setChannelFree(final long channelId) {
194194
* It first updates the channel names, order and grouping(categories) according to
195195
* {@link net.dv8tion.jda.api.JDA} for the monitored channels. So that the output is always
196196
* consistent with remote changes.
197-
*
197+
*
198198
* @param guild the guild the message is intended for.
199199
* @return a string representing the busy/free status of channels in this guild. The String
200200
* includes emojis and other discord specific markup. Attempting to display this
@@ -215,7 +215,7 @@ public String statusMessage(@NotNull final Guild guild) {
215215
// pointless ... added to remove warnings
216216
continue;
217217
}
218-
Category category = channel.getParent();
218+
Category category = channel.getParentCategory();
219219
if (category != null && !category.getName().equals(categoryName)) {
220220
categoryName = category.getName();
221221
// append the category name on a new line with markup for underlining
@@ -239,7 +239,7 @@ public String statusMessage(@NotNull final Guild guild) {
239239
* This method is run automatically during startup and should be run on a set schedule, as
240240
* defined in {@link org.togetherjava.tjbot.config.FreeCommandConfig}. The scheduled execution
241241
* is not currently implemented
242-
*
242+
*
243243
* @param guild the guild for which to test the channel statuses of.
244244
*/
245245
public void updateStatusFor(@NotNull Guild guild) {
@@ -284,7 +284,7 @@ public void updateStatusFor(@NotNull Guild guild) {
284284
/**
285285
* The toString method for this class, it generates a human-readable text string of the
286286
* currently monitored channels and the channels the status are printed in.
287-
*
287+
*
288288
* @return the human-readable text string that describes this class.
289289
*/
290290
@Override
@@ -293,4 +293,4 @@ public String toString() {
293293
return "Monitoring Channels: %s%nDisplaying on Channels: %s"
294294
.formatted(channelsToMonitorById, guildIdToStatusChannel);
295295
}
296-
}
296+
}

application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import net.dv8tion.jda.api.events.GenericEvent;
1010
import net.dv8tion.jda.api.events.ReadyEvent;
1111
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
12-
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
12+
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
1313
import net.dv8tion.jda.api.requests.RestAction;
1414
import org.jetbrains.annotations.NotNull;
1515
import org.slf4j.Logger;
@@ -119,7 +119,7 @@ public void onReady(@NotNull final ReadyEvent event) {
119119
* <p>
120120
* If this is called on from a channel that was not configured for monitoring (see
121121
* {@link FreeCommandConfig}) the user will receive an ephemeral message stating such.
122-
*
122+
*
123123
* @param event the event that triggered this
124124
* @throws IllegalStateException if this method is called for a Global Slash Command
125125
*/
@@ -289,26 +289,30 @@ private void checkBusyStatusAllChannels(@NotNull JDA jda) {
289289
public void onEvent(@NotNull GenericEvent event) {
290290
if (event instanceof ReadyEvent readyEvent) {
291291
onReady(readyEvent);
292-
} else if (event instanceof GuildMessageReceivedEvent guildEvent) {
293-
if (guildEvent.isWebhookMessage() || guildEvent.getAuthor().isBot()) {
292+
} else if (event instanceof MessageReceivedEvent messageEvent) {
293+
if (!messageEvent.isFromGuild()) {
294+
return;
295+
}
296+
297+
if (messageEvent.isWebhookMessage() || messageEvent.getAuthor().isBot()) {
294298
return;
295299
}
296-
if (!channelMonitor.isMonitoringChannel(guildEvent.getChannel().getIdLong())) {
300+
if (!channelMonitor.isMonitoringChannel(messageEvent.getChannel().getIdLong())) {
297301
logger.debug(
298302
"Channel is not being monitored, ignoring message received in {} from {}",
299-
guildEvent.getChannel().getName(), guildEvent.getAuthor());
303+
messageEvent.getChannel().getName(), messageEvent.getAuthor());
300304
return;
301305
}
302-
if (channelMonitor.isChannelBusy(guildEvent.getChannel().getIdLong())) {
306+
if (channelMonitor.isChannelBusy(messageEvent.getChannel().getIdLong())) {
303307
logger.debug(
304308
"Channel status is currently busy, ignoring message received in {} from {}",
305-
guildEvent.getChannel().getName(), guildEvent.getAuthor());
309+
messageEvent.getChannel().getName(), messageEvent.getAuthor());
306310
return;
307311
}
308-
channelMonitor.setChannelBusy(guildEvent.getChannel().getIdLong(),
309-
guildEvent.getAuthor().getIdLong());
310-
displayStatus(channelMonitor.getStatusChannelFor(guildEvent.getGuild()));
311-
guildEvent.getMessage().reply(UserStrings.NEW_QUESTION.message()).queue();
312+
channelMonitor.setChannelBusy(messageEvent.getChannel().getIdLong(),
313+
messageEvent.getAuthor().getIdLong());
314+
displayStatus(channelMonitor.getStatusChannelFor(messageEvent.getGuild()));
315+
messageEvent.getMessage().reply(UserStrings.NEW_QUESTION.message()).queue();
312316
}
313317
}
314318

@@ -366,4 +370,4 @@ private void initStatusMessageChannels(@NotNull final JDA jda) {
366370
}
367371
return channel;
368372
}
369-
}
373+
}

application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,4 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) {
230230
reason, deleteHistoryDays, guild, event));
231231
}).queue();
232232
}
233-
}
233+
}

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
import net.dv8tion.jda.api.JDA;
44
import net.dv8tion.jda.api.Permission;
5-
import net.dv8tion.jda.api.entities.AbstractChannel;
5+
import net.dv8tion.jda.api.entities.Channel;
66
import net.dv8tion.jda.api.entities.Guild;
77
import net.dv8tion.jda.api.entities.TextChannel;
88
import net.dv8tion.jda.api.events.ReadyEvent;
99
import net.dv8tion.jda.api.events.interaction.ButtonClickEvent;
1010
import net.dv8tion.jda.api.events.interaction.SelectionMenuEvent;
1111
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
12-
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
13-
import net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent;
12+
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
13+
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
1414
import net.dv8tion.jda.api.exceptions.ErrorHandler;
1515
import net.dv8tion.jda.api.hooks.ListenerAdapter;
1616
import net.dv8tion.jda.api.interactions.commands.Command;
@@ -152,19 +152,21 @@ public void onReady(@NotNull ReadyEvent event) {
152152
}
153153

154154
@Override
155-
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
155+
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
156156
getMessageReceiversSubscribedTo(event.getChannel())
157-
.forEach(messageReceiver -> messageReceiver.onMessageReceived(event));
157+
.forEach(messageReceiver -> messageReceiver.onMessageReceived(event));
158158
}
159159

160160
@Override
161-
public void onGuildMessageUpdate(@NotNull GuildMessageUpdateEvent event) {
161+
public void onMessageUpdate(@NotNull MessageUpdateEvent event) {
162162
getMessageReceiversSubscribedTo(event.getChannel())
163-
.forEach(messageReceiver -> messageReceiver.onMessageUpdated(event));
163+
.forEach(messageReceiver -> messageReceiver.onMessageUpdated(event));
164164
}
165165

166+
167+
166168
private @NotNull Stream<MessageReceiver> getMessageReceiversSubscribedTo(
167-
@NotNull AbstractChannel channel) {
169+
@NotNull Channel channel) {
168170
String channelName = channel.getName();
169171
return channelNameToMessageReceiver.entrySet()
170172
.stream()
@@ -279,7 +281,7 @@ private static void handleRegisterErrors(Throwable ex, Guild guild) {
279281
Optional<TextChannel> channelToReportTo = guild.getTextChannelCache()
280282
.stream()
281283
.filter(channel -> guild.getPublicRole()
282-
.hasPermission(channel, Permission.MESSAGE_WRITE))
284+
.hasPermission(channel, Permission.MESSAGE_SEND))
283285
.findAny();
284286

285287
// Report the problem to the guild
@@ -328,4 +330,4 @@ private interface TriConsumer<A, B, C> {
328330
*/
329331
void accept(A first, B second, C third);
330332
}
331-
}
333+
}

application/src/main/java/org/togetherjava/tjbot/commands/tophelper/TopHelpersMessageListener.java

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

3-
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
3+
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
44
import org.jetbrains.annotations.NotNull;
55
import org.togetherjava.tjbot.commands.MessageReceiverAdapter;
66
import org.togetherjava.tjbot.config.Config;
@@ -28,15 +28,15 @@ public TopHelpersMessageListener(@NotNull Database database) {
2828
}
2929

3030
@Override
31-
public void onMessageReceived(@NotNull GuildMessageReceivedEvent event) {
31+
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
3232
if (event.getAuthor().isBot() || event.isWebhookMessage()) {
3333
return;
3434
}
3535

3636
addMessageRecord(event);
3737
}
3838

39-
private void addMessageRecord(@NotNull GuildMessageReceivedEvent event) {
39+
private void addMessageRecord(@NotNull MessageReceivedEvent event) {
4040
database.write(context -> context.newRecord(HELP_CHANNEL_MESSAGES)
4141
.setMessageId(event.getMessage().getIdLong())
4242
.setGuildId(event.getGuild().getIdLong())
@@ -45,4 +45,4 @@ private void addMessageRecord(@NotNull GuildMessageReceivedEvent event) {
4545
.setSentAt(event.getMessage().getTimeCreated().toInstant())
4646
.insert());
4747
}
48-
}
48+
}

0 commit comments

Comments
 (0)