diff --git a/.eslintrc b/.eslintrc index ee7270c..d3fa3c0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,7 +12,7 @@ ], "extends": [ "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended" + "plugin:@typescript-eslint/strict-type-checked" ], "rules": { // simple-import-sort @@ -26,39 +26,15 @@ "typescript-sort-keys/interface": "error", "typescript-sort-keys/string-enum": "error", - // common - "no-return-await": "error", - "no-unreachable-loop": "error", - "no-promise-executor-return": "error", - "no-unsafe-optional-chaining": "error", - "no-useless-backreference": "error", - "require-atomic-updates": "error", - "require-await": "error", - "no-await-in-loop": "error", - "spaced-comment": "error", - "sort-imports": "off", - "sort-keys": "error", - "no-unused-vars": "off", // typescript-eslint suggestion: off - "curly": "error", - "camelcase": "error", - - // TypeScript - "@typescript-eslint/consistent-type-imports": "error", - "@typescript-eslint/no-use-before-define": "error", - "@typescript-eslint/no-shadow": "error", - "@typescript-eslint/prefer-optional-chain": "error", - "@typescript-eslint/no-unused-vars": "error", - "@typescript-eslint/semi": "error", - "@typescript-eslint/no-loss-of-precision": "error", + // typescript-eslint "@typescript-eslint/quotes": ["error", "double", { "avoidEscape": true }], - "@typescript-eslint/no-empty-function": "error", - "@typescript-eslint/no-empty-interface": "error", - "@typescript-eslint/no-inferrable-types": "error", - "@typescript-eslint/no-non-null-asserted-optional-chain": "error", - "@typescript-eslint/no-non-null-assertion": "error", - "@typescript-eslint/explicit-module-boundary-types": "error", - "@typescript-eslint/no-var-requires": "error", - "@typescript-eslint/no-explicit-any": "error", - "@typescript-eslint/ban-types": "error" + "@typescript-eslint/no-misused-promises": [ + "error", + { + "checksVoidReturn": { + "arguments": false + } + } + ] } } diff --git a/1-starter/src/commands/choices.ts b/1-starter/src/commands/choices.ts index b71d8c7..3b90c65 100644 --- a/1-starter/src/commands/choices.ts +++ b/1-starter/src/commands/choices.ts @@ -5,7 +5,7 @@ import { Discord, Slash, SlashChoice, SlashOption } from "discordx"; @Discord() export class Example { @Slash({ description: "choose" }) - choose( + async choose( @SlashChoice("Human", "Astronaut", "Dev") @SlashOption({ description: "What are you?", @@ -15,12 +15,12 @@ export class Example { }) what: string, interaction: CommandInteraction, - ): void { - interaction.reply(what); + ): Promise { + await interaction.reply(what); } @Slash({ description: "choose1" }) - choose1( + async choose1( @SlashChoice({ name: "are you okay?", value: "okay" }) @SlashChoice({ name: "are you good?", value: "good" }) @SlashOption({ @@ -31,7 +31,7 @@ export class Example { }) what: string, interaction: CommandInteraction, - ): void { - interaction.reply(what); + ): Promise { + await interaction.reply(what); } } diff --git a/1-starter/src/commands/context.ts b/1-starter/src/commands/context.ts index 8623fc3..0d75868 100644 --- a/1-starter/src/commands/context.ts +++ b/1-starter/src/commands/context.ts @@ -11,12 +11,16 @@ export class Example { name: "message context", type: ApplicationCommandType.Message, }) - messageHandler(interaction: MessageContextMenuCommandInteraction): void { - interaction.reply("I am user context handler"); + async messageHandler( + interaction: MessageContextMenuCommandInteraction, + ): Promise { + await interaction.reply("I am user context handler"); } @ContextMenu({ name: "user context", type: ApplicationCommandType.User }) - userHandler(interaction: UserContextMenuCommandInteraction): void { - interaction.reply("I am user context handler"); + async userHandler( + interaction: UserContextMenuCommandInteraction, + ): Promise { + await interaction.reply("I am user context handler"); } } diff --git a/1-starter/src/commands/menu.ts b/1-starter/src/commands/menu.ts index 61a5e7b..e60c5a6 100644 --- a/1-starter/src/commands/menu.ts +++ b/1-starter/src/commands/menu.ts @@ -19,7 +19,7 @@ export class Example { await interaction.deferReply(); // extract selected value by member - const roleValue = interaction.values?.[0]; + const roleValue = interaction.values[0]; // if value not found if (!roleValue) { @@ -50,7 +50,7 @@ export class Example { ); // send it - interaction.editReply({ + await interaction.editReply({ components: [buttonRow], content: "select your role!", }); diff --git a/1-starter/src/commands/simple command.ts b/1-starter/src/commands/simple command.ts index 6faacd1..6ae0c87 100644 --- a/1-starter/src/commands/simple command.ts +++ b/1-starter/src/commands/simple command.ts @@ -11,37 +11,38 @@ import { @Discord() export class Example { @SimpleCommand({ aliases: ["hi"] }) - hello(command: SimpleCommandMessage): void { - command.message.reply(`👋 ${command.message.member}`); + async hello(command: SimpleCommandMessage): Promise { + await command.message.reply(`👋 ${command.message.member?.toString()}`); } @SimpleCommand({ argSplitter: "+" }) - sum( + async sum( @SimpleCommandOption({ name: "num1", type: SimpleCommandOptionType.Number }) num1: number | undefined, @SimpleCommandOption({ name: "num2", type: SimpleCommandOptionType.Number }) num2: number | undefined, command: SimpleCommandMessage, - ): void { + ): Promise { if (!num1 || !num2) { - command.sendUsageSyntax(); + await command.sendUsageSyntax(); return; } - command.message.reply(`total = ${num1 + num2}`); + + await command.message.reply(`total = ${num1 + num2}`); } // make single handler for simple and slash command - likeIt(command: CommandInteraction | Message): void { - command.reply("I like it, Thanks"); + async likeIt(command: CommandInteraction | Message): Promise { + await command.reply("I like it, Thanks"); } @SimpleCommand({ name: "like-it" }) - simpleLikeIt(command: SimpleCommandMessage): void { - this.likeIt(command.message); + async simpleLikeIt(command: SimpleCommandMessage): Promise { + await this.likeIt(command.message); } @Slash({ description: "like-ite", name: "like-it" }) - slashLikeIt(command: CommandInteraction): void { - this.likeIt(command); + async slashLikeIt(command: CommandInteraction): Promise { + await this.likeIt(command); } } diff --git a/1-starter/src/commands/slash + button.ts b/1-starter/src/commands/slash + button.ts index eed198d..b5a268a 100644 --- a/1-starter/src/commands/slash + button.ts +++ b/1-starter/src/commands/slash + button.ts @@ -39,14 +39,14 @@ export class Example { helloBtn, ); - interaction.editReply({ + await interaction.editReply({ components: [row], - content: `${user}, Say hello to bot`, + content: `${user?.toString()}, Say hello to bot`, }); } @ButtonComponent({ id: "hello-btn" }) - helloBtn(interaction: ButtonInteraction): void { - interaction.reply(`👋 ${interaction.member}`); + async helloBtn(interaction: ButtonInteraction): Promise { + await interaction.reply(`👋 ${interaction.member?.toString()}`); } } diff --git a/1-starter/src/commands/slash group.ts b/1-starter/src/commands/slash group.ts index 62e11c1..46feb2c 100644 --- a/1-starter/src/commands/slash group.ts +++ b/1-starter/src/commands/slash group.ts @@ -8,7 +8,7 @@ import { Discord, Slash, SlashGroup, SlashOption } from "discordx"; export class GroupExample { @Slash({ description: "add" }) @SlashGroup("maths", "testing") - add( + async add( @SlashOption({ description: "x value", name: "x", @@ -24,13 +24,13 @@ export class GroupExample { }) y: number, interaction: CommandInteraction, - ): void { - interaction.reply(String(x + y)); + ): Promise { + await interaction.reply(String(x + y)); } @Slash({ description: "multiply" }) @SlashGroup("maths", "testing") - multiply( + async multiply( @SlashOption({ description: "x value", name: "x", @@ -46,13 +46,13 @@ export class GroupExample { }) y: number, interaction: CommandInteraction, - ): void { - interaction.reply(String(x * y)); + ): Promise { + await interaction.reply(String(x * y)); } @Slash({ description: "root" }) @SlashGroup("testing") - root( + async root( @SlashOption({ description: "text", name: "text", @@ -61,7 +61,7 @@ export class GroupExample { }) text: string, interaction: CommandInteraction, - ): void { - interaction.reply(text); + ): Promise { + await interaction.reply(text); } } diff --git a/1-starter/src/main.ts b/1-starter/src/main.ts index 7e20ed1..dcd4050 100644 --- a/1-starter/src/main.ts +++ b/1-starter/src/main.ts @@ -48,8 +48,8 @@ bot.on("interactionCreate", (interaction: Interaction) => { bot.executeInteraction(interaction); }); -bot.on("messageCreate", (message: Message) => { - bot.executeCommand(message); +bot.on("messageCreate", async (message: Message) => { + await bot.executeCommand(message); }); async function run() { @@ -69,4 +69,6 @@ async function run() { await bot.login(process.env.BOT_TOKEN); } -run(); +run().catch((err) => { + throw err; +}); diff --git a/2-starter-with-api/src/api/guilds.ts b/2-starter-with-api/src/api/guilds.ts index dc960d4..fe1cb1d 100644 --- a/2-starter-with-api/src/api/guilds.ts +++ b/2-starter-with-api/src/api/guilds.ts @@ -22,6 +22,8 @@ export class API { @Get() guilds(context: Context): void { - context.body = `${bot.guilds.cache.map((g) => `${g.id}: ${g.name}\n`)}`; + context.body = `${bot.guilds.cache + .map((g) => `${g.id}: ${g.name}`) + .join("\n")}`; } } diff --git a/2-starter-with-api/src/commands/choices.ts b/2-starter-with-api/src/commands/choices.ts index b71d8c7..3b90c65 100644 --- a/2-starter-with-api/src/commands/choices.ts +++ b/2-starter-with-api/src/commands/choices.ts @@ -5,7 +5,7 @@ import { Discord, Slash, SlashChoice, SlashOption } from "discordx"; @Discord() export class Example { @Slash({ description: "choose" }) - choose( + async choose( @SlashChoice("Human", "Astronaut", "Dev") @SlashOption({ description: "What are you?", @@ -15,12 +15,12 @@ export class Example { }) what: string, interaction: CommandInteraction, - ): void { - interaction.reply(what); + ): Promise { + await interaction.reply(what); } @Slash({ description: "choose1" }) - choose1( + async choose1( @SlashChoice({ name: "are you okay?", value: "okay" }) @SlashChoice({ name: "are you good?", value: "good" }) @SlashOption({ @@ -31,7 +31,7 @@ export class Example { }) what: string, interaction: CommandInteraction, - ): void { - interaction.reply(what); + ): Promise { + await interaction.reply(what); } } diff --git a/2-starter-with-api/src/commands/context.ts b/2-starter-with-api/src/commands/context.ts index 8623fc3..0d75868 100644 --- a/2-starter-with-api/src/commands/context.ts +++ b/2-starter-with-api/src/commands/context.ts @@ -11,12 +11,16 @@ export class Example { name: "message context", type: ApplicationCommandType.Message, }) - messageHandler(interaction: MessageContextMenuCommandInteraction): void { - interaction.reply("I am user context handler"); + async messageHandler( + interaction: MessageContextMenuCommandInteraction, + ): Promise { + await interaction.reply("I am user context handler"); } @ContextMenu({ name: "user context", type: ApplicationCommandType.User }) - userHandler(interaction: UserContextMenuCommandInteraction): void { - interaction.reply("I am user context handler"); + async userHandler( + interaction: UserContextMenuCommandInteraction, + ): Promise { + await interaction.reply("I am user context handler"); } } diff --git a/2-starter-with-api/src/commands/menu.ts b/2-starter-with-api/src/commands/menu.ts index 61a5e7b..e60c5a6 100644 --- a/2-starter-with-api/src/commands/menu.ts +++ b/2-starter-with-api/src/commands/menu.ts @@ -19,7 +19,7 @@ export class Example { await interaction.deferReply(); // extract selected value by member - const roleValue = interaction.values?.[0]; + const roleValue = interaction.values[0]; // if value not found if (!roleValue) { @@ -50,7 +50,7 @@ export class Example { ); // send it - interaction.editReply({ + await interaction.editReply({ components: [buttonRow], content: "select your role!", }); diff --git a/2-starter-with-api/src/commands/simple command.ts b/2-starter-with-api/src/commands/simple command.ts index 6faacd1..6ae0c87 100644 --- a/2-starter-with-api/src/commands/simple command.ts +++ b/2-starter-with-api/src/commands/simple command.ts @@ -11,37 +11,38 @@ import { @Discord() export class Example { @SimpleCommand({ aliases: ["hi"] }) - hello(command: SimpleCommandMessage): void { - command.message.reply(`👋 ${command.message.member}`); + async hello(command: SimpleCommandMessage): Promise { + await command.message.reply(`👋 ${command.message.member?.toString()}`); } @SimpleCommand({ argSplitter: "+" }) - sum( + async sum( @SimpleCommandOption({ name: "num1", type: SimpleCommandOptionType.Number }) num1: number | undefined, @SimpleCommandOption({ name: "num2", type: SimpleCommandOptionType.Number }) num2: number | undefined, command: SimpleCommandMessage, - ): void { + ): Promise { if (!num1 || !num2) { - command.sendUsageSyntax(); + await command.sendUsageSyntax(); return; } - command.message.reply(`total = ${num1 + num2}`); + + await command.message.reply(`total = ${num1 + num2}`); } // make single handler for simple and slash command - likeIt(command: CommandInteraction | Message): void { - command.reply("I like it, Thanks"); + async likeIt(command: CommandInteraction | Message): Promise { + await command.reply("I like it, Thanks"); } @SimpleCommand({ name: "like-it" }) - simpleLikeIt(command: SimpleCommandMessage): void { - this.likeIt(command.message); + async simpleLikeIt(command: SimpleCommandMessage): Promise { + await this.likeIt(command.message); } @Slash({ description: "like-ite", name: "like-it" }) - slashLikeIt(command: CommandInteraction): void { - this.likeIt(command); + async slashLikeIt(command: CommandInteraction): Promise { + await this.likeIt(command); } } diff --git a/2-starter-with-api/src/commands/slash + button.ts b/2-starter-with-api/src/commands/slash + button.ts index eed198d..b5a268a 100644 --- a/2-starter-with-api/src/commands/slash + button.ts +++ b/2-starter-with-api/src/commands/slash + button.ts @@ -39,14 +39,14 @@ export class Example { helloBtn, ); - interaction.editReply({ + await interaction.editReply({ components: [row], - content: `${user}, Say hello to bot`, + content: `${user?.toString()}, Say hello to bot`, }); } @ButtonComponent({ id: "hello-btn" }) - helloBtn(interaction: ButtonInteraction): void { - interaction.reply(`👋 ${interaction.member}`); + async helloBtn(interaction: ButtonInteraction): Promise { + await interaction.reply(`👋 ${interaction.member?.toString()}`); } } diff --git a/2-starter-with-api/src/commands/slash group.ts b/2-starter-with-api/src/commands/slash group.ts index 62e11c1..46feb2c 100644 --- a/2-starter-with-api/src/commands/slash group.ts +++ b/2-starter-with-api/src/commands/slash group.ts @@ -8,7 +8,7 @@ import { Discord, Slash, SlashGroup, SlashOption } from "discordx"; export class GroupExample { @Slash({ description: "add" }) @SlashGroup("maths", "testing") - add( + async add( @SlashOption({ description: "x value", name: "x", @@ -24,13 +24,13 @@ export class GroupExample { }) y: number, interaction: CommandInteraction, - ): void { - interaction.reply(String(x + y)); + ): Promise { + await interaction.reply(String(x + y)); } @Slash({ description: "multiply" }) @SlashGroup("maths", "testing") - multiply( + async multiply( @SlashOption({ description: "x value", name: "x", @@ -46,13 +46,13 @@ export class GroupExample { }) y: number, interaction: CommandInteraction, - ): void { - interaction.reply(String(x * y)); + ): Promise { + await interaction.reply(String(x * y)); } @Slash({ description: "root" }) @SlashGroup("testing") - root( + async root( @SlashOption({ description: "text", name: "text", @@ -61,7 +61,7 @@ export class GroupExample { }) text: string, interaction: CommandInteraction, - ): void { - interaction.reply(text); + ): Promise { + await interaction.reply(text); } } diff --git a/2-starter-with-api/src/commands/slashes.ts b/2-starter-with-api/src/commands/slashes.ts index 7efdac1..0dc79a0 100644 --- a/2-starter-with-api/src/commands/slashes.ts +++ b/2-starter-with-api/src/commands/slashes.ts @@ -12,7 +12,7 @@ export class SlashExample { }) async pages(interaction: CommandInteraction): Promise { const commands = MetadataStorage.instance.applicationCommands.map((cmd) => { - return { description: cmd?.description, name: cmd.name }; + return { description: cmd.description, name: cmd.name }; }); const pages = commands.map((cmd, i) => { diff --git a/2-starter-with-api/src/main.ts b/2-starter-with-api/src/main.ts index 4564925..a4090dc 100644 --- a/2-starter-with-api/src/main.ts +++ b/2-starter-with-api/src/main.ts @@ -49,8 +49,8 @@ bot.on("interactionCreate", (interaction: Interaction) => { bot.executeInteraction(interaction); }); -bot.on("messageCreate", (message: Message) => { - bot.executeCommand(message); +bot.on("messageCreate", async (message: Message) => { + await bot.executeCommand(message); }); async function run() { @@ -89,4 +89,6 @@ async function run() { // ************* rest api section: end ********** } -run(); +run().catch((err) => { + throw err; +}); diff --git a/3-blank/src/commands/slashes.ts b/3-blank/src/commands/slashes.ts index a23a5a8..61bfa32 100644 --- a/3-blank/src/commands/slashes.ts +++ b/3-blank/src/commands/slashes.ts @@ -4,7 +4,7 @@ import { Discord, Slash } from "discordx"; @Discord() export class Example { @Slash({ description: "ping" }) - ping(interaction: CommandInteraction): void { - interaction.reply("pong!"); + async ping(interaction: CommandInteraction): Promise { + await interaction.reply("pong!"); } } diff --git a/3-blank/src/main.ts b/3-blank/src/main.ts index cdc9973..b088a17 100644 --- a/3-blank/src/main.ts +++ b/3-blank/src/main.ts @@ -47,8 +47,8 @@ bot.on("interactionCreate", (interaction: Interaction) => { bot.executeInteraction(interaction); }); -bot.on("messageCreate", (message: Message) => { - bot.executeCommand(message); +bot.on("messageCreate", async (message: Message) => { + await bot.executeCommand(message); }); async function run() { @@ -68,4 +68,6 @@ async function run() { await bot.login(process.env.BOT_TOKEN); } -run(); +run().catch((err) => { + throw err; +}); diff --git a/4-music-player-ytdl/src/main.ts b/4-music-player-ytdl/src/main.ts index eb36b5b..b66655a 100644 --- a/4-music-player-ytdl/src/main.ts +++ b/4-music-player-ytdl/src/main.ts @@ -55,8 +55,8 @@ bot.on("interactionCreate", (interaction: Interaction) => { bot.executeInteraction(interaction); }); -bot.on("messageCreate", (message: Message) => { - bot.executeCommand(message); +bot.on("messageCreate", async (message: Message) => { + await bot.executeCommand(message); }); async function run() { @@ -76,4 +76,6 @@ async function run() { await bot.login(process.env.BOT_TOKEN); } -run(); +run().catch((err) => { + throw err; +}); diff --git a/5-music-player-lavalink/src/main.ts b/5-music-player-lavalink/src/main.ts index 304b89e..215634d 100644 --- a/5-music-player-lavalink/src/main.ts +++ b/5-music-player-lavalink/src/main.ts @@ -55,8 +55,8 @@ bot.on("interactionCreate", (interaction: Interaction) => { bot.executeInteraction(interaction); }); -bot.on("messageCreate", (message: Message) => { - bot.executeCommand(message); +bot.on("messageCreate", async (message: Message) => { + await bot.executeCommand(message); }); async function run() { @@ -76,4 +76,6 @@ async function run() { await bot.login(process.env.BOT_TOKEN); } -run(); +run().catch((err) => { + throw err; +}); diff --git a/6-koa-server/src/main.ts b/6-koa-server/src/main.ts index 2002d69..d444ed6 100644 --- a/6-koa-server/src/main.ts +++ b/6-koa-server/src/main.ts @@ -27,4 +27,6 @@ async function run() { // ************* rest api section: end ********** } -run(); +run().catch((err) => { + throw err; +}); diff --git a/7-hot-module-reload/src/bot.ts b/7-hot-module-reload/src/bot.ts index 2c6c18e..8eb75e3 100644 --- a/7-hot-module-reload/src/bot.ts +++ b/7-hot-module-reload/src/bot.ts @@ -47,6 +47,6 @@ bot.on("interactionCreate", (interaction: Interaction) => { bot.executeInteraction(interaction); }); -bot.on("messageCreate", (message: Message) => { - bot.executeCommand(message); +bot.on("messageCreate", async (message: Message) => { + await bot.executeCommand(message); }); diff --git a/7-hot-module-reload/src/commands/slashes.ts b/7-hot-module-reload/src/commands/slashes.ts index 8093a05..401a04b 100644 --- a/7-hot-module-reload/src/commands/slashes.ts +++ b/7-hot-module-reload/src/commands/slashes.ts @@ -4,7 +4,7 @@ import { Discord, Slash } from "discordx"; @Discord() export class Example { @Slash({ description: "ping" }) - ping(interaction: CommandInteraction): void { - interaction.reply("pong! hola!"); + async ping(interaction: CommandInteraction): Promise { + await interaction.reply("pong! hola!"); } } diff --git a/7-hot-module-reload/src/dev.ts b/7-hot-module-reload/src/dev.ts index 5580514..d92b0d3 100644 --- a/7-hot-module-reload/src/dev.ts +++ b/7-hot-module-reload/src/dev.ts @@ -80,4 +80,6 @@ async function run() { } } -run(); +run().catch((err) => { + throw err; +}); diff --git a/7-hot-module-reload/src/main.ts b/7-hot-module-reload/src/main.ts index 31dfb0f..f3f8df7 100644 --- a/7-hot-module-reload/src/main.ts +++ b/7-hot-module-reload/src/main.ts @@ -19,4 +19,6 @@ async function run() { await bot.login(process.env.BOT_TOKEN); } -run(); +run().catch((err) => { + throw err; +});