Skip to content

Commit

Permalink
remove safeReply
Browse files Browse the repository at this point in the history
  • Loading branch information
Dougley committed Feb 7, 2022
1 parent 2b91159 commit 644ce51
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 33 deletions.
22 changes: 0 additions & 22 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,3 @@ export default class GreetCommand extends BaseSlashCommand {
// ...
}
```

### Sending messages

When sending messages, send them using `<BaseInteractionCommand>.safeReply()`. This will disable all mentions in the message making it safe to directly pass user-input. Calling `<InteractionContext>.editOrRespond()` or other methods that return text directly is discouraged.

```ts
// ⚠ avoid
export default class GreetCommand extends BaseSlashCommand {
async run (context: Interaction.InteractionContext): Promise<void> {
await context.awaitOrRespond('Hello world!')
}
}
```

```ts
// ✓ prefered
export default class GreetCommand extends BaseSlashCommand {
async run (context: Interaction.InteractionContext): Promise<void> {
await this.safeReply(context, 'Hello world!')
}
}
```
2 changes: 1 addition & 1 deletion docs/fundamentals/commands/slash-commands/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/interactions/slash-commands/8ball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default class EightBallCommand extends BaseSlashCommand {

async run (context: Interaction.InteractionContext): Promise<void> {
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)}`) }))
}
}
2 changes: 1 addition & 1 deletion src/interactions/slash-commands/advice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export default class AdviceCommand extends BaseSlashCommand {

async run (context: Interaction.InteractionContext): Promise<void> {
const advice = await (await fetch('https://api.adviceslip.com/advice')).json()
await this.safeReply(context, advice.slip.advice)
await context.editOrRespond(advice.slip.advice)
}
}
2 changes: 1 addition & 1 deletion src/interactions/slash-commands/dice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
}
2 changes: 1 addition & 1 deletion src/interactions/slash-commands/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
2 changes: 1 addition & 1 deletion src/interactions/slash-commands/inspire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/interactions/slash-commands/invite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class InviteCommand extends BaseSlashCommand {

async run (context: Interaction.InteractionContext): Promise<void> {
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
}),
Expand All @@ -21,23 +21,23 @@ 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}`
}),
flags: MessageFlags.EPHEMERAL
})
} else {
const owner = context.client.application!.owner
await this.safeReply(context, {
await context.editOrRespond( {
content: translate('commands.invite.private', {
owner: `${owner.username}#${owner.discriminator}`
}),
flags: MessageFlags.EPHEMERAL
})
}
} 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`
}),
Expand Down
2 changes: 1 addition & 1 deletion src/interactions/slash-commands/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default class PingCommand extends BaseSlashCommand {

async run (context: Interaction.InteractionContext): Promise<void> {
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)`)
}
}

0 comments on commit 644ce51

Please sign in to comment.