mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
My life sucks
- Fixes mistake that caused the shop plugin to not enable properly - Fixes issue that caused the Discord integration to block the main thread when it shouldn't - Removes old legacy code that still relied on JDA - Fixes issue that caused slash commands to fail to register properly
This commit is contained in:
parent
631b691518
commit
5332dc88cd
@ -1,43 +1,31 @@
|
||||
package me.totalfreedom.discord;
|
||||
|
||||
import discord4j.common.util.Snowflake;
|
||||
import discord4j.core.DiscordClientBuilder;
|
||||
import discord4j.core.GatewayDiscordClient;
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
|
||||
import discord4j.core.object.entity.Guild;
|
||||
import discord4j.core.object.entity.Member;
|
||||
import discord4j.core.object.entity.Role;
|
||||
import discord4j.core.object.entity.channel.TextChannel;
|
||||
import me.totalfreedom.discord.command.HelpCommand;
|
||||
import me.totalfreedom.discord.command.ListCommand;
|
||||
import me.totalfreedom.discord.command.TPSCommand;
|
||||
import me.totalfreedom.discord.handling.CommandHandler;
|
||||
import me.totalfreedom.discord.util.SnowflakeEntry;
|
||||
import me.totalfreedom.discord.util.TFM_Bridge;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.PlayerData;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import net.dv8tion.jda.internal.utils.concurrent.CountingThreadFactory;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
|
||||
public class Bot
|
||||
{
|
||||
private final GatewayDiscordClient client;
|
||||
private final TFM_Bridge tfm;
|
||||
private final HashMap<String, PlayerData> LINK_CODES = new HashMap<>();
|
||||
private ScheduledThreadPoolExecutor RATELIMIT_EXECUTOR;
|
||||
private Boolean enabled = false;
|
||||
|
||||
|
||||
public Bot()
|
||||
{
|
||||
//Creates the gateway client and connects to the gateway
|
||||
@ -59,25 +47,20 @@ public class Bot
|
||||
is overly complicated for such a simple demo and requires handling for both IDE and .jar packaging.
|
||||
Using SpringBoot we can avoid all of this and use their resource pattern matcher to do this for us.
|
||||
*/
|
||||
List<String> commands = List.of("greet.json", "ping.json");
|
||||
|
||||
try
|
||||
{
|
||||
handler.registerCommands(commands);
|
||||
handler.registerCommand(new HelpCommand());
|
||||
handler.registerCommand(new ListCommand());
|
||||
handler.registerCommand(new TPSCommand());
|
||||
} catch (Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Bukkit.getLogger().severe("Error trying to register global slash commands.\n" + e.getMessage());
|
||||
}
|
||||
//Register our slash command listener
|
||||
client.on(ChatInputInteractionEvent.class, handler::handle)
|
||||
.then(client.onDisconnect())
|
||||
.block(); // We use .block() as there is not another non-daemon thread and the jvm would close otherwise.
|
||||
|
||||
RATELIMIT_EXECUTOR = new ScheduledThreadPoolExecutor(5, new CountingThreadFactory(this::poolIdentifier, "RateLimit"));
|
||||
RATELIMIT_EXECUTOR.setRemoveOnCancelPolicy(true);
|
||||
.then(client.onDisconnect());
|
||||
//.block(); // We use .block() as there is not another non-daemon thread and the jvm would close otherwise.
|
||||
}
|
||||
|
||||
public String formatBotTag() {
|
||||
@ -131,7 +114,6 @@ public class Bot
|
||||
|
||||
Guild server = client.getGuildById(SnowflakeEntry.serverID).block();
|
||||
if (server == null)
|
||||
|
||||
{
|
||||
FLog.severe("The Discord server ID specified is invalid, or the bot is not on the server.");
|
||||
return false;
|
||||
|
@ -28,7 +28,6 @@ import reactor.core.publisher.Mono;
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -42,10 +41,7 @@ public class TFD4JCommonsImpl implements TFD4JCommons
|
||||
{
|
||||
this.tfd4J = tfd4J;
|
||||
this.sentMessages = Flux.fromIterable(new ArrayList<>());
|
||||
this.DISCORD_SUBDOMAINS = (ImmutableList<String>)
|
||||
List.of("discordapp.com",
|
||||
"discord.com",
|
||||
"discord.gg");
|
||||
this.DISCORD_SUBDOMAINS = ImmutableList.of("discordapp.com", "discord.com", "discord.gg");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: TF-Shoppe
|
||||
main: me.totalfreedom.shop.Shop
|
||||
main: me.totalfreedom.shop.TFShoppe
|
||||
version: ${project.version}
|
||||
authors: [AtlasMediaGroup, TotalFreedom]
|
||||
api-version: 1.19
|
||||
|
Loading…
Reference in New Issue
Block a user