mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 14:38:49 +00:00
fix: Fixed annotations
This commit is contained in:
1 parent
0d9f4bd404
commit
89f8e2d0d1
6 files changed
+55
-21
No files matched your search
@@ -1,7 +1,8 @@
|
|||||||
import { Client } from 'discord.js';
|
import { Client, Collection } from 'discord.js';
|
||||||
|
|
||||||
type RegisterClientCommandsFunction = (params: { client: Client; executionId: string }) => void;
|
type RegisterClientCommandsFunction = (params: { client: Client; executionId: string }) => void;
|
||||||
|
|
||||||
export interface ExtendedClient extends Client {
|
export interface ExtendedClient extends Client {
|
||||||
registerClientCommands?: RegisterClientCommandsFunction;
|
registerClientCommands?: RegisterClientCommandsFunction;
|
||||||
|
commands?: Collection<string, NodeModule>;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export type ClientEventArguments = unknown[];
|
||||||
|
export type ProcessEventArguments = unknown[];
|
||||||
|
export type PlayerEventArguments = unknown[];
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { Player } from 'discord-player';
|
||||||
|
import { ExtendedClient } from './clientTypes';
|
||||||
|
|
||||||
|
export interface RegisterEventListenersParams {
|
||||||
|
client: ExtendedClient;
|
||||||
|
player: Player;
|
||||||
|
executionId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RegisterClientCommandsParams {
|
||||||
|
client: ExtendedClient;
|
||||||
|
executionId: string;
|
||||||
|
}
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { REST, Routes } from 'discord.js';
|
import { REST, RouteLike, Routes, SlashCommandBuilder } from 'discord.js';
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import loggerModule from '../services/logger';
|
import loggerModule from '../services/logger';
|
||||||
const systemOptions = config.get('systemOptions');
|
import { SystemOptions } from '../types/configTypes';
|
||||||
|
const systemOptions: SystemOptions = config.get('systemOptions');
|
||||||
|
|
||||||
const executionId = uuidv4();
|
const executionId = uuidv4();
|
||||||
|
|
||||||
@@ -16,8 +17,8 @@ const logger = loggerModule.child({
|
|||||||
executionId: executionId
|
executionId: executionId
|
||||||
});
|
});
|
||||||
|
|
||||||
const slashCommands = [];
|
const slashCommands: SlashCommandBuilder[] = [];
|
||||||
const systemCommands = [];
|
const systemCommands: SlashCommandBuilder[] = [];
|
||||||
const commandFolders = fs.readdirSync(path.resolve('./dist/commands'));
|
const commandFolders = fs.readdirSync(path.resolve('./dist/commands'));
|
||||||
for (const folder of commandFolders) {
|
for (const folder of commandFolders) {
|
||||||
const commandFiles = fs
|
const commandFiles = fs
|
||||||
@@ -33,6 +34,14 @@ for (const folder of commandFolders) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!process.env.DISCORD_BOT_TOKEN) {
|
||||||
|
throw new Error('DISCORD_BOT_TOKEN environment variable is not set.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!process.env.DISCORD_APPLICATION_ID) {
|
||||||
|
throw new Error('DISCORD_APPLICATION_ID environment variable is not set.');
|
||||||
|
}
|
||||||
|
|
||||||
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN);
|
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
@@ -46,7 +55,7 @@ const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN)
|
|||||||
logger.debug(`Bot user slash commands found: ${slashCommands.map((command) => `/${command.name}`).join(', ')}`);
|
logger.debug(`Bot user slash commands found: ${slashCommands.map((command) => `/${command.name}`).join(', ')}`);
|
||||||
|
|
||||||
logger.info('Started refreshing user slash commands.');
|
logger.info('Started refreshing user slash commands.');
|
||||||
await refreshCommands(Routes.applicationCommands(process.env.DISCORD_APPLICATION_ID), slashCommands);
|
await refreshCommands(Routes.applicationCommands(process.env.DISCORD_APPLICATION_ID!), slashCommands);
|
||||||
logger.info('Successfully refreshed user slash commands.');
|
logger.info('Successfully refreshed user slash commands.');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error, 'Failed to refresh user slash commands.');
|
logger.error(error, 'Failed to refresh user slash commands.');
|
||||||
@@ -62,10 +71,10 @@ const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN)
|
|||||||
logger.info('Started refreshing system slash commands.');
|
logger.info('Started refreshing system slash commands.');
|
||||||
const systemGuildIds = systemOptions.systemGuildIds;
|
const systemGuildIds = systemOptions.systemGuildIds;
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
systemGuildIds.map((systemGuildId) => {
|
systemGuildIds.map((systemGuildId: string) => {
|
||||||
logger.debug(`Refreshing system slash command for guild id '${systemGuildId}'.`);
|
logger.debug(`Refreshing system slash command for guild id '${systemGuildId}'.`);
|
||||||
refreshCommands(
|
refreshCommands(
|
||||||
Routes.applicationGuildCommands(process.env.DISCORD_APPLICATION_ID, systemGuildId),
|
Routes.applicationGuildCommands(process.env.DISCORD_APPLICATION_ID!, systemGuildId),
|
||||||
systemCommands
|
systemCommands
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
@@ -79,6 +88,6 @@ const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN)
|
|||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
async function refreshCommands(route, commands) {
|
async function refreshCommands(route: RouteLike, commands: object[]) {
|
||||||
await rest.put(route, { body: commands });
|
await rest.put(route, { body: commands });
|
||||||
}
|
}
|
||||||
@@ -2,14 +2,15 @@ import fs from 'node:fs';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { Collection } from 'discord.js';
|
import { Collection } from 'discord.js';
|
||||||
import loggerModule from '../services/logger';
|
import loggerModule from '../services/logger';
|
||||||
|
import { RegisterClientCommandsParams } from '../types/utilTypes';
|
||||||
|
|
||||||
export const registerClientCommands = ({ client, executionId }) => {
|
export const registerClientCommands = ({ client, executionId }: RegisterClientCommandsParams) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'registerClientCommands.js',
|
source: 'registerClientCommands.js',
|
||||||
module: 'register',
|
module: 'register',
|
||||||
name: 'registerClientCommands',
|
name: 'registerClientCommands',
|
||||||
executionId: executionId,
|
executionId: executionId,
|
||||||
shardId: client.shard.ids[0]
|
shardId: client.shard?.ids[0]
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.debug('Registering client commands...');
|
logger.debug('Registering client commands...');
|
||||||
@@ -33,7 +34,11 @@ export const registerClientCommands = ({ client, executionId }) => {
|
|||||||
client.commands.delete(command.data.name);
|
client.commands.delete(command.data.name);
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error registering command ${folder}/${file}: ${error.message}`);
|
if (error instanceof Error) {
|
||||||
|
logger.error(`Error registering command ${folder}/${file}: ${error.message}`);
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,18 @@ import fs from 'node:fs';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import config from 'config';
|
import config from 'config';
|
||||||
import loggerModule from '../services/logger';
|
import loggerModule from '../services/logger';
|
||||||
const loggerOptions = config.get('loggerOptions');
|
import { LoggerOptions } from '../types/configTypes';
|
||||||
|
import { RegisterEventListenersParams } from '../types/utilTypes';
|
||||||
|
import { ClientEventArguments, PlayerEventArguments, ProcessEventArguments } from '../types/eventTypes';
|
||||||
|
const loggerOptions: LoggerOptions = config.get('loggerOptions');
|
||||||
|
|
||||||
export const registerEventListeners = ({ client, player, executionId }) => {
|
export const registerEventListeners = ({ client, player, executionId }: RegisterEventListenersParams) => {
|
||||||
const logger = loggerModule.child({
|
const logger = loggerModule.child({
|
||||||
source: 'registerEventListeners.js',
|
source: 'registerEventListeners.js',
|
||||||
module: 'register',
|
module: 'register',
|
||||||
name: 'registerEventListeners',
|
name: 'registerEventListeners',
|
||||||
executionId: executionId,
|
executionId: executionId,
|
||||||
shardId: client.shard.ids[0]
|
shardId: client.shard?.ids[0]
|
||||||
});
|
});
|
||||||
|
|
||||||
logger.debug('Registering event listeners...');
|
logger.debug('Registering event listeners...');
|
||||||
@@ -29,20 +32,20 @@ export const registerEventListeners = ({ client, player, executionId }) => {
|
|||||||
switch (folder) {
|
switch (folder) {
|
||||||
case 'client':
|
case 'client':
|
||||||
if (event.once) {
|
if (event.once) {
|
||||||
client.once(event.name, (...args) => event.execute(...args));
|
client.once(event.name, (...args: ClientEventArguments) => event.execute(...args));
|
||||||
} else {
|
} else {
|
||||||
if (!event.isDebug || process.env.MINIMUM_LOG_LEVEL === 'debug') {
|
if (!event.isDebug || process.env.MINIMUM_LOG_LEVEL === 'debug') {
|
||||||
client.on(event.name, (...args) => event.execute(...args));
|
client.on(event.name, (...args: ClientEventArguments) => event.execute(...args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'interactions':
|
case 'interactions':
|
||||||
client.on(event.name, (...args) => event.execute(...args, { client }));
|
client.on(event.name, (...args: ClientEventArguments) => event.execute(...args, { client }));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'process':
|
case 'process':
|
||||||
process.on(event.name, (...args) => event.execute(...args));
|
process.on(event.name, (...args: ProcessEventArguments) => event.execute(...args));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'player':
|
case 'player':
|
||||||
@@ -51,10 +54,10 @@ export const registerEventListeners = ({ client, player, executionId }) => {
|
|||||||
(loggerOptions.minimumLogLevel === 'debug' && loggerOptions.discordPlayerDebug)
|
(loggerOptions.minimumLogLevel === 'debug' && loggerOptions.discordPlayerDebug)
|
||||||
) {
|
) {
|
||||||
if (event.isPlayerEvent) {
|
if (event.isPlayerEvent) {
|
||||||
player.events.on(event.name, (...args) => event.execute(...args));
|
player.events.on(event.name, (...args: PlayerEventArguments) => event.execute(...args));
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
player.on(event.name, (...args) => event.execute(...args));
|
player.on(event.name, (...args: PlayerEventArguments) => event.execute(...args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in new issue
Block a user