Compare commits
135 Commits
d3d9a305d0
...
f88e14b34a
Author | SHA1 | Date | |
---|---|---|---|
f88e14b34a | |||
94b0797797 | |||
1253c1acf4 | |||
54dcfddd1a | |||
4653af6f90 | |||
0d80761e2c | |||
bba1617926 | |||
b8adefd093 | |||
c7aad7190e | |||
fe139004bf | |||
3563e5be62 | |||
8d2f647ffd | |||
146bdf363e | |||
647dc6211b | |||
aee298f791 | |||
2a695f24c6 | |||
cfc714611e | |||
580b54c549 | |||
aa3eac70ba | |||
5b7862fe7b | |||
7983eb60f9 | |||
4aee497fba | |||
e0c581dcfd | |||
84f754dd5b | |||
3cea3694db | |||
fa6a9fa2e3 | |||
73562b3570 | |||
0c3c1b5582 | |||
7ea28db049 | |||
e74bd83ee6 | |||
ab6ca9edeb | |||
064abe7e24 | |||
5c4192eb4b | |||
b99db199d7 | |||
9f3bceeade | |||
bdb08c1810 | |||
b76e772ee2 | |||
f919dde7fa | |||
76526e08b9 | |||
80d4693c3d | |||
ffa4d43d8f | |||
2a33dea919 | |||
04bbb7e376 | |||
14a63d43d1 | |||
d7bef27f52 | |||
fe211b7055 | |||
0edfd41c13 | |||
a14298fa66 | |||
daef590b83 | |||
4e3cfacfa4 | |||
4ab74597b7 | |||
b5440ae98d | |||
78cdf79fc4 | |||
13497ebf43 | |||
5e43e9ba18 | |||
1ebe30f981 | |||
746341d48a | |||
3a2073f61f | |||
73de6dbcec | |||
7a9c2441a3 | |||
5338b56e4c | |||
552b0b9c3d | |||
dc166dd286 | |||
cb1662cefb | |||
e69806c132 | |||
dfe673bebc | |||
81bb307896 | |||
2c7dd26189 | |||
067702ecc6 | |||
03fb793b6c | |||
83068ae085 | |||
76641b31c7 | |||
ea54565c6a | |||
8e9ddb1e7b | |||
f5d8bcc449 | |||
7f94c9ddd3 | |||
b9407ed52c | |||
6ded01b046 | |||
3339d7a244 | |||
0ffb68fd96 | |||
f3e2715703 | |||
a29e2074a5 | |||
d212ca398a | |||
d0ec7fbb6c | |||
b5079b6f40 | |||
1a3e7ac96b | |||
a0eb75e4ee | |||
c8e3fc2f2c | |||
000acd20aa | |||
105932b5a3 | |||
4fea72ad88 | |||
32ceb7646b | |||
46e938946c | |||
fdedb50bc5 | |||
61b8a9a2ec | |||
86091f5eee | |||
095ad012ff | |||
4bdd04a881 | |||
cb56dded3b | |||
7fa972b411 | |||
70d183e1ef | |||
d272bdb15e | |||
c66cff1d21 | |||
474a35a736 | |||
ddcec60be6 | |||
531b07e304 | |||
42293efb68 | |||
3fa0bd9c1f | |||
1e716d5f5e | |||
afa958b557 | |||
d7409ed0f7 | |||
124e5afe5a | |||
7cd7d68d3b | |||
caa23d6cb2 | |||
3d89bd8e65 | |||
cd44a4717a | |||
04b259cf56 | |||
7026ed56a8 | |||
ae8562c536 | |||
7468dca986 | |||
7126d34866 | |||
e41afe0ada | |||
1f5f5621c3 | |||
56a2c697dc | |||
c19ef05c82 | |||
8a619b53e4 | |||
db551f7e5b | |||
7fe865ad98 | |||
0edf46856a | |||
713135a021 | |||
e67a846fa4 | |||
617edfd0a2 | |||
3f1495cd07 | |||
7b04f95444 | |||
c222b0db1d |
@ -4,6 +4,7 @@ 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,5 +8,8 @@
|
|||||||
"ecmaVersion": "latest",
|
"ecmaVersion": "latest",
|
||||||
"sourceType": "module"
|
"sourceType": "module"
|
||||||
},
|
},
|
||||||
"rules": {}
|
"plugins": ["jsdoc"],
|
||||||
|
"rules": {
|
||||||
|
"jsdoc/no-undefined-types": 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -2,4 +2,6 @@
|
|||||||
node_modules
|
node_modules
|
||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
|
commands/examples
|
||||||
|
docs
|
||||||
|
7
.jsdoc.conf.json
Normal file
7
.jsdoc.conf.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"source": {
|
||||||
|
"include": ["."],
|
||||||
|
"exclude": ["node_modules", "commands/examples"],
|
||||||
|
"includePattern": ".+\\.js(doc|x)?$"
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ 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,13 +3,17 @@ 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.`);
|
||||||
@ -32,6 +36,7 @@ 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((module) => module !== 0)
|
.filter(/** @param {(Module|0)} module */ (module) => module !== 0)
|
||||||
.map((module) => module.data.toJSON())
|
.map(/** @param {Module} module */ (module) => module.data.toJSON())
|
||||||
).then(putCommands);
|
)
|
||||||
|
.then(putCommands);
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
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 {
|
||||||
@ -21,9 +27,21 @@ 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(`[INFO] Command ${(cmdName ?? interaction.commandName) ?? 'anonymous'} ${description ?? `used "${name}"`}.`);
|
console.info(
|
||||||
|
`[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);
|
||||||
@ -31,7 +49,9 @@ 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,7 +1,8 @@
|
|||||||
import { Events } from 'discord.js';
|
import { Events, Client } 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,23 +1,38 @@
|
|||||||
import { Client, Collection, GatewayIntentBits } from 'discord.js';
|
import { Client, Collection, GatewayIntentBits, Partials } 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))
|
||||||
@ -35,13 +50,10 @@ 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)))
|
(await Promise.all(files.map(importAndCheck))).filter((module) => module !== 0)
|
||||||
.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(
|
const events = await Promise.all(files.map(async (filePath) => await import(filePath)));
|
||||||
files.map(async (filePath) =>
|
|
||||||
await import(filePath)
|
|
||||||
));
|
|
||||||
runClient(commands, events);
|
runClient(commands, events);
|
||||||
});
|
});
|
||||||
|
1536
package-lock.json
generated
1536
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -8,18 +8,20 @@
|
|||||||
"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.3.1",
|
"dotenv": "^16.4.5",
|
||||||
"proxy-agent": "^6.3.1"
|
"sqlite3": "^5.1.7"
|
||||||
},
|
},
|
||||||
"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"
|
||||||
|
90
shared.js
90
shared.js
@ -1,38 +1,52 @@
|
|||||||
import { join } from 'path';
|
import { readdir } from 'fs/promises';
|
||||||
import { readdir } from 'fs/promises';
|
import { join } from 'path';
|
||||||
|
import Module from 'module';
|
||||||
const required = ['data', 'execute'];
|
|
||||||
const optional = ['autocomplete', 'modalSubmit'];
|
// Lists of required and optional attributes of command modules
|
||||||
|
const required = ['data', 'execute'];
|
||||||
export const getFiles = async (dir) => {
|
const optional = ['autocomplete', 'modalSubmit'];
|
||||||
const dirents = await readdir(dir, { withFileTypes: true });
|
|
||||||
const files = await Promise.all(dirents.map((dirent) => {
|
/**
|
||||||
const res = join(dir, dirent.name);
|
* Recursively scans a directory for all files in it.
|
||||||
return dirent.isDirectory() ? getFiles(res) : res;
|
* @param {string} dir
|
||||||
}));
|
* @returns {Promise<Array<string>>} Array of paths to the files within.
|
||||||
return Array.prototype.concat(...files);
|
*/
|
||||||
};
|
export const getFiles = async (dir) => {
|
||||||
|
const dirents = await readdir(dir, { withFileTypes: true });
|
||||||
export const importAndCheck = async (filePath) => {
|
const files = await Promise.all(
|
||||||
if (!filePath.endsWith('.js') || filePath.endsWith('.example.js')) {
|
dirents.map((dirent) => {
|
||||||
// Skip this file
|
const res = join(dir, dirent.name);
|
||||||
return 0;
|
return dirent.isDirectory() ? getFiles(res) : res;
|
||||||
}
|
})
|
||||||
const command = await import(filePath);
|
);
|
||||||
// Warn incomplete commands
|
return Array.prototype.concat(...files);
|
||||||
if (!required.every((name) => name in command)) {
|
};
|
||||||
console.error(
|
|
||||||
`[ERROR] The command at ${filePath} is missing a required "data" or "execute" property.`
|
/**
|
||||||
);
|
* Imports and checks a command from a path as a module.
|
||||||
return 0;
|
* @param {string} filePath
|
||||||
}
|
* @returns {Promise<Module|0>}
|
||||||
const properties = optional.filter((name) => !(name in command));
|
*/
|
||||||
if (properties.length > 0)
|
export const importAndCheck = async (filePath) => {
|
||||||
properties.forEach((name) =>
|
if (!filePath.endsWith('.js') || filePath.endsWith('.example.js')) {
|
||||||
console.warn(
|
// Skip this file
|
||||||
`[WARNING] The command at ${filePath} is missing an optional "${name}" property.`
|
return 0;
|
||||||
)
|
}
|
||||||
);
|
const command = await import(filePath);
|
||||||
// Add command to collection
|
// Warn incomplete commands
|
||||||
return command;
|
if (!required.every((name) => name in command)) {
|
||||||
};
|
console.error(
|
||||||
|
`[ERROR] The command at ${filePath} is missing a required "data" or "execute" property.`
|
||||||
|
);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
const properties = optional.filter((name) => !(name in command));
|
||||||
|
if (properties.length > 0)
|
||||||
|
properties.forEach((name) =>
|
||||||
|
console.warn(
|
||||||
|
`[WARNING] The command at ${filePath} is missing an optional "${name}" property.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
// Add command to collection
|
||||||
|
return command;
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user