Use JDA LTS #8

Merge aplicado
Awakened-Redstone mesclou 8 commits from experimental/jda-lts into master 2022-03-13 03:26:17 +00:00
15 arquivos alterados com 90 adições e 68 exclusões
Mostrando apenas as alterações do commit 8d7ff2f52e - Mostrar todos os commits

Use JDA 4.4.0 LTS

Luna Fox 2022-03-13 00:16:34 -03:00

Ver arquivo

@ -30,6 +30,10 @@ group = project.maven_group
sourceCompatibility = 16 sourceCompatibility = 16
targetCompatibility = 16 targetCompatibility = 16
configurations {
includeTransitive
}
dependencies { dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}" minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
@ -37,20 +41,20 @@ dependencies {
include(modImplementation(fabricApi.module("fabric-lifecycle-events-v1", project.fabric_version))) include(modImplementation(fabricApi.module("fabric-lifecycle-events-v1", project.fabric_version)))
include(modImplementation(fabricApi.module("fabric-api-base", project.fabric_version))) include(modImplementation(fabricApi.module("fabric-api-base", project.fabric_version)))
implementation include('net.dv8tion:JDA:5.0.0-alpha.5') { implementation('net.dv8tion:JDA:4.4.0') {
exclude module: 'opus-java' exclude module: 'opus-java'
} }
include "net.sf.trove4j:trove4j:3.0.3" includeTransitive implementation('net.dv8tion:JDA:4.4.0_352') {
include 'org.apache.commons:commons-collections4:4.1' exclude module: 'opus-java'
include 'com.neovisionaries:nv-websocket-client:2.14' }
include 'com.squareup.okhttp3:okhttp:3.13.0'
include 'com.squareup.okio:okio:1.17.2'
include 'com.fasterxml.jackson.core:jackson-databind:2.10.1'
include 'com.fasterxml.jackson.core:jackson-annotations:2.10.1'
include 'com.fasterxml.jackson.core:jackson-core:2.10.1'
} }
configurations.getByName("includeTransitive").resolvedConfiguration.resolvedArtifacts.forEach(dep -> {
if (!dep.id.componentIdentifier.displayName.contains("slf4j-api"))
dependencies.add("include", dep.id.componentIdentifier.displayName)
})
compileJava { compileJava {
sourceCompatibility = 16 sourceCompatibility = 16
targetCompatibility = 16 targetCompatibility = 16
@ -115,7 +119,7 @@ curseforge {
id = "575422" id = "575422"
changelog = ENV.CHANGELOG ?: "No changelog provided" changelog = ENV.CHANGELOG ?: "No changelog provided"
releaseType = "release" releaseType = "release"
addGameVersion "1.18-Snapshot" addGameVersion "$project.minecraft_version"
addGameVersion "Fabric" addGameVersion "Fabric"
mainArtifact(remapJar) { mainArtifact(remapJar) {
@ -148,7 +152,6 @@ task github(dependsOn: remapMavenJar) {
releaseBuilder.name("[$project.supported_versions] AutoWhitelist - $project.version") releaseBuilder.name("[$project.supported_versions] AutoWhitelist - $project.version")
releaseBuilder.body(ENV.CHANGELOG ?: "No changelog provided") releaseBuilder.body(ENV.CHANGELOG ?: "No changelog provided")
releaseBuilder.commitish(getBranch()) releaseBuilder.commitish(getBranch())
releaseBuilder.prerelease(false)
def ghRelease = releaseBuilder.create() def ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive"); ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive");

Ver arquivo

@ -1,11 +1,11 @@
org.gradle.jvmargs=-Xmx1G org.gradle.jvmargs=-Xmx1G
minecraft_version=1.18.2-pre1 minecraft_version=1.18.2
yarn_mappings=1.18.2-pre1+build.3 yarn_mappings=1.18.2+build.1
loader_version=0.13.2 loader_version=0.13.2
mod_version=1.0.0 mod_version=1.0.1
maven_group=com.awakenedredstone maven_group=com.awakenedredstone
archives_base_name=autowhitelist archives_base_name=autowhitelist
supported_versions=1.18.2-pre1+ supported_versions=1.18.2+
fabric_version=0.47.3+1.18.2 fabric_version=0.47.3+1.18.2

Ver arquivo

@ -72,7 +72,7 @@ public class Config {
json.add("token", new JsonPrimitive("bot-token")); json.add("token", new JsonPrimitive("bot-token"));
json.add("clientId", new JsonPrimitive("client-id")); json.add("clientId", new JsonPrimitive("client-id"));
json.add("discordServerId", new JsonPrimitive("discord-server-id")); json.add("discordServerId", new JsonPrimitive("discord-server-id"));
//json.add("enableSlashCommands", new JsonPrimitive(false)); Disabled due to high times to update global commands and not being practical for now //json.add("enableSlashCommands", new JsonPrimitive(false)); Removed due to high times to update global commands and not being practical for now
JsonObject whitelistJson = JsonHelper.getNestedObject(json, "whitelist", true); JsonObject whitelistJson = JsonHelper.getNestedObject(json, "whitelist", true);
if (whitelistJson == null) { if (whitelistJson == null) {
AutoWhitelist.LOGGER.error("Something went wrong when generating the default config file!"); AutoWhitelist.LOGGER.error("Something went wrong when generating the default config file!");

Ver arquivo

@ -12,6 +12,5 @@ public class ConfigData {
public String token; public String token;
public String clientId; public String clientId;
public String discordServerId; public String discordServerId;
public boolean enableSlashCommands;
public Map<String, List<String>> whitelist; public Map<String, List<String>> whitelist;
} }

Ver arquivo

@ -22,7 +22,7 @@ import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.OptionData; import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.requests.GatewayIntent; import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.MemberCachePolicy; import net.dv8tion.jda.api.utils.MemberCachePolicy;
import net.dv8tion.jda.internal.interactions.CommandDataImpl; //import net.dv8tion.jda.internal.interactions.CommandDataImpl;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.util.logging.UncaughtExceptionHandler; import net.minecraft.util.logging.UncaughtExceptionHandler;
@ -104,8 +104,8 @@ public class Bot implements Runnable {
builder.setMemberCachePolicy(MemberCachePolicy.ALL); builder.setMemberCachePolicy(MemberCachePolicy.ALL);
jda = builder.build(); jda = builder.build();
try { try {
jda.getPresence().setActivity(Activity.of(Activity.ActivityType.valueOf(new TranslatableText("bot.activity.type").getString().toUpperCase()), new TranslatableText("bot.activity.message").getString())); jda.getPresence().setActivity(Activity.of(Activity.ActivityType.valueOf(new TranslatableText("bot.activity.type").getString().toUpperCase().replace("PLAYING", "DEFAULT")), new TranslatableText("bot.activity.message").getString()));
} catch (IllegalArgumentException | NullPointerException e) { } catch (IllegalArgumentException | NullPointerException e) { //TODO: remove the replace once JDA is updated to 5.x.x
AutoWhitelist.LOGGER.error("Failed to set bot activity, the chosen activity type value is not valid.", e); AutoWhitelist.LOGGER.error("Failed to set bot activity, the chosen activity type value is not valid.", e);
} }
TestCommand.register(AutoWhitelistAPI.dispatcher()); TestCommand.register(AutoWhitelistAPI.dispatcher());

Ver arquivo

@ -14,10 +14,11 @@ import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; //import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -53,6 +54,11 @@ public class CommandManager {
return var18; return var18;
} catch (CommandSyntaxException var14) { } catch (CommandSyntaxException var14) {
if (var14.getInput() != null && var14.getCursor() >= 0) { if (var14.getInput() != null && var14.getCursor() >= 0) {
ParseResults<DiscordCommandSource> parse = dispatcher.parse(stringReader, commandSource);
CommandContext<DiscordCommandSource> context = parse.getContext().build(parse.getReader().getString());
if (context.getChild() == null && context.getCommand() == null) {
}
int i = Math.min(var14.getInput().length(), var14.getCursor()); int i = Math.min(var14.getInput().length(), var14.getCursor());
MutableText mutableText = Util.toText(var14.getRawMessage()).shallowCopy(); MutableText mutableText = Util.toText(var14.getRawMessage()).shallowCopy();
mutableText.append("\n"); mutableText.append("\n");
@ -74,7 +80,7 @@ public class CommandManager {
embedBuilder.setDescription(mutableText.getString()); embedBuilder.setDescription(mutableText.getString());
embedBuilder.setFooter(new TranslatableText("command.feedback.message.signature").getString()); embedBuilder.setFooter(new TranslatableText("command.feedback.message.signature").getString());
embedBuilder.setColor(BotHelper.MessageType.ERROR.hexColor); embedBuilder.setColor(BotHelper.MessageType.ERROR.hexColor);
((SlashCommandInteractionEvent)commandSource.getEvent()).deferReply(true).queue(m -> m.editOriginal(new MessageBuilder().setEmbeds(embedBuilder.build()).build()).queue()); // ((SlashCommandInteractionEvent)commandSource.getEvent()).deferReply(true).queue(m -> m.editOriginal(new MessageBuilder().setEmbeds(embedBuilder.build()).build()).queue());
} else { } else {
commandSource.sendError(mutableText); commandSource.sendError(mutableText);
} }

Ver arquivo

@ -17,11 +17,11 @@ 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.MessageChannel; import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; //import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.OptionData; import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.requests.restaction.MessageAction; import net.dv8tion.jda.api.requests.restaction.MessageAction;
import net.dv8tion.jda.internal.interactions.CommandDataImpl; //import net.dv8tion.jda.internal.interactions.CommandDataImpl;
import net.minecraft.scoreboard.Team; import net.minecraft.scoreboard.Team;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
@ -40,10 +40,10 @@ public class RegisterCommand {
LiteralCommandNode<DiscordCommandSource> literalCommandNode = dispatcher.register(CommandManager.literal("register").requires(DiscordCommandSource::isFromGuild) LiteralCommandNode<DiscordCommandSource> literalCommandNode = dispatcher.register(CommandManager.literal("register").requires(DiscordCommandSource::isFromGuild)
.then(CommandManager.argument("minecraft_username", StringArgumentType.word()).executes((source) -> { .then(CommandManager.argument("minecraft_username", StringArgumentType.word()).executes((source) -> {
if (source.getSource().getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) { if (source.getSource().getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) {
((SlashCommandInteractionEvent) source.getSource().getEvent()).deferReply().queue(m -> { // ((SlashCommandInteractionEvent) source.getSource().getEvent()).deferReply().queue(m -> {
execute(source.getSource(), StringArgumentType.getString(source, "minecraft_username")); // execute(source.getSource(), StringArgumentType.getString(source, "minecraft_username"));
m.deleteOriginal().queue(); // m.deleteOriginal().queue();
}); // });
} else { } else {
execute(source.getSource(), StringArgumentType.getString(source, "minecraft_username")); execute(source.getSource(), StringArgumentType.getString(source, "minecraft_username"));
} }

Ver arquivo

@ -6,7 +6,7 @@ import com.awakenedredstone.autowhitelist.discord.api.command.DiscordCommandSour
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; //import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
@ -47,7 +47,7 @@ public class BotStatusCommand {
embedBuilder.addField("Discord timings", output, false); embedBuilder.addField("Discord timings", output, false);
if (source.getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) { if (source.getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) {
((SlashCommandInteractionEvent)source.getEvent()).replyEmbeds(embedBuilder.build()).queue(); // ((SlashCommandInteractionEvent)source.getEvent()).replyEmbeds(embedBuilder.build()).queue();
} else { } else {
source.getChannel().sendMessageEmbeds(embedBuilder.build()).queue(); source.getChannel().sendMessageEmbeds(embedBuilder.build()).queue();
} }

Ver arquivo

@ -7,9 +7,9 @@ import com.awakenedredstone.autowhitelist.discord.api.text.TranslatableText;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; //import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.internal.interactions.CommandDataImpl; //import net.dv8tion.jda.internal.interactions.CommandDataImpl;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerManager; import net.minecraft.server.PlayerManager;
import net.minecraft.util.Util; import net.minecraft.util.Util;
@ -69,7 +69,7 @@ public class ServerStatusCommand {
embedBuilder.addField("Server information", serverInformation.toString(), true); embedBuilder.addField("Server information", serverInformation.toString(), true);
if (source.getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) { if (source.getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) {
((SlashCommandInteractionEvent)source.getEvent()).replyEmbeds(embedBuilder.build()).queue(); // ((SlashCommandInteractionEvent)source.getEvent()).replyEmbeds(embedBuilder.build()).queue();
} else { } else {
source.getChannel().sendMessageEmbeds(embedBuilder.build()).queue(); source.getChannel().sendMessageEmbeds(embedBuilder.build()).queue();
} }

Ver arquivo

@ -3,14 +3,10 @@ package com.awakenedredstone.autowhitelist.discord.commands.developer;
import com.awakenedredstone.autowhitelist.AutoWhitelist; import com.awakenedredstone.autowhitelist.AutoWhitelist;
import com.awakenedredstone.autowhitelist.discord.api.command.CommandManager; import com.awakenedredstone.autowhitelist.discord.api.command.CommandManager;
import com.awakenedredstone.autowhitelist.discord.api.command.DiscordCommandSource; import com.awakenedredstone.autowhitelist.discord.api.command.DiscordCommandSource;
import com.awakenedredstone.autowhitelist.lang.TranslatableText;
import com.awakenedredstone.autowhitelist.util.Debugger; import com.awakenedredstone.autowhitelist.util.Debugger;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.tree.LiteralCommandNode;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; //import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.internal.interactions.CommandDataImpl;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import java.util.Arrays; import java.util.Arrays;
@ -61,7 +57,7 @@ public class StatusCommand {
embedBuilder.addField("Processing timings", output2.toString(), true); embedBuilder.addField("Processing timings", output2.toString(), true);
if (source.getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) { if (source.getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) {
((SlashCommandInteractionEvent)source.getEvent()).replyEmbeds(embedBuilder.build()).queue(); // ((SlashCommandInteractionEvent)source.getEvent()).replyEmbeds(embedBuilder.build()).queue();
} else { } else {
source.getChannel().sendMessageEmbeds(embedBuilder.build()).queue(); source.getChannel().sendMessageEmbeds(embedBuilder.build()).queue();
} }

Ver arquivo

@ -7,9 +7,9 @@ import com.awakenedredstone.autowhitelist.discord.api.text.TranslatableText;
import com.awakenedredstone.autowhitelist.discord.api.util.Formatting; import com.awakenedredstone.autowhitelist.discord.api.util.Formatting;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; //import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.build.CommandData; //import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.internal.interactions.CommandDataImpl; //import net.dv8tion.jda.internal.interactions.CommandDataImpl;
import static com.awakenedredstone.autowhitelist.discord.Bot.jda; import static com.awakenedredstone.autowhitelist.discord.Bot.jda;
@ -47,7 +47,7 @@ public class TestCommand {
description += "\n" + new LiteralText("Test complete, I think.").markdownFormatted(); description += "\n" + new LiteralText("Test complete, I think.").markdownFormatted();
embedBuilder.setDescription(description); embedBuilder.setDescription(description);
if (source.getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) { if (source.getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) {
((SlashCommandInteractionEvent)source.getEvent()).replyEmbeds(embedBuilder.build()).queue(); // ((SlashCommandInteractionEvent)source.getEvent()).replyEmbeds(embedBuilder.build()).queue();
} else { } else {
source.getChannel().sendMessageEmbeds(embedBuilder.build()).queue(); source.getChannel().sendMessageEmbeds(embedBuilder.build()).queue();
} }

Ver arquivo

@ -12,11 +12,11 @@ import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.CommandNode;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; //import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
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.OptionData; //import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.internal.interactions.CommandDataImpl; //import net.dv8tion.jda.internal.interactions.CommandDataImpl;
import java.util.Map; import java.util.Map;
@ -46,7 +46,7 @@ public class HelpCommand {
} }
if (source.getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) { if (source.getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) {
((SlashCommandInteractionEvent)source.getEvent()).replyEmbeds(embedBuilder.build()).queue(); // ((SlashCommandInteractionEvent)source.getEvent()).replyEmbeds(embedBuilder.build()).queue();
} else { } else {
source.getChannel().sendMessageEmbeds(embedBuilder.build()).queue(); source.getChannel().sendMessageEmbeds(embedBuilder.build()).queue();
} }
@ -75,7 +75,7 @@ public class HelpCommand {
embedBuilder.appendDescription(new LiteralText("`" + AutoWhitelist.getConfigData().prefix + result + "` | ").append(new TranslatableText("command.description." + result)).getString()); embedBuilder.appendDescription(new LiteralText("`" + AutoWhitelist.getConfigData().prefix + result + "` | ").append(new TranslatableText("command.description." + result)).getString());
} }
if (source.getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) { if (source.getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) {
((SlashCommandInteractionEvent)source.getEvent()).replyEmbeds(embedBuilder.build()).queue(); // ((SlashCommandInteractionEvent)source.getEvent()).replyEmbeds(embedBuilder.build()).queue();
} else { } else {
source.getChannel().sendMessageEmbeds(embedBuilder.build()).queue(); source.getChannel().sendMessageEmbeds(embedBuilder.build()).queue();
} }

Ver arquivo

@ -7,7 +7,7 @@ import com.awakenedredstone.autowhitelist.discord.api.text.TranslatableText;
import com.awakenedredstone.autowhitelist.discord.api.util.Formatting; import com.awakenedredstone.autowhitelist.discord.api.util.Formatting;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; //import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
@ -24,12 +24,12 @@ public class PingCommand {
public static void execute(DiscordCommandSource source) { public static void execute(DiscordCommandSource source) {
if (source.getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) { if (source.getType() == DiscordCommandSource.CommandType.SLASH_COMMAND) {
((SlashCommandInteractionEvent)source.getEvent()).deferReply().queue(r -> { /*((SlashCommandInteractionEvent)source.getEvent()).deferReply().queue(r -> {
r.editOriginal("Ping: ...").queue(m -> { r.editOriginal("Ping: ...").queue(m -> {
long ping = ((SlashCommandInteractionEvent)source.getEvent()).getInteraction().getTimeCreated().until(m.getTimeCreated(), ChronoUnit.MILLIS); long ping = ((SlashCommandInteractionEvent)source.getEvent()).getInteraction().getTimeCreated().until(m.getTimeCreated(), ChronoUnit.MILLIS);
m.editMessage("Ping: " + ping + "ms | Websocket: " + m.getJDA().getGatewayPing() + "ms").queue(); m.editMessage("Ping: " + ping + "ms | Websocket: " + m.getJDA().getGatewayPing() + "ms").queue();
}); });
}); });*/
} else { } else {
source.getChannel().sendMessage("Ping: ...").queue(m -> { source.getChannel().sendMessage("Ping: ...").queue(m -> {
long ping = source.getMessage().getTimeCreated().until(m.getTimeCreated(), ChronoUnit.MILLIS); long ping = source.getMessage().getTimeCreated().until(m.getTimeCreated(), ChronoUnit.MILLIS);

Ver arquivo

@ -2,7 +2,6 @@ package com.awakenedredstone.autowhitelist.discord.events;
import com.awakenedredstone.autowhitelist.AutoWhitelist; import com.awakenedredstone.autowhitelist.AutoWhitelist;
import com.awakenedredstone.autowhitelist.discord.DiscordDataProcessor; import com.awakenedredstone.autowhitelist.discord.DiscordDataProcessor;
import com.awakenedredstone.autowhitelist.discord.api.AutoWhitelistAPI;
import com.awakenedredstone.autowhitelist.lang.TranslatableText; import com.awakenedredstone.autowhitelist.lang.TranslatableText;
import com.awakenedredstone.autowhitelist.mixin.ServerConfigEntryMixin; import com.awakenedredstone.autowhitelist.mixin.ServerConfigEntryMixin;
import com.awakenedredstone.autowhitelist.util.ExtendedGameProfile; import com.awakenedredstone.autowhitelist.util.ExtendedGameProfile;
@ -10,7 +9,10 @@ import com.awakenedredstone.autowhitelist.util.FailedToUpdateWhitelistException;
import com.awakenedredstone.autowhitelist.util.InvalidTeamNameException; import com.awakenedredstone.autowhitelist.util.InvalidTeamNameException;
import com.awakenedredstone.autowhitelist.whitelist.ExtendedWhitelist; import com.awakenedredstone.autowhitelist.whitelist.ExtendedWhitelist;
import com.awakenedredstone.autowhitelist.whitelist.ExtendedWhitelistEntry; import com.awakenedredstone.autowhitelist.whitelist.ExtendedWhitelistEntry;
import com.mojang.brigadier.arguments.*;
import com.mojang.brigadier.tree.ArgumentCommandNode;
import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.CommandNode;
import com.mojang.brigadier.tree.LiteralCommandNode;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.User;
@ -19,10 +21,9 @@ import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent; import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent; import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent;
import net.dv8tion.jda.api.hooks.SubscribeEvent; import net.dv8tion.jda.api.hooks.SubscribeEvent;
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.OptionData; import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.internal.interactions.CommandDataImpl; //import net.dv8tion.jda.internal.interactions.CommandDataImpl;
import net.minecraft.scoreboard.Scoreboard; import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.scoreboard.Team; import net.minecraft.scoreboard.Team;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -30,14 +31,11 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.awakenedredstone.autowhitelist.discord.Bot.*; import static com.awakenedredstone.autowhitelist.discord.Bot.*;
import static com.awakenedredstone.autowhitelist.discord.Bot.whitelistDataMap;
import static com.awakenedredstone.autowhitelist.util.Debugger.analyzeTimings; import static com.awakenedredstone.autowhitelist.util.Debugger.analyzeTimings;
public class CoreEvents { public class CoreEvents {
@ -45,7 +43,7 @@ public class CoreEvents {
@SubscribeEvent @SubscribeEvent
public void onReady(ReadyEvent e) { public void onReady(ReadyEvent e) {
AutoWhitelist.LOGGER.info("Finishing setup."); AutoWhitelist.LOGGER.info("Finishing setup.");
if (AutoWhitelist.getConfigData().enableSlashCommands) { /*if (AutoWhitelist.getConfigData().enableSlashCommands) {
List<Command> commands = jda.retrieveCommands().complete(); List<Command> commands = jda.retrieveCommands().complete();
AutoWhitelistAPI.dispatcher().getRoot().getChildren().forEach(command -> { AutoWhitelistAPI.dispatcher().getRoot().getChildren().forEach(command -> {
if (commands.stream().map(Command::getName).noneMatch(slashCommand -> slashCommand.equalsIgnoreCase(command.getName()))) { if (commands.stream().map(Command::getName).noneMatch(slashCommand -> slashCommand.equalsIgnoreCase(command.getName()))) {
@ -53,8 +51,8 @@ public class CoreEvents {
} }
}); });
} else { } else {
jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).queue()); jSlashCommandDatada.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).queue());
} }*/
if (scheduledUpdate != null) { if (scheduledUpdate != null) {
scheduledUpdate.cancel(false); scheduledUpdate.cancel(false);
@ -152,8 +150,28 @@ public class CoreEvents {
if (command.getRedirect() != null) { if (command.getRedirect() != null) {
return; return;
} }
CommandDataImpl commandData = new CommandDataImpl(command.getName().toLowerCase(), new TranslatableText("command.description." + command.getName()).getString()); // CommandDataImpl commandData = new CommandDataImpl(command.getName().toLowerCase(), new TranslatableText("command.description." + command.getName()).getString());
command.getChildren().forEach(node -> commandData.addOptions(new OptionData(OptionType.STRING, node.getName(), new TranslatableText("command.description." + command.getName() + "." + node.getName()).getString()))); boolean required = command.getCommand() == null;
//jda.upsertCommand(commandData).queue(); command.getChildren().forEach(node -> {
if (node instanceof LiteralCommandNode) {
// commandData.addOptions(new OptionData(OptionType.SUB_COMMAND, node.getName(), new TranslatableText("command.description." + command.getName() + "." + node.getName()).getString(), required));
}
else if (node instanceof ArgumentCommandNode node1) {
OptionType type;
ArgumentType<?> type1 = node1.getType();
if (type1 instanceof BoolArgumentType) {
type = OptionType.BOOLEAN;
} else if (type1 instanceof DoubleArgumentType || type1 instanceof FloatArgumentType) {
type = OptionType.NUMBER;
} else if (type1 instanceof IntegerArgumentType || type1 instanceof LongArgumentType) {
type = OptionType.INTEGER;
} else {
type = OptionType.STRING;
}
// commandData.addOptions(new OptionData(type, node.getName(), new TranslatableText("command.description." + command.getName() + "." + node.getName()).getString(), required));
}
});
// jda.upsertCommand(commandData).queue();
} }
} }

Ver arquivo

@ -4,7 +4,7 @@ import com.awakenedredstone.autowhitelist.AutoWhitelist;
import com.awakenedredstone.autowhitelist.discord.api.AutoWhitelistAPI; import com.awakenedredstone.autowhitelist.discord.api.AutoWhitelistAPI;
import com.awakenedredstone.autowhitelist.discord.api.command.DiscordCommandSource; import com.awakenedredstone.autowhitelist.discord.api.command.DiscordCommandSource;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; //import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.SubscribeEvent; import net.dv8tion.jda.api.hooks.SubscribeEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionMapping;
@ -29,7 +29,7 @@ public class GatewayEvents {
} }
} }
@SubscribeEvent /*@SubscribeEvent
public void onSlashCommand(SlashCommandInteractionEvent event) { public void onSlashCommand(SlashCommandInteractionEvent event) {
String command = "/".concat(event.getName()).concat(event.getOptions().stream().map(OptionMapping::getAsString).map(v -> " " + v).collect(Collectors.joining())); String command = "/".concat(event.getName()).concat(event.getOptions().stream().map(OptionMapping::getAsString).map(v -> " " + v).collect(Collectors.joining()));
if (event.isFromGuild()) { if (event.isFromGuild()) {
@ -37,5 +37,5 @@ public class GatewayEvents {
} else { } else {
AutoWhitelistAPI.INSTANCE.getCommandManager().execute(new DiscordCommandSource(event.getUser(), null, event.getChannel(), DiscordCommandSource.CommandType.SLASH_COMMAND, event), command); AutoWhitelistAPI.INSTANCE.getCommandManager().execute(new DiscordCommandSource(event.getUser(), null, event.getChannel(), DiscordCommandSource.CommandType.SLASH_COMMAND, event), command);
} }
} }*/
} }