mirror of
https://code.chipmunk.land/Parker2991/NitoriBot/
synced 2026-12-05 08:35:39 -05:00
v9.1.0 build 5322
This commit is contained in:
@@ -81,6 +81,7 @@ public final class Config {
|
||||
public boolean isPrivate;
|
||||
public String username;
|
||||
public String discordChannelId;
|
||||
public String fluxerChannelId;
|
||||
public int reconnectDelay;
|
||||
public int selfcareInterval;
|
||||
public String mode;
|
||||
|
||||
@@ -7,16 +7,29 @@ import com.google.gson.JsonParser;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.boot.GetBotBuildInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.boot.LoadConfig;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.console.CreateConsole;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.blocks.BlockRegistries;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.BotBuildInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.RepoCommitInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.discord.MessageLogger;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.discord.SlashCommandEvent;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.console.FileLogging.compress;
|
||||
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.events.GenericEvent;
|
||||
import net.dv8tion.jda.api.events.session.ReadyEvent;
|
||||
import net.dv8tion.jda.api.interactions.IntegrationType;
|
||||
import net.dv8tion.jda.api.interactions.InteractionContextType;
|
||||
import net.dv8tion.jda.api.interactions.commands.ICommandReference;
|
||||
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.Commands;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -24,11 +37,13 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EventListener;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class Main {
|
||||
public final class Main implements EventListener {
|
||||
private static final Gson GSON = new Gson();
|
||||
public static final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
public static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||
@@ -176,6 +191,37 @@ public final class Main {
|
||||
Bots.add(bot);
|
||||
bot.connect();
|
||||
}
|
||||
|
||||
final NitoriBot bot = Bots.getFirst();
|
||||
|
||||
/*
|
||||
yeah yeah bitch at me for this hce, but for whatever reason it was acting like not all commands was
|
||||
registered even though they were
|
||||
*/
|
||||
List<CommandData> commands = new ArrayList<>();
|
||||
|
||||
for (CommandInfo command : bot.commandManager.commands) {
|
||||
scheduler.schedule(() -> {
|
||||
commands.add(
|
||||
Commands.slash(
|
||||
command.getAliases().getFirst(),
|
||||
command.getDescription()
|
||||
).addOption(OptionType.STRING, "content", "arguments")
|
||||
.setContexts(InteractionContextType.BOT_DM, InteractionContextType.GUILD,
|
||||
InteractionContextType.PRIVATE_CHANNEL)
|
||||
.setIntegrationTypes(
|
||||
IntegrationType.GUILD_INSTALL,
|
||||
IntegrationType.USER_INSTALL
|
||||
)
|
||||
|
||||
);
|
||||
}, 2500, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
scheduler.schedule(() -> {
|
||||
discordClient.updateCommands().addCommands(commands).queue();
|
||||
}, 3000, TimeUnit.MILLISECONDS);
|
||||
discordClient.addEventListener(new SlashCommandEvent(bot));
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(
|
||||
"{}",
|
||||
|
||||
+17
-6
@@ -8,13 +8,19 @@ import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.componentToAnsi;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.discord.SlashCommandEvent;
|
||||
import net.dv8tion.jda.api.events.Event;
|
||||
import net.dv8tion.jda.api.events.GenericEvent;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record CommandSource(
|
||||
PlayerProfileData sender,
|
||||
MessageReceivedEvent discordEvent,
|
||||
GenericEvent discordEvent,
|
||||
CommandMessageSource source,
|
||||
ChatType chatType,
|
||||
ParsedChatType parsedChatType
|
||||
@@ -42,11 +48,16 @@ public record CommandSource(
|
||||
);
|
||||
}
|
||||
case CommandMessageSource.DISCORD -> {
|
||||
final String message = "```ansi\n" + componentToAnsi(component) + "\n```";
|
||||
discordEvent
|
||||
.getMessage()
|
||||
.reply(message)
|
||||
.queue();
|
||||
if (discordEvent instanceof MessageReceivedEvent event) {
|
||||
final String message = "```ansi\n" + componentToAnsi(component) + "\n```";
|
||||
event
|
||||
.getMessage()
|
||||
.reply(message)
|
||||
.queue();
|
||||
} else if (discordEvent instanceof SlashCommandInteractionEvent event) {
|
||||
final String message = "```ansi\n" + componentToAnsi(component) + "\n```";
|
||||
event.reply(message).queue();
|
||||
}
|
||||
}
|
||||
case CommandMessageSource.CONSOLE -> {
|
||||
Component host = Component
|
||||
|
||||
+46
-5
@@ -2,14 +2,29 @@ package land.chipmunk.parker2991.nitoribot.nightofnights.discord;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandMessageSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class MessageLogger extends ListenerAdapter {
|
||||
private final JDA client;
|
||||
|
||||
private Guild getServer (String id) {
|
||||
for (Guild servers : client.getGuilds()) {
|
||||
if (servers.getId().equals(id)) return servers;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived (MessageReceivedEvent event) {
|
||||
if (event
|
||||
@@ -20,12 +35,38 @@ public final class MessageLogger extends ListenerAdapter {
|
||||
.getId()))
|
||||
return;
|
||||
|
||||
for (NitoriBot bot : Main.Bots) {
|
||||
if (event
|
||||
.getChannel()
|
||||
final MessageChannelUnion channel = event.getChannel();
|
||||
|
||||
final NitoriBot bot = Main.Bots.getFirst();
|
||||
|
||||
final String message = event.getMessage().getContentRaw();
|
||||
|
||||
if (message.startsWith(Main.config.prefixes.getFirst())) {
|
||||
System.out.println(message);
|
||||
final String args = message.substring(Main.config.prefixes.getFirst().length());
|
||||
final CommandSource source = new CommandSource(
|
||||
null,
|
||||
event,
|
||||
CommandMessageSource.DISCORD,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
final Component output = bot.commandManager.executeString(
|
||||
source,
|
||||
args
|
||||
);
|
||||
|
||||
source.sendFeedback(bot, output);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (NitoriBot eachBot : Main.Bots) {
|
||||
if (channel
|
||||
.getId()
|
||||
.equals(bot.options.discordChannelId)) {
|
||||
for (Listener listener : bot.listenerManager.listeners()) {
|
||||
.equals(eachBot.options.discordChannelId)) {
|
||||
for (Listener listener : eachBot.listenerManager.listeners()) {
|
||||
listener.discordMessageReceived(event);
|
||||
}
|
||||
}
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.discord;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandMessageSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil.componentToAnsi;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class SlashCommandEvent extends ListenerAdapter {
|
||||
private NitoriBot bot;
|
||||
|
||||
@Override
|
||||
public void onSlashCommandInteraction (SlashCommandInteractionEvent event) {
|
||||
for (CommandInfo commands : bot.commandManager.commands) {
|
||||
if (event
|
||||
.getName()
|
||||
.equals(commands
|
||||
.getAliases()
|
||||
.getFirst())) {
|
||||
final String content = event.getOption(
|
||||
"content",
|
||||
OptionMapping::getAsString
|
||||
);
|
||||
String command;
|
||||
if (content == null)
|
||||
command = event.getName();
|
||||
else
|
||||
command = event.getName() + " " + content;
|
||||
final CommandSource source = new CommandSource(
|
||||
null,
|
||||
event,
|
||||
CommandMessageSource.DISCORD,
|
||||
null,
|
||||
null
|
||||
);
|
||||
final Component output = bot.commandManager.executeString(
|
||||
source,
|
||||
command
|
||||
);
|
||||
|
||||
final String message = "```ansi\n" + componentToAnsi(output) + "\n```";
|
||||
event
|
||||
.reply(message)
|
||||
.queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SlashCommandEvent (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
}
|
||||
}
|
||||
+23
-15
@@ -16,6 +16,7 @@ import static land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUti
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.ChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.ParsedChatType;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.events.GenericEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -140,21 +141,24 @@ public class CommandManagerModule {
|
||||
if (source
|
||||
.source()
|
||||
.equals(CommandMessageSource.DISCORD)) {
|
||||
final MessageReceivedEvent event = source.discordEvent();
|
||||
final int userTrustLevel = getDiscordRoleTrustLevelAsInteger(event
|
||||
.getMember()
|
||||
.getRoles());
|
||||
final GenericEvent discordEvent = source.discordEvent();
|
||||
if (discordEvent instanceof MessageReceivedEvent event) {
|
||||
final int userTrustLevel = getDiscordRoleTrustLevelAsInteger(event
|
||||
.getMember()
|
||||
.getRoles());
|
||||
|
||||
if (userTrustLevel < cmdTrustLevel) {
|
||||
final Component playerTrustLevelComponent = convertTrustLevelIdToComponent(userTrustLevel);
|
||||
final Component cmdTrustLevelComponent = convertTrustLevelIdToComponent(cmdTrustLevel);
|
||||
if (userTrustLevel < cmdTrustLevel) {
|
||||
final Component playerTrustLevelComponent = convertTrustLevelIdToComponent(userTrustLevel);
|
||||
final Component cmdTrustLevelComponent = convertTrustLevelIdToComponent(cmdTrustLevel);
|
||||
|
||||
throw new CommandError(Component.translatable(
|
||||
"Your Trust Level (%s) does not meet the required Trust Level (%s) for the command: %s",
|
||||
playerTrustLevelComponent,
|
||||
cmdTrustLevelComponent,
|
||||
Component.text(commandName)
|
||||
));
|
||||
throw new CommandError(Component.translatable(
|
||||
"Your Trust Level (%s) does not meet the required Trust Level (%s) for the command: %s",
|
||||
playerTrustLevelComponent,
|
||||
cmdTrustLevelComponent,
|
||||
Component.text(commandName)
|
||||
));
|
||||
} else
|
||||
throw new CommandError(Component.text("this command can only be ran in the bots discord channels!"));
|
||||
}
|
||||
} else {
|
||||
final int playerTrustLevel = source.sender().trustLevel.level();
|
||||
@@ -176,9 +180,13 @@ public class CommandManagerModule {
|
||||
}
|
||||
}
|
||||
|
||||
if (command.getPlayerChatOnly() == true && source.chatType() != ChatType.PLAYER) return null;
|
||||
if (command.getPlayerChatOnly() == true && source.chatType() != ChatType.PLAYER)
|
||||
return null;
|
||||
|
||||
if (source.source() != CommandMessageSource.CONSOLE && command.getTrustLevel().level() == 4) throw new CommandError(Component.text("This command can only be ran via console!"));
|
||||
if (source.source() != CommandMessageSource.CONSOLE && command
|
||||
.getTrustLevel()
|
||||
.level() == 4)
|
||||
throw new CommandError(Component.text("This command can only be ran via console!"));
|
||||
|
||||
commandOutput = command.execute(context);
|
||||
} catch (CommandError error) {
|
||||
|
||||
+1
@@ -7,6 +7,7 @@ import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.ChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.channel.Channel;
|
||||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"color": "green"
|
||||
}
|
||||
],
|
||||
"version": "v9.0.2",
|
||||
"version": "v9.1.0",
|
||||
"codename": [
|
||||
{
|
||||
"text": "Night",
|
||||
@@ -26,7 +26,7 @@
|
||||
"color": "blue"
|
||||
}
|
||||
],
|
||||
"build": "5321",
|
||||
"build": "5322",
|
||||
"versionReleaseDate": "N\\A",
|
||||
"initialBotRelease": "November 22, 2022"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user