Compare commits
No commits in common. "f88e14b34ac35e8be44cde95ca4142cc157df42e" and "d3d9a305d0b877974da1fc5389e0175a06b2e48d" have entirely different histories.
f88e14b34a
...
d3d9a305d0
@ -4,7 +4,6 @@ node_modules
|
|||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
docs
|
|
||||||
|
|
||||||
# Ignore files for PNPM, NPM and YARN
|
# Ignore files for PNPM, NPM and YARN
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
|
@ -8,8 +8,5 @@
|
|||||||
"ecmaVersion": "latest",
|
"ecmaVersion": "latest",
|
||||||
"sourceType": "module"
|
"sourceType": "module"
|
||||||
},
|
},
|
||||||
"plugins": ["jsdoc"],
|
"rules": {}
|
||||||
"rules": {
|
|
||||||
"jsdoc/no-undefined-types": 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,5 +3,3 @@ node_modules
|
|||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
commands/examples
|
|
||||||
docs
|
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"source": {
|
|
||||||
"include": ["."],
|
|
||||||
"exclude": ["node_modules", "commands/examples"],
|
|
||||||
"includePattern": ".+\\.js(doc|x)?$"
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,6 @@ node_modules
|
|||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
docs
|
|
||||||
|
|
||||||
# Ignore files for PNPM, NPM and YARN
|
# Ignore files for PNPM, NPM and YARN
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
|
13
deploy.js
13
deploy.js
@ -3,17 +3,13 @@ import { REST, Routes } from 'discord.js';
|
|||||||
import { join, dirname } from 'path';
|
import { join, dirname } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { config } from 'dotenv';
|
import { config } from 'dotenv';
|
||||||
import Module from 'module';
|
|
||||||
|
|
||||||
config();
|
config();
|
||||||
|
|
||||||
// Construct and prepare an instance of the REST module
|
// Construct and prepare an instance of the REST module
|
||||||
const rest = new REST().setToken(process.env.TOKEN);
|
const rest = new REST().setToken(process.env.TOKEN);
|
||||||
|
|
||||||
/**
|
// and deploy your commands!
|
||||||
* Calls HTTP PUT to register commands in discord.
|
|
||||||
* @param {Array<Object>} commands
|
|
||||||
*/
|
|
||||||
const putCommands = async (commands) => {
|
const putCommands = async (commands) => {
|
||||||
try {
|
try {
|
||||||
console.info(`[INFO] Started refreshing ${commands.length} application (/) commands.`);
|
console.info(`[INFO] Started refreshing ${commands.length} application (/) commands.`);
|
||||||
@ -36,7 +32,6 @@ getFiles(cmdPath)
|
|||||||
// For each command file
|
// For each command file
|
||||||
.then(async (files) =>
|
.then(async (files) =>
|
||||||
(await Promise.all(files.map(importAndCheck)))
|
(await Promise.all(files.map(importAndCheck)))
|
||||||
.filter(/** @param {(Module|0)} module */ (module) => module !== 0)
|
.filter((module) => module !== 0)
|
||||||
.map(/** @param {Module} module */ (module) => module.data.toJSON())
|
.map((module) => module.data.toJSON())
|
||||||
)
|
).then(putCommands);
|
||||||
.then(putCommands);
|
|
||||||
|
@ -1,11 +1,5 @@
|
|||||||
import { Events } from 'discord.js';
|
import { Events } from 'discord.js';
|
||||||
import Module from 'module';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A more precise execution function specifically to call the main property of a module.
|
|
||||||
* @param {import('discord.js').Interaction} interaction
|
|
||||||
* @param {Module} command
|
|
||||||
*/
|
|
||||||
const executeCommand = async (interaction, command) => {
|
const executeCommand = async (interaction, command) => {
|
||||||
// Try executing command
|
// Try executing command
|
||||||
try {
|
try {
|
||||||
@ -27,21 +21,9 @@ const executeCommand = async (interaction, command) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* A generic execution function to call command methods.
|
|
||||||
* @param {import('discord.js').Interaction} interaction
|
|
||||||
* @param {Module} command
|
|
||||||
* @param {string} name
|
|
||||||
* @param {string=} description
|
|
||||||
* @param {string=} cmdName
|
|
||||||
*/
|
|
||||||
const genericExecute = async (interaction, command, name, description, cmdName) => {
|
const genericExecute = async (interaction, command, name, description, cmdName) => {
|
||||||
try {
|
try {
|
||||||
console.info(
|
console.info(`[INFO] Command ${(cmdName ?? interaction.commandName) ?? 'anonymous'} ${description ?? `used "${name}"`}.`);
|
||||||
`[INFO] Command ${cmdName ?? interaction.commandName ?? 'anonymous'} ${
|
|
||||||
description ?? `used "${name}"`
|
|
||||||
}.`
|
|
||||||
);
|
|
||||||
await command[name](interaction);
|
await command[name](interaction);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -49,9 +31,7 @@ const genericExecute = async (interaction, command, name, description, cmdName)
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const name = Events.InteractionCreate;
|
export const name = Events.InteractionCreate;
|
||||||
/** @param {import('discord.js').Interaction} interaction */
|
|
||||||
export async function execute(interaction) {
|
export async function execute(interaction) {
|
||||||
/** @type {Module} */
|
|
||||||
let command = interaction.client.commands.get(interaction.commandName);
|
let command = interaction.client.commands.get(interaction.commandName);
|
||||||
|
|
||||||
// Execute slash- and context-menu-commands
|
// Execute slash- and context-menu-commands
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import { Events, Client } from 'discord.js';
|
import { Events } from 'discord.js';
|
||||||
|
|
||||||
export const name = Events.ClientReady;
|
export const name = Events.ClientReady;
|
||||||
export const once = true;
|
export const once = true;
|
||||||
/** @param {Client} client */
|
|
||||||
export function execute(client) {
|
export function execute(client) {
|
||||||
console.info(`[INFO] Ready! Logged in as ${client.user.tag}`);
|
console.info(`[INFO] Ready! Logged in as ${client.user.tag}`);
|
||||||
}
|
}
|
||||||
|
30
index.js
30
index.js
@ -1,38 +1,23 @@
|
|||||||
import { Client, Collection, GatewayIntentBits, Partials } from 'discord.js';
|
import { Client, Collection, GatewayIntentBits } from 'discord.js';
|
||||||
import { getFiles, importAndCheck } from './shared.js';
|
import { getFiles, importAndCheck } from './shared.js';
|
||||||
|
import { Partials } from 'discord.js';
|
||||||
import { join, dirname } from 'path';
|
import { join, dirname } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { config } from 'dotenv';
|
import { config } from 'dotenv';
|
||||||
import Module from 'module';
|
|
||||||
|
|
||||||
config();
|
config();
|
||||||
|
|
||||||
/**
|
|
||||||
* Main entry point, the bot logs on to discord.
|
|
||||||
* @param {Array<Module>} commands
|
|
||||||
* @param {Array<Module>} events
|
|
||||||
*/
|
|
||||||
const runClient = (commands, events) => {
|
const runClient = (commands, events) => {
|
||||||
// Create a new client instance
|
// Create a new client instance
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
GatewayIntentBits.Guilds,
|
GatewayIntentBits.Guilds,
|
||||||
GatewayIntentBits.GuildMembers,
|
|
||||||
GatewayIntentBits.GuildMessages,
|
GatewayIntentBits.GuildMessages,
|
||||||
GatewayIntentBits.GuildVoiceStates,
|
|
||||||
GatewayIntentBits.GuildMessageReactions
|
|
||||||
],
|
],
|
||||||
partials: [Partials.Message, Partials.Reaction]
|
partials: [Partials.Message, Partials.Reaction]
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* The commands registered for this client.
|
|
||||||
* @type {Collection}
|
|
||||||
*/
|
|
||||||
client.commands = new Collection();
|
client.commands = new Collection();
|
||||||
commands.forEach((c) => client.commands.set(c.data.name, c));
|
commands.forEach((c) => client.commands.set(c.data.name, c));
|
||||||
|
|
||||||
// Register client events
|
|
||||||
events.forEach((e) =>
|
events.forEach((e) =>
|
||||||
e.once
|
e.once
|
||||||
? client.once(e.name, (...args) => e.execute(...args))
|
? client.once(e.name, (...args) => e.execute(...args))
|
||||||
@ -50,10 +35,13 @@ const evtPath = join(__dirname, 'events');
|
|||||||
getFiles(cmdPath)
|
getFiles(cmdPath)
|
||||||
// For each command file
|
// For each command file
|
||||||
.then(async (files) =>
|
.then(async (files) =>
|
||||||
(await Promise.all(files.map(importAndCheck))).filter((module) => module !== 0)
|
(await Promise.all(files.map(importAndCheck)))
|
||||||
)
|
.filter((module) => module !== 0)
|
||||||
.then(async (commands) => {
|
).then(async (commands) => {
|
||||||
const files = await getFiles(evtPath);
|
const files = await getFiles(evtPath);
|
||||||
const events = await Promise.all(files.map(async (filePath) => await import(filePath)));
|
const events = await Promise.all(
|
||||||
|
files.map(async (filePath) =>
|
||||||
|
await import(filePath)
|
||||||
|
));
|
||||||
runClient(commands, events);
|
runClient(commands, events);
|
||||||
});
|
});
|
||||||
|
1524
package-lock.json
generated
1524
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -8,20 +8,18 @@
|
|||||||
"start": "node .",
|
"start": "node .",
|
||||||
"deploy": "node deploy.js",
|
"deploy": "node deploy.js",
|
||||||
"lint": "prettier --check . && eslint .",
|
"lint": "prettier --check . && eslint .",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write ."
|
||||||
"jsdoc": "rm -rf docs/ && jsdoc -c ./.jsdoc.conf.json -d docs/ -r ."
|
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.14.1",
|
"discord.js": "^14.14.1",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.3.1",
|
||||||
"sqlite3": "^5.1.7"
|
"proxy-agent": "^6.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^8.56.0",
|
"eslint": "^8.56.0",
|
||||||
"eslint-config-prettier": "^9.1.0",
|
"eslint-config-prettier": "^9.1.0",
|
||||||
"eslint-plugin-jsdoc": "^48.0.6",
|
|
||||||
"prettier": "^3.1.1"
|
"prettier": "^3.1.1"
|
||||||
},
|
},
|
||||||
"type": "module"
|
"type": "module"
|
||||||
|
24
shared.js
24
shared.js
@ -1,32 +1,18 @@
|
|||||||
import { readdir } from 'fs/promises';
|
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import Module from 'module';
|
import { readdir } from 'fs/promises';
|
||||||
|
|
||||||
// Lists of required and optional attributes of command modules
|
|
||||||
const required = ['data', 'execute'];
|
const required = ['data', 'execute'];
|
||||||
const optional = ['autocomplete', 'modalSubmit'];
|
const optional = ['autocomplete', 'modalSubmit'];
|
||||||
|
|
||||||
/**
|
|
||||||
* Recursively scans a directory for all files in it.
|
|
||||||
* @param {string} dir
|
|
||||||
* @returns {Promise<Array<string>>} Array of paths to the files within.
|
|
||||||
*/
|
|
||||||
export const getFiles = async (dir) => {
|
export const getFiles = async (dir) => {
|
||||||
const dirents = await readdir(dir, { withFileTypes: true });
|
const dirents = await readdir(dir, { withFileTypes: true });
|
||||||
const files = await Promise.all(
|
const files = await Promise.all(dirents.map((dirent) => {
|
||||||
dirents.map((dirent) => {
|
const res = join(dir, dirent.name);
|
||||||
const res = join(dir, dirent.name);
|
return dirent.isDirectory() ? getFiles(res) : res;
|
||||||
return dirent.isDirectory() ? getFiles(res) : res;
|
}));
|
||||||
})
|
|
||||||
);
|
|
||||||
return Array.prototype.concat(...files);
|
return Array.prototype.concat(...files);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Imports and checks a command from a path as a module.
|
|
||||||
* @param {string} filePath
|
|
||||||
* @returns {Promise<Module|0>}
|
|
||||||
*/
|
|
||||||
export const importAndCheck = async (filePath) => {
|
export const importAndCheck = async (filePath) => {
|
||||||
if (!filePath.endsWith('.js') || filePath.endsWith('.example.js')) {
|
if (!filePath.endsWith('.js') || filePath.endsWith('.example.js')) {
|
||||||
// Skip this file
|
// Skip this file
|
||||||
|
Loading…
Reference in New Issue
Block a user