From 644ce51455ad5e09e2a24136bd92da249574fde3 Mon Sep 17 00:00:00 2001 From: Remco Date: Mon, 7 Feb 2022 20:55:00 +0100 Subject: [PATCH] remove safeReply --- .github/CONTRIBUTING.md | 22 ------------------- .../commands/slash-commands/options.md | 2 +- src/interactions/slash-commands/8ball.ts | 2 +- src/interactions/slash-commands/advice.ts | 2 +- src/interactions/slash-commands/dice.ts | 2 +- src/interactions/slash-commands/info.ts | 2 +- src/interactions/slash-commands/inspire.ts | 2 +- src/interactions/slash-commands/invite.ts | 8 +++---- src/interactions/slash-commands/ping.ts | 2 +- 9 files changed, 11 insertions(+), 33 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index f1dcef677..55a52cdaf 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -114,25 +114,3 @@ export default class GreetCommand extends BaseSlashCommand { // ... } ``` - -### Sending messages - -When sending messages, send them using `.safeReply()`. This will disable all mentions in the message making it safe to directly pass user-input. Calling `.editOrRespond()` or other methods that return text directly is discouraged. - -```ts -// ⚠ avoid -export default class GreetCommand extends BaseSlashCommand { - async run (context: Interaction.InteractionContext): Promise { - await context.awaitOrRespond('Hello world!') - } -} -``` - -```ts -// ✓ prefered -export default class GreetCommand extends BaseSlashCommand { - async run (context: Interaction.InteractionContext): Promise { - await this.safeReply(context, 'Hello world!') - } -} -``` diff --git a/docs/fundamentals/commands/slash-commands/options.md b/docs/fundamentals/commands/slash-commands/options.md index ac7be5e72..2786f52c2 100644 --- a/docs/fundamentals/commands/slash-commands/options.md +++ b/docs/fundamentals/commands/slash-commands/options.md @@ -54,7 +54,7 @@ export default class DiceCommand extends BaseSlashCommand { total += Math.floor(Math.random() * diceSides) + 1 } - await this.safeReply(context, `${context.user.username} rolled ${diceCount}d${diceSides} and got ${total}`) + await context.editOrRespond(`${context.user.username} rolled ${diceCount}d${diceSides} and got ${total}`) } } diff --git a/src/interactions/slash-commands/8ball.ts b/src/interactions/slash-commands/8ball.ts index 19c1f7e77..92e461693 100644 --- a/src/interactions/slash-commands/8ball.ts +++ b/src/interactions/slash-commands/8ball.ts @@ -9,6 +9,6 @@ export default class EightBallCommand extends BaseSlashCommand { async run (context: Interaction.InteractionContext): Promise { const length = traverse('commands.8ball.choices.length') - await this.safeReply(context, translate('commands.8ball.prefix', { response: translate(`commands.8ball.choices.${Math.floor(Math.random() * length)}`) })) + await context.editOrRespond(translate('commands.8ball.prefix', { response: translate(`commands.8ball.choices.${Math.floor(Math.random() * length)}`) })) } } diff --git a/src/interactions/slash-commands/advice.ts b/src/interactions/slash-commands/advice.ts index 674fb1234..7c2945b79 100644 --- a/src/interactions/slash-commands/advice.ts +++ b/src/interactions/slash-commands/advice.ts @@ -9,6 +9,6 @@ export default class AdviceCommand extends BaseSlashCommand { async run (context: Interaction.InteractionContext): Promise { const advice = await (await fetch('https://api.adviceslip.com/advice')).json() - await this.safeReply(context, advice.slip.advice) + await context.editOrRespond(advice.slip.advice) } } diff --git a/src/interactions/slash-commands/dice.ts b/src/interactions/slash-commands/dice.ts index 7e46e7d48..5966b0b7b 100644 --- a/src/interactions/slash-commands/dice.ts +++ b/src/interactions/slash-commands/dice.ts @@ -41,6 +41,6 @@ export default class DiceCommand extends BaseSlashCommand { total += Math.floor(Math.random() * diceSides) + 1 } - await this.safeReply(context, `${context.user.username} rolled ${diceCount}d${diceSides} and got ${total}`) + await context.editOrRespond(`${context.user.username} rolled ${diceCount}d${diceSides} and got ${total}`) } } diff --git a/src/interactions/slash-commands/info.ts b/src/interactions/slash-commands/info.ts index 405b9cc40..b3f1059df 100644 --- a/src/interactions/slash-commands/info.ts +++ b/src/interactions/slash-commands/info.ts @@ -36,7 +36,7 @@ export default class InfoCommand extends BaseSlashCommand { .setColor(0x00AE86) .setThumbnail(context.client.user!.avatarUrl) .setFooter(`${context.client.user!.username} - ${translate('commands.info.poweredBy')}`) - await this.safeReply(context, { + await context.editOrRespond( { embed, flags: MessageFlags.EPHEMERAL }) diff --git a/src/interactions/slash-commands/inspire.ts b/src/interactions/slash-commands/inspire.ts index ea9e16dd9..a1da607ce 100644 --- a/src/interactions/slash-commands/inspire.ts +++ b/src/interactions/slash-commands/inspire.ts @@ -14,7 +14,7 @@ export default class InspirobotCommand extends BaseSlashCommand { const url = await (await fetch('https://inspirobot.me/api?generate=true')).text() try { const ctx = new URL(url) - await this.safeReply(context, { + await context.editOrRespond( { embed: { image: { url: ctx.href diff --git a/src/interactions/slash-commands/invite.ts b/src/interactions/slash-commands/invite.ts index fddd0ac6d..4f80c95ac 100644 --- a/src/interactions/slash-commands/invite.ts +++ b/src/interactions/slash-commands/invite.ts @@ -10,7 +10,7 @@ export default class InviteCommand extends BaseSlashCommand { async run (context: Interaction.InteractionContext): Promise { if (process.env.WILDBEAST_INVITE_OVERRIDE !== undefined) { - await this.safeReply(context, { + await context.editOrRespond( { content: translate('commands.invite.done', { invite: process.env.WILDBEAST_INVITE_OVERRIDE }), @@ -21,7 +21,7 @@ export default class InviteCommand extends BaseSlashCommand { if (!context.client.application!.botPublic) { if (context.client.application!.team !== undefined) { const teamowner = context.client.application!.team.owner! - await this.safeReply(context, { + await context.editOrRespond( { content: translate('commands.invite.private', { owner: `${teamowner.username}#${teamowner.discriminator}` }), @@ -29,7 +29,7 @@ export default class InviteCommand extends BaseSlashCommand { }) } else { const owner = context.client.application!.owner - await this.safeReply(context, { + await context.editOrRespond( { content: translate('commands.invite.private', { owner: `${owner.username}#${owner.discriminator}` }), @@ -37,7 +37,7 @@ export default class InviteCommand extends BaseSlashCommand { }) } } else { - await this.safeReply(context, { + await context.editOrRespond( { content: translate('commands.invite.done', { invite: `https://discordapp.com/oauth2/authorize?&client_id=${context.client.application!.id}&scope=bot%20applications.commands` }), diff --git a/src/interactions/slash-commands/ping.ts b/src/interactions/slash-commands/ping.ts index d8e081a0d..4e18117e3 100644 --- a/src/interactions/slash-commands/ping.ts +++ b/src/interactions/slash-commands/ping.ts @@ -8,6 +8,6 @@ export default class PingCommand extends BaseSlashCommand { async run (context: Interaction.InteractionContext): Promise { const { gateway, rest } = await context.client.ping() - return await this.safeReply(context, `Pong! (gateway: ${gateway}ms) (rest: ${rest}ms)`) + await context.editOrRespond(`Pong! (gateway: ${gateway}ms) (rest: ${rest}ms)`) } }