Update Discord Module to JDA 5
This commit is contained in:
parent
a1fa1e38f8
commit
697128bcf2
|
@ -4,12 +4,14 @@ plugins {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly project(':EssentialsX')
|
compileOnly project(':EssentialsX')
|
||||||
implementation('net.dv8tion:JDA:4.4.1_353') {
|
implementation('net.dv8tion:JDA:5.0.0-beta.12') {
|
||||||
exclude(module: 'opus-java')
|
exclude(module: 'opus-java')
|
||||||
}
|
}
|
||||||
implementation 'com.vdurmont:emoji-java:5.1.1'
|
implementation 'com.github.MinnDevelopment:emoji-java:v6.1.0'
|
||||||
implementation 'club.minnced:discord-webhooks:0.7.2'
|
implementation('club.minnced:discord-webhooks:0.8.2') {
|
||||||
compileOnly 'org.apache.logging.log4j:log4j-core:2.15.0'
|
exclude(module: 'okhttp')
|
||||||
|
}
|
||||||
|
compileOnly 'org.apache.logging.log4j:log4j-core:2.17.1'
|
||||||
compileOnly 'me.clip:placeholderapi:2.10.9'
|
compileOnly 'me.clip:placeholderapi:2.10.9'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +30,7 @@ shadowJar {
|
||||||
include(dependency('org.slf4j:slf4j-api'))
|
include(dependency('org.slf4j:slf4j-api'))
|
||||||
|
|
||||||
// Emoji
|
// Emoji
|
||||||
include(dependency('com.vdurmont:emoji-java'))
|
include(dependency('com.github.MinnDevelopment:emoji-java'))
|
||||||
include(dependency('org.json:json'))
|
include(dependency('org.json:json'))
|
||||||
|
|
||||||
// discord-webhooks
|
// discord-webhooks
|
||||||
|
|
|
@ -472,7 +472,7 @@ public class DiscordSettings implements IConf {
|
||||||
activityType = Activity.ActivityType.valueOf(activity);
|
activityType = Activity.ActivityType.valueOf(activity);
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
activityType = Activity.ActivityType.DEFAULT;
|
activityType = Activity.ActivityType.PLAYING;
|
||||||
}
|
}
|
||||||
if (activityType != null) {
|
if (activityType != null) {
|
||||||
statusActivity = Activity.of(activityType, config.getString("presence.message", "Minecraft"));
|
statusActivity = Activity.of(activityType, config.getString("presence.message", "Minecraft"));
|
||||||
|
|
|
@ -11,14 +11,15 @@ import com.earth2me.essentials.utils.NumberUtil;
|
||||||
import com.earth2me.essentials.utils.VersionUtil;
|
import com.earth2me.essentials.utils.VersionUtil;
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.JDABuilder;
|
import net.dv8tion.jda.api.JDABuilder;
|
||||||
import net.dv8tion.jda.api.entities.Emote;
|
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.Role;
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
|
||||||
import net.dv8tion.jda.api.entities.Webhook;
|
import net.dv8tion.jda.api.entities.Webhook;
|
||||||
import net.dv8tion.jda.api.events.ShutdownEvent;
|
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||||
|
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
|
||||||
|
import net.dv8tion.jda.api.events.session.ShutdownEvent;
|
||||||
import net.dv8tion.jda.api.hooks.EventListener;
|
import net.dv8tion.jda.api.hooks.EventListener;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
|
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||||
import net.dv8tion.jda.api.utils.cache.CacheFlag;
|
import net.dv8tion.jda.api.utils.cache.CacheFlag;
|
||||||
import net.ess3.nms.refl.providers.AchievementListenerProvider;
|
import net.ess3.nms.refl.providers.AchievementListenerProvider;
|
||||||
import net.ess3.nms.refl.providers.AdvancementListenerProvider;
|
import net.ess3.nms.refl.providers.AdvancementListenerProvider;
|
||||||
|
@ -154,7 +155,7 @@ public class JDADiscordService implements DiscordService, IEssentialsModule {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
channel.sendMessage(strippedContent)
|
channel.sendMessage(strippedContent)
|
||||||
.allowedMentions(groupMentions ? null : DiscordUtil.NO_GROUP_MENTIONS)
|
.setAllowedMentions(groupMentions ? null : DiscordUtil.NO_GROUP_MENTIONS)
|
||||||
.queue();
|
.queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +170,8 @@ public class JDADiscordService implements DiscordService, IEssentialsModule {
|
||||||
|
|
||||||
jda = JDABuilder.createDefault(plugin.getSettings().getBotToken())
|
jda = JDABuilder.createDefault(plugin.getSettings().getBotToken())
|
||||||
.addEventListeners(new DiscordListener(this))
|
.addEventListeners(new DiscordListener(this))
|
||||||
.enableCache(CacheFlag.EMOTE)
|
.enableIntents(GatewayIntent.MESSAGE_CONTENT)
|
||||||
|
.enableCache(CacheFlag.EMOJI)
|
||||||
.disableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE)
|
.disableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE)
|
||||||
.setContextEnabled(false)
|
.setContextEnabled(false)
|
||||||
.build()
|
.build()
|
||||||
|
@ -205,7 +207,7 @@ public class JDADiscordService implements DiscordService, IEssentialsModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load emotes into cache, JDA will handle updates from here on out.
|
// Load emotes into cache, JDA will handle updates from here on out.
|
||||||
guild.retrieveEmotes().queue();
|
guild.retrieveEmojis().queue();
|
||||||
|
|
||||||
updatePrimaryChannel();
|
updatePrimaryChannel();
|
||||||
|
|
||||||
|
@ -323,10 +325,10 @@ public class JDADiscordService implements DiscordService, IEssentialsModule {
|
||||||
public void updatePrimaryChannel() {
|
public void updatePrimaryChannel() {
|
||||||
TextChannel channel = guild.getTextChannelById(plugin.getSettings().getPrimaryChannelId());
|
TextChannel channel = guild.getTextChannelById(plugin.getSettings().getPrimaryChannelId());
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
channel = guild.getDefaultChannel();
|
if (!(guild.getDefaultChannel() instanceof TextChannel)) {
|
||||||
if (channel == null) {
|
|
||||||
throw new RuntimeException(tl("discordErrorNoPerms"));
|
throw new RuntimeException(tl("discordErrorNoPerms"));
|
||||||
}
|
}
|
||||||
|
channel = (TextChannel) guild.getDefaultChannel();
|
||||||
logger.warning(tl("discordErrorNoPrimary", channel.getName()));
|
logger.warning(tl("discordErrorNoPrimary", channel.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,7 +339,7 @@ public class JDADiscordService implements DiscordService, IEssentialsModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String parseMessageEmotes(String message) {
|
public String parseMessageEmotes(String message) {
|
||||||
for (final Emote emote : guild.getEmoteCache()) {
|
for (final RichCustomEmoji emote : guild.getEmojiCache()) {
|
||||||
message = message.replaceAll(":" + Pattern.quote(emote.getName()) + ":", emote.getAsMention());
|
message = message.replaceAll(":" + Pattern.quote(emote.getName()) + ":", emote.getAsMention());
|
||||||
}
|
}
|
||||||
return message;
|
return message;
|
||||||
|
@ -483,7 +485,7 @@ public class JDADiscordService implements DiscordService, IEssentialsModule {
|
||||||
|
|
||||||
shutdownConsoleRelay(true);
|
shutdownConsoleRelay(true);
|
||||||
|
|
||||||
for (WebhookClient webhook : channelIdToWebhook.values()) {
|
for (WrappedWebhookClient webhook : channelIdToWebhook.values()) {
|
||||||
webhook.close();
|
webhook.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ import com.earth2me.essentials.CommandSource;
|
||||||
import com.earth2me.essentials.commands.EssentialsCommand;
|
import com.earth2me.essentials.commands.EssentialsCommand;
|
||||||
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
|
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
|
||||||
import com.vdurmont.emoji.EmojiParser;
|
import com.vdurmont.emoji.EmojiParser;
|
||||||
import net.dv8tion.jda.api.entities.Emote;
|
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;
|
||||||
import net.essentialsx.discord.JDADiscordService;
|
import net.essentialsx.discord.JDADiscordService;
|
||||||
import net.essentialsx.discord.util.DiscordUtil;
|
import net.essentialsx.discord.util.DiscordUtil;
|
||||||
import net.essentialsx.discord.util.MessageUtil;
|
import net.essentialsx.discord.util.MessageUtil;
|
||||||
|
@ -48,7 +48,7 @@ public class Commanddiscordbroadcast extends EssentialsCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.sendMessage(jda.parseMessageEmotes(message))
|
channel.sendMessage(jda.parseMessageEmotes(message))
|
||||||
.allowedMentions(sender.isAuthorized("essentials.discordbroadcast.ping", ess) ? null : DiscordUtil.NO_GROUP_MENTIONS)
|
.setAllowedMentions(sender.isAuthorized("essentials.discordbroadcast.ping", ess) ? null : DiscordUtil.NO_GROUP_MENTIONS)
|
||||||
.queue();
|
.queue();
|
||||||
|
|
||||||
sender.sendMessage(tl("discordbroadcastSent", "#" + EmojiParser.parseToAliases(channel.getName())));
|
sender.sendMessage(tl("discordbroadcastSent", "#" + EmojiParser.parseToAliases(channel.getName())));
|
||||||
|
@ -65,12 +65,12 @@ public class Commanddiscordbroadcast extends EssentialsCommand {
|
||||||
final String curArg = args[args.length - 1];
|
final String curArg = args[args.length - 1];
|
||||||
if (!curArg.isEmpty() && curArg.charAt(0) == ':' && (curArg.length() == 1 || curArg.charAt(curArg.length() - 1) != ':')) {
|
if (!curArg.isEmpty() && curArg.charAt(0) == ':' && (curArg.length() == 1 || curArg.charAt(curArg.length() - 1) != ':')) {
|
||||||
final JDADiscordService jda = (JDADiscordService) module;
|
final JDADiscordService jda = (JDADiscordService) module;
|
||||||
if (jda.getGuild().getEmoteCache().isEmpty()) {
|
if (jda.getGuild().getEmojiCache().isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<String> completions = new ArrayList<>();
|
final List<String> completions = new ArrayList<>();
|
||||||
for (final Emote emote : jda.getGuild().getEmoteCache()) {
|
for (final RichCustomEmoji emote : jda.getGuild().getEmojiCache()) {
|
||||||
completions.add(":" + emote.getName() + ":");
|
completions.add(":" + emote.getName() + ":");
|
||||||
}
|
}
|
||||||
return completions;
|
return completions;
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package net.essentialsx.discord.interactions;
|
package net.essentialsx.discord.interactions;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.entities.GuildChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
|
||||||
|
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
|
||||||
import net.essentialsx.api.v2.services.discord.InteractionChannel;
|
import net.essentialsx.api.v2.services.discord.InteractionChannel;
|
||||||
|
|
||||||
public class InteractionChannelImpl implements InteractionChannel {
|
public class InteractionChannelImpl implements InteractionChannel {
|
||||||
private final GuildChannel channel;
|
private final GuildMessageChannel channel;
|
||||||
|
|
||||||
public InteractionChannelImpl(GuildChannel channel) {
|
public InteractionChannelImpl(GuildMessageChannel channel) {
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
package net.essentialsx.discord.interactions;
|
package net.essentialsx.discord.interactions;
|
||||||
|
|
||||||
import com.earth2me.essentials.utils.StringUtil;
|
import com.earth2me.essentials.utils.StringUtil;
|
||||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
|
import net.dv8tion.jda.api.exceptions.ErrorResponseException;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
import net.dv8tion.jda.api.interactions.commands.Command;
|
import net.dv8tion.jda.api.interactions.commands.Command;
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
|
||||||
import net.dv8tion.jda.api.requests.ErrorResponse;
|
import net.dv8tion.jda.api.requests.ErrorResponse;
|
||||||
import net.essentialsx.api.v2.services.discord.InteractionCommand;
|
import net.essentialsx.api.v2.services.discord.InteractionCommand;
|
||||||
import net.essentialsx.api.v2.services.discord.InteractionCommandArgument;
|
import net.essentialsx.api.v2.services.discord.InteractionCommandArgument;
|
||||||
|
@ -42,7 +44,7 @@ public class InteractionControllerImpl extends ListenerAdapter implements Intera
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSlashCommand(@NotNull SlashCommandEvent event) {
|
public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
|
||||||
if (event.getGuild() == null || event.getMember() == null || !commandMap.containsKey(event.getName())) {
|
if (event.getGuild() == null || event.getMember() == null || !commandMap.containsKey(event.getName())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +79,7 @@ public class InteractionControllerImpl extends ListenerAdapter implements Intera
|
||||||
for (final InteractionCommand command : batchRegistrationQueue.values()) {
|
for (final InteractionCommand command : batchRegistrationQueue.values()) {
|
||||||
// German is quite the language
|
// German is quite the language
|
||||||
final String description = StringUtil.abbreviate(command.getDescription(), 100);
|
final String description = StringUtil.abbreviate(command.getDescription(), 100);
|
||||||
final CommandData data = new CommandData(command.getName(), description);
|
final SlashCommandData data = Commands.slash(command.getName(), description);
|
||||||
if (command.getArguments() != null) {
|
if (command.getArguments() != null) {
|
||||||
for (final InteractionCommandArgument argument : command.getArguments()) {
|
for (final InteractionCommandArgument argument : command.getArguments()) {
|
||||||
// German doesn't support spaces between words
|
// German doesn't support spaces between words
|
||||||
|
@ -132,7 +134,7 @@ public class InteractionControllerImpl extends ListenerAdapter implements Intera
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final CommandData data = new CommandData(command.getName(), command.getDescription());
|
final SlashCommandData data = Commands.slash(command.getName(), command.getDescription());
|
||||||
if (command.getArguments() != null) {
|
if (command.getArguments() != null) {
|
||||||
for (final InteractionCommandArgument argument : command.getArguments()) {
|
for (final InteractionCommandArgument argument : command.getArguments()) {
|
||||||
data.addOption(OptionType.valueOf(argument.getType().name()), argument.getName(), argument.getDescription(), argument.isRequired());
|
data.addOption(OptionType.valueOf(argument.getType().name()), argument.getName(), argument.getDescription(), argument.isRequired());
|
||||||
|
|
|
@ -2,10 +2,10 @@ package net.essentialsx.discord.interactions;
|
||||||
|
|
||||||
import com.earth2me.essentials.utils.FormatUtil;
|
import com.earth2me.essentials.utils.FormatUtil;
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import net.dv8tion.jda.api.MessageBuilder;
|
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||||
|
import net.dv8tion.jda.api.utils.messages.MessageEditBuilder;
|
||||||
import net.essentialsx.api.v2.services.discord.InteractionChannel;
|
import net.essentialsx.api.v2.services.discord.InteractionChannel;
|
||||||
import net.essentialsx.api.v2.services.discord.InteractionEvent;
|
import net.essentialsx.api.v2.services.discord.InteractionEvent;
|
||||||
import net.essentialsx.api.v2.services.discord.InteractionMember;
|
import net.essentialsx.api.v2.services.discord.InteractionMember;
|
||||||
|
@ -23,11 +23,11 @@ import java.util.logging.Logger;
|
||||||
*/
|
*/
|
||||||
public class InteractionEventImpl implements InteractionEvent {
|
public class InteractionEventImpl implements InteractionEvent {
|
||||||
private final static Logger logger = EssentialsDiscord.getWrappedLogger();
|
private final static Logger logger = EssentialsDiscord.getWrappedLogger();
|
||||||
private final SlashCommandEvent event;
|
private final SlashCommandInteractionEvent event;
|
||||||
private final InteractionMember member;
|
private final InteractionMember member;
|
||||||
private final List<String> replyBuffer = new ArrayList<>();
|
private final List<String> replyBuffer = new ArrayList<>();
|
||||||
|
|
||||||
public InteractionEventImpl(final SlashCommandEvent jdaEvent) {
|
public InteractionEventImpl(final SlashCommandInteractionEvent jdaEvent) {
|
||||||
this.event = jdaEvent;
|
this.event = jdaEvent;
|
||||||
this.member = new InteractionMemberImpl(jdaEvent.getMember());
|
this.member = new InteractionMemberImpl(jdaEvent.getMember());
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class InteractionEventImpl implements InteractionEvent {
|
||||||
String reply = Joiner.on('\n').join(replyBuffer);
|
String reply = Joiner.on('\n').join(replyBuffer);
|
||||||
reply = reply.substring(0, Math.min(Message.MAX_CONTENT_LENGTH, reply.length()));
|
reply = reply.substring(0, Math.min(Message.MAX_CONTENT_LENGTH, reply.length()));
|
||||||
event.getHook().editOriginal(
|
event.getHook().editOriginal(
|
||||||
new MessageBuilder()
|
new MessageEditBuilder()
|
||||||
.setContent(reply)
|
.setContent(reply)
|
||||||
.setAllowedMentions(DiscordUtil.NO_GROUP_MENTIONS).build())
|
.setAllowedMentions(DiscordUtil.NO_GROUP_MENTIONS).build())
|
||||||
.queue(null, error -> logger.log(Level.SEVERE, "Error while editing command interaction response", error));
|
.queue(null, error -> logger.log(Level.SEVERE, "Error while editing command interaction response", error));
|
||||||
|
@ -77,7 +77,7 @@ public class InteractionEventImpl implements InteractionEvent {
|
||||||
@Override
|
@Override
|
||||||
public InteractionChannel getChannelArgument(String key) {
|
public InteractionChannel getChannelArgument(String key) {
|
||||||
final OptionMapping mapping = event.getOption(key);
|
final OptionMapping mapping = event.getOption(key);
|
||||||
return mapping == null ? null : new InteractionChannelImpl(mapping.getAsGuildChannel());
|
return mapping == null ? null : new InteractionChannelImpl(mapping.getAsChannel().asGuildMessageChannel());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,8 +2,8 @@ package net.essentialsx.discord.interactions;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.Permission;
|
import net.dv8tion.jda.api.Permission;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.PrivateChannel;
|
|
||||||
import net.dv8tion.jda.api.entities.Role;
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
|
import net.dv8tion.jda.api.entities.channel.concrete.PrivateChannel;
|
||||||
import net.essentialsx.api.v2.services.discord.InteractionMember;
|
import net.essentialsx.api.v2.services.discord.InteractionMember;
|
||||||
import net.essentialsx.api.v2.services.discord.InteractionRole;
|
import net.essentialsx.api.v2.services.discord.InteractionRole;
|
||||||
import net.essentialsx.discord.util.DiscordUtil;
|
import net.essentialsx.discord.util.DiscordUtil;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.essentialsx.discord.listeners;
|
package net.essentialsx.discord.listeners;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
import net.essentialsx.discord.JDADiscordService;
|
import net.essentialsx.discord.JDADiscordService;
|
||||||
import net.essentialsx.discord.util.DiscordCommandSender;
|
import net.essentialsx.discord.util.DiscordCommandSender;
|
||||||
|
@ -18,7 +19,11 @@ public class DiscordCommandDispatcher extends ListenerAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
|
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
|
||||||
|
if (event.getMessage().getChannelType() != ChannelType.TEXT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (jda.getConsoleWebhook() != null && event.getChannel().getId().equals(channelId)) {
|
if (jda.getConsoleWebhook() != null && event.getChannel().getId().equals(channelId)) {
|
||||||
if ((event.isWebhookMessage() || event.getAuthor().isBot()) && (!jda.getSettings().isConsoleBotCommandRelay() || DiscordUtil.ACTIVE_WEBHOOKS.contains(event.getAuthor().getId()) || event.getAuthor().getId().equals(event.getGuild().getSelfMember().getId()))) {
|
if ((event.isWebhookMessage() || event.getAuthor().isBot()) && (!jda.getSettings().isConsoleBotCommandRelay() || DiscordUtil.ACTIVE_WEBHOOKS.contains(event.getAuthor().getId()) || event.getAuthor().getId().equals(event.getGuild().getSelfMember().getId()))) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -6,7 +6,8 @@ import com.vdurmont.emoji.EmojiParser;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.api.entities.channel.ChannelType;
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
import net.ess3.api.IUser;
|
import net.ess3.api.IUser;
|
||||||
import net.essentialsx.api.v2.events.discord.DiscordRelayEvent;
|
import net.essentialsx.api.v2.events.discord.DiscordRelayEvent;
|
||||||
|
@ -36,7 +37,11 @@ public class DiscordListener extends ListenerAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuildMessageReceived(@NotNull GuildMessageReceivedEvent event) {
|
public void onMessageReceived(@NotNull MessageReceivedEvent event) {
|
||||||
|
if (event.getMessage().getChannelType() != ChannelType.TEXT) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event.getAuthor().isBot() && !event.isWebhookMessage() && (!plugin.getSettings().isShowBotMessages() || event.getAuthor().getId().equals(plugin.getJda().getSelfUser().getId()))) {
|
if (event.getAuthor().isBot() && !event.isWebhookMessage() && (!plugin.getSettings().isShowBotMessages() || event.getAuthor().getId().equals(plugin.getJda().getSelfUser().getId()))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +125,7 @@ public class DiscordListener extends ListenerAdapter {
|
||||||
// Do not create the event specific objects if there are no listeners
|
// Do not create the event specific objects if there are no listeners
|
||||||
if (DiscordRelayEvent.getHandlerList().getRegisteredListeners().length != 0) {
|
if (DiscordRelayEvent.getHandlerList().getRegisteredListeners().length != 0) {
|
||||||
final DiscordRelayEvent relayEvent = new DiscordRelayEvent(
|
final DiscordRelayEvent relayEvent = new DiscordRelayEvent(
|
||||||
new InteractionMemberImpl(member), new InteractionChannelImpl(event.getChannel()),
|
new InteractionMemberImpl(member), new InteractionChannelImpl(event.getGuildChannel()),
|
||||||
Collections.unmodifiableList(keys), event.getMessage().getContentRaw(), formattedMessage, viewers);
|
Collections.unmodifiableList(keys), event.getMessage().getContentRaw(), formattedMessage, viewers);
|
||||||
Bukkit.getPluginManager().callEvent(relayEvent);
|
Bukkit.getPluginManager().callEvent(relayEvent);
|
||||||
if (relayEvent.isCancelled()) {
|
if (relayEvent.isCancelled()) {
|
||||||
|
|
|
@ -13,8 +13,8 @@ import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.entities.Role;
|
import net.dv8tion.jda.api.entities.Role;
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
|
||||||
import net.dv8tion.jda.api.entities.Webhook;
|
import net.dv8tion.jda.api.entities.Webhook;
|
||||||
|
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||||
import net.essentialsx.api.v2.events.discord.DiscordMessageEvent;
|
import net.essentialsx.api.v2.events.discord.DiscordMessageEvent;
|
||||||
import net.essentialsx.api.v2.services.discord.MessageType;
|
import net.essentialsx.api.v2.services.discord.MessageType;
|
||||||
import net.essentialsx.discord.JDADiscordService;
|
import net.essentialsx.discord.JDADiscordService;
|
||||||
|
@ -39,7 +39,7 @@ public final class DiscordUtil {
|
||||||
final ImmutableList.Builder<Message.MentionType> types = new ImmutableList.Builder<>();
|
final ImmutableList.Builder<Message.MentionType> types = new ImmutableList.Builder<>();
|
||||||
types.add(Message.MentionType.USER);
|
types.add(Message.MentionType.USER);
|
||||||
types.add(Message.MentionType.CHANNEL);
|
types.add(Message.MentionType.CHANNEL);
|
||||||
types.add(Message.MentionType.EMOTE);
|
types.add(Message.MentionType.EMOJI);
|
||||||
NO_GROUP_MENTIONS = types.build();
|
NO_GROUP_MENTIONS = types.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,13 +4,11 @@ dependencyResolutionManagement {
|
||||||
maven("https://papermc.io/repo/repository/maven-public/")
|
maven("https://papermc.io/repo/repository/maven-public/")
|
||||||
maven("https://jitpack.io") {
|
maven("https://jitpack.io") {
|
||||||
content { includeGroup("com.github.milkbowl") }
|
content { includeGroup("com.github.milkbowl") }
|
||||||
|
content { includeGroup("com.github.MinnDevelopment") }
|
||||||
}
|
}
|
||||||
maven("https://repo.codemc.org/repository/maven-public") {
|
maven("https://repo.codemc.org/repository/maven-public") {
|
||||||
content { includeGroup("org.bstats") }
|
content { includeGroup("org.bstats") }
|
||||||
}
|
}
|
||||||
maven("https://m2.dv8tion.net/releases/") {
|
|
||||||
content { includeGroup("net.dv8tion") }
|
|
||||||
}
|
|
||||||
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") {
|
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") {
|
||||||
content { includeGroup("me.clip") }
|
content { includeGroup("me.clip") }
|
||||||
}
|
}
|
||||||
|
@ -18,6 +16,7 @@ dependencyResolutionManagement {
|
||||||
content { includeGroup("com.mojang") }
|
content { includeGroup("com.mojang") }
|
||||||
}
|
}
|
||||||
mavenCentral {
|
mavenCentral {
|
||||||
|
content { includeGroup("net.dv8tion") }
|
||||||
content { includeGroup("net.kyori") }
|
content { includeGroup("net.kyori") }
|
||||||
content { includeGroup("org.apache.logging.log4j") }
|
content { includeGroup("org.apache.logging.log4j") }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue