Compare commits

...

5 commits

Author SHA1 Message Date
6e1cb8c956 Merge branch 'refactor/scripts' 2023-10-12 12:01:52 +02:00
a186ba9e80 scripts/pushCommands: Refactor how commands are being read
this should reduce errors when reading commands
also this won't fail if reading one command fails
2023-10-12 11:55:53 +02:00
a05047ab7d script/pushCommands: make sure the script exits 2023-09-30 14:47:10 +02:00
4729f7f563 /check-limit: rename to check-quota and change description
to match it to the new reality, limits are named quotas now

description of an option previously was longer than 100 characters
which discord api didn't like it
2023-09-30 14:46:12 +02:00
6a31473d22 scripts: move scripts to the project root directory
I believe, that these kind of scripts should reside there
instead of src directory
2023-09-30 14:46:12 +02:00
5 changed files with 26 additions and 15 deletions

View file

@ -12,6 +12,7 @@ RUN npx prisma generate
# Typescript compiling # Typescript compiling
COPY tsconfig.json . COPY tsconfig.json .
COPY src ./src COPY src ./src
COPY scripts ./scripts
RUN npx tsc RUN npx tsc
# Run the app # Run the app

View file

@ -6,7 +6,7 @@
"scripts": { "scripts": {
"start": "tsc && node dist/src/index.js", "start": "tsc && node dist/src/index.js",
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"publishCommands": "tsc && node dist/src/scripts/pushCommands.js" "publishCommands": "tsc && node dist/scripts/pushCommands.js"
}, },
"author": "Wroclaw", "author": "Wroclaw",
"license": "MIT", "license": "MIT",

View file

@ -1,23 +1,29 @@
// https://discordjs.guide/creating-your-bot/command-deployment.html#guild-commands // https://discordjs.guide/creating-your-bot/command-deployment.html#guild-commands
import { REST, RESTGetAPIOAuth2CurrentApplicationResult, RESTPostAPIApplicationCommandsJSONBody, Routes } from "discord.js"; import { REST, RESTGetAPIOAuth2CurrentApplicationResult, RESTPostAPIApplicationCommandsJSONBody, Routes } from "discord.js";
import { config } from "../index"; import { config } from "../src/index";
import requireDirectory from "require-directory"; import requireDirectory from "require-directory";
import Command from "../command"; import Command from "../src/command";
const post: RESTPostAPIApplicationCommandsJSONBody[] = []; const post: RESTPostAPIApplicationCommandsJSONBody[] = [];
const guildId = process.argv.slice(2)[0]; const guildId = process.argv.slice(2)[0];
requireDirectory<{default: Command}, void>(module, "../commands", { const importedCommands = requireDirectory(module, "../src/commands");
visit: function (obj) {
console.log(obj); for (const obj in importedCommands) {
try {
const allExports = importedCommands[obj] as {default: unknown};
const defaultExport = allExports.default;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-expect-error
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call const constructedExport = new defaultExport() as unknown;
post.push(new obj.default().toRESTPostApplicationCommands()); if (!(constructedExport instanceof Command)) throw new Error(`${obj}'s default does not extends Command`);
}, post.push(constructedExport.toRESTPostApplicationCommands());
}); } catch (e) {
console.error(e);
}
}
const rest = new REST().setToken(config.tokens.Discord); const rest = new REST().setToken(config.tokens.Discord);
@ -37,6 +43,8 @@ const rest = new REST().setToken(config.tokens.Discord);
); );
} }
console.log("Refreshed successfully"); console.log("Refreshed successfully");
process.exit(0);
})().catch( e => { })().catch( e => {
console.error(e); console.error(e);
process.exit(1);
}); });

View file

@ -4,13 +4,13 @@ import Command from "../command";
import { config } from "../index"; import { config } from "../index";
export default class MyLimit extends Command implements Command { export default class MyLimit extends Command implements Command {
name = "check-limit"; name = "check-quota";
description = "Checks your limit and usage"; description = "Checks your quota and usage";
type = ApplicationCommandType.ChatInput; type = ApplicationCommandType.ChatInput;
options: APIApplicationCommandOption[] = [ options: APIApplicationCommandOption[] = [
{ {
name: "recovery-for", name: "recovery-for",
description: "Calculate the limit recovery time for given message count (default: amount required to use the bot again or 1)", description: "Get the recovery time for given quota units count (default: until can use the bot or 1)",
type: ApplicationCommandOptionType.Integer, type: ApplicationCommandOptionType.Integer,
required: false, required: false,
}, },
@ -18,6 +18,7 @@ export default class MyLimit extends Command implements Command {
name: "ephemeral", name: "ephemeral",
description: "if true, only you can see the response (default true)", description: "if true, only you can see the response (default true)",
type: ApplicationCommandOptionType.Boolean, type: ApplicationCommandOptionType.Boolean,
required: false,
} }
]; ];

View file

@ -1,6 +1,7 @@
{ {
"include": [ "include": [
"./src/**/*" "./src/**/*",
"./scripts/**/*"
], ],
"compilerOptions": { "compilerOptions": {
"target": "ES2022", "target": "ES2022",