forked from syntaxbullet/AuroraBot-discord
feat(settings): support toggling disabled commands and auto-reload bot on save
This commit is contained in:
@@ -8,6 +8,7 @@ import { EventLoader } from "@lib/loaders/EventLoader";
|
|||||||
export class Client extends DiscordClient {
|
export class Client extends DiscordClient {
|
||||||
|
|
||||||
commands: Collection<string, Command>;
|
commands: Collection<string, Command>;
|
||||||
|
knownCommands: Set<string>;
|
||||||
lastCommandTimestamp: number | null = null;
|
lastCommandTimestamp: number | null = null;
|
||||||
maintenanceMode: boolean = false;
|
maintenanceMode: boolean = false;
|
||||||
private commandLoader: CommandLoader;
|
private commandLoader: CommandLoader;
|
||||||
@@ -16,6 +17,7 @@ export class Client extends DiscordClient {
|
|||||||
constructor({ intents }: { intents: number[] }) {
|
constructor({ intents }: { intents: number[] }) {
|
||||||
super({ intents });
|
super({ intents });
|
||||||
this.commands = new Collection<string, Command>();
|
this.commands = new Collection<string, Command>();
|
||||||
|
this.knownCommands = new Set<string>();
|
||||||
this.commandLoader = new CommandLoader(this);
|
this.commandLoader = new CommandLoader(this);
|
||||||
this.eventLoader = new EventLoader(this);
|
this.eventLoader = new EventLoader(this);
|
||||||
}
|
}
|
||||||
@@ -77,6 +79,7 @@ export class Client extends DiscordClient {
|
|||||||
async loadCommands(reload: boolean = false) {
|
async loadCommands(reload: boolean = false) {
|
||||||
if (reload) {
|
if (reload) {
|
||||||
this.commands.clear();
|
this.commands.clear();
|
||||||
|
this.knownCommands.clear();
|
||||||
console.log("♻️ Reloading commands...");
|
console.log("♻️ Reloading commands...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ export class CommandLoader {
|
|||||||
if (this.isValidCommand(command)) {
|
if (this.isValidCommand(command)) {
|
||||||
command.category = category;
|
command.category = category;
|
||||||
|
|
||||||
|
// Track all known commands regardless of enabled status
|
||||||
|
this.client.knownCommands.add(command.data.name);
|
||||||
|
|
||||||
const isEnabled = config.commands[command.data.name] !== false;
|
const isEnabled = config.commands[command.data.name] !== false;
|
||||||
|
|
||||||
if (!isEnabled) {
|
if (!isEnabled) {
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ mock.module("../../bot/lib/BotClient", () => ({
|
|||||||
},
|
},
|
||||||
commands: [
|
commands: [
|
||||||
{ data: { name: "ping" } }
|
{ data: { name: "ping" } }
|
||||||
]
|
],
|
||||||
|
knownCommands: new Set(["ping", "help", "disabled-cmd"])
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@@ -186,8 +186,13 @@ export async function createWebServer(config: WebServerConfig = {}): Promise<Web
|
|||||||
// Merge partial update into current config
|
// Merge partial update into current config
|
||||||
const mergedConfig = deepMerge(currentConfig, partialConfig);
|
const mergedConfig = deepMerge(currentConfig, partialConfig);
|
||||||
|
|
||||||
|
|
||||||
// saveConfig throws if validation fails
|
// saveConfig throws if validation fails
|
||||||
saveConfig(mergedConfig);
|
saveConfig(mergedConfig);
|
||||||
|
|
||||||
|
const { systemEvents, EVENTS } = await import("@shared/lib/events");
|
||||||
|
systemEvents.emit(EVENTS.ACTIONS.RELOAD_COMMANDS);
|
||||||
|
|
||||||
return Response.json({ success: true });
|
return Response.json({ success: true });
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -221,7 +226,7 @@ export async function createWebServer(config: WebServerConfig = {}): Promise<Web
|
|||||||
const channels = guild.channels.cache
|
const channels = guild.channels.cache
|
||||||
.map(c => ({ id: c.id, name: c.name, type: c.type }));
|
.map(c => ({ id: c.id, name: c.name, type: c.type }));
|
||||||
|
|
||||||
const commands = AuroraClient.commands.map(c => c.data.name);
|
const commands = Array.from(AuroraClient.knownCommands).sort();
|
||||||
|
|
||||||
return Response.json({ roles, channels, commands });
|
return Response.json({ roles, channels, commands });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user