Skip to content

Commit 4f6f286

Browse files
committed
feat(discord): env-driven command registration scope, localized cooldowns and misc polish
1 parent e77a96d commit 4f6f286

18 files changed

Lines changed: 253 additions & 275 deletions

File tree

‎apps/discord/src/commands/slash/8ball.mts‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@ import { TracedCommand } from '../../structures/command.mjs'
44

55
export class EightBallCommand extends TracedCommand {
66
public override registerApplicationCommands(registry: Command.Registry) {
7-
registry.registerChatInputCommand(
8-
(builder) => {
9-
applyLocalizedBuilder(
10-
builder,
11-
'commands/names:8ball',
12-
'commands/descriptions:8ball',
13-
)
14-
},
15-
{
16-
guildIds: ['1034462346908794910'],
17-
},
18-
)
7+
registry.registerChatInputCommand((builder) => {
8+
applyLocalizedBuilder(
9+
builder,
10+
'commands/names:8ball',
11+
'commands/descriptions:8ball',
12+
)
13+
})
1914
}
2015

2116
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {

‎apps/discord/src/commands/slash/advice.mts‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@ import { fetchJson } from '../../utils/http.mjs'
99
})
1010
export class AdviceCommand extends TracedCommand {
1111
public override registerApplicationCommands(registry: Command.Registry) {
12-
registry.registerChatInputCommand(
13-
(builder) => {
14-
applyLocalizedBuilder(
15-
builder,
16-
'commands/names:advice',
17-
'commands/descriptions:advice',
18-
)
19-
},
20-
{
21-
guildIds: ['1034462346908794910'],
22-
},
23-
)
12+
registry.registerChatInputCommand((builder) => {
13+
applyLocalizedBuilder(
14+
builder,
15+
'commands/names:advice',
16+
'commands/descriptions:advice',
17+
)
18+
})
2419
}
2520

2621
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
22+
// adviceslip serves a cached slip for ~2 seconds; the query string
23+
// busts that so back-to-back calls differ.
2724
const { slip } = await fetchJson<{ slip: { advice: string } }>(
28-
'https://api.adviceslip.com/advice',
25+
`https://api.adviceslip.com/advice?t=${interaction.id}`,
2926
)
3027
return interaction.reply(slip.advice)
3128
}

‎apps/discord/src/commands/slash/booru.mts‎

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,34 @@ export class BooruCommand extends TracedSubcommand {
3333
.setMaxLength(BOORU_QUERY_MAX_LENGTH)
3434
.setAutocomplete(true)
3535

36-
registry.registerChatInputCommand(
37-
(builder) => {
38-
applyLocalizedBuilder(
39-
builder,
40-
'commands/names:booru',
41-
'commands/descriptions:booru',
36+
registry.registerChatInputCommand((builder) => {
37+
applyLocalizedBuilder(
38+
builder,
39+
'commands/names:booru',
40+
'commands/descriptions:booru',
41+
)
42+
.addSubcommand((sub) =>
43+
applyLocalizedBuilder(
44+
sub,
45+
'commands/names:booruE621',
46+
'commands/descriptions:booruE621',
47+
).addStringOption(queryOption),
4248
)
43-
.addSubcommand((sub) =>
44-
applyLocalizedBuilder(
45-
sub,
46-
'commands/names:booruE621',
47-
'commands/descriptions:booruE621',
48-
).addStringOption(queryOption),
49-
)
50-
.addSubcommand((sub) =>
51-
applyLocalizedBuilder(
52-
sub,
53-
'commands/names:booruRule34',
54-
'commands/descriptions:booruRule34',
55-
).addStringOption(queryOption),
56-
)
57-
.addSubcommand((sub) =>
58-
applyLocalizedBuilder(
59-
sub,
60-
'commands/names:booruDerpibooru',
61-
'commands/descriptions:booruDerpibooru',
62-
).addStringOption(queryOption),
63-
)
64-
},
65-
{
66-
guildIds: ['1034462346908794910'],
67-
},
68-
)
49+
.addSubcommand((sub) =>
50+
applyLocalizedBuilder(
51+
sub,
52+
'commands/names:booruRule34',
53+
'commands/descriptions:booruRule34',
54+
).addStringOption(queryOption),
55+
)
56+
.addSubcommand((sub) =>
57+
applyLocalizedBuilder(
58+
sub,
59+
'commands/names:booruDerpibooru',
60+
'commands/descriptions:booruDerpibooru',
61+
).addStringOption(queryOption),
62+
)
63+
})
6964
}
7065

7166
public override async autocompleteRun(

‎apps/discord/src/commands/slash/cat.mts‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,13 @@ import { buildCatMessage } from '../../utils/funMessages.mjs'
99
})
1010
export class CatCommand extends TracedCommand {
1111
public override registerApplicationCommands(registry: Command.Registry) {
12-
registry.registerChatInputCommand(
13-
(builder) => {
14-
applyLocalizedBuilder(
15-
builder,
16-
'commands/names:cat',
17-
'commands/descriptions:cat',
18-
)
19-
},
20-
{
21-
guildIds: ['1034462346908794910'],
22-
},
23-
)
12+
registry.registerChatInputCommand((builder) => {
13+
applyLocalizedBuilder(
14+
builder,
15+
'commands/names:cat',
16+
'commands/descriptions:cat',
17+
)
18+
})
2419
}
2520

2621
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {

‎apps/discord/src/commands/slash/dice.mts‎

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,31 @@ import { TracedCommand } from '../../structures/command.mjs'
44

55
export class DiceCommand extends TracedCommand {
66
public override registerApplicationCommands(registry: Command.Registry) {
7-
registry.registerChatInputCommand(
8-
(builder) => {
9-
applyLocalizedBuilder(
10-
builder,
11-
'commands/names:dice',
12-
'commands/descriptions:dice',
13-
)
14-
.addIntegerOption((option) =>
15-
applyLocalizedBuilder(
16-
option,
17-
'commands/names:diceOptionDice',
18-
'commands/descriptions:diceOptionDice',
19-
)
20-
.setMinValue(1)
21-
.setMaxValue(100),
7+
registry.registerChatInputCommand((builder) => {
8+
applyLocalizedBuilder(
9+
builder,
10+
'commands/names:dice',
11+
'commands/descriptions:dice',
12+
)
13+
.addIntegerOption((option) =>
14+
applyLocalizedBuilder(
15+
option,
16+
'commands/names:diceOptionDice',
17+
'commands/descriptions:diceOptionDice',
2218
)
23-
.addIntegerOption((option) =>
24-
applyLocalizedBuilder(
25-
option,
26-
'commands/names:diceOptionSides',
27-
'commands/descriptions:diceOptionSides',
28-
)
29-
.setMinValue(2)
30-
.setMaxValue(1_000),
19+
.setMinValue(1)
20+
.setMaxValue(100),
21+
)
22+
.addIntegerOption((option) =>
23+
applyLocalizedBuilder(
24+
option,
25+
'commands/names:diceOptionSides',
26+
'commands/descriptions:diceOptionSides',
3127
)
32-
},
33-
{
34-
guildIds: ['1034462346908794910'],
35-
},
36-
)
28+
.setMinValue(2)
29+
.setMaxValue(1_000),
30+
)
31+
})
3732
}
3833

3934
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {

‎apps/discord/src/commands/slash/dog.mts‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,13 @@ import { buildDogMessage } from '../../utils/funMessages.mjs'
99
})
1010
export class DogCommand extends TracedCommand {
1111
public override registerApplicationCommands(registry: Command.Registry) {
12-
registry.registerChatInputCommand(
13-
(builder) => {
14-
applyLocalizedBuilder(
15-
builder,
16-
'commands/names:dog',
17-
'commands/descriptions:dog',
18-
)
19-
},
20-
{
21-
guildIds: ['1034462346908794910'],
22-
},
23-
)
12+
registry.registerChatInputCommand((builder) => {
13+
applyLocalizedBuilder(
14+
builder,
15+
'commands/names:dog',
16+
'commands/descriptions:dog',
17+
)
18+
})
2419
}
2520

2621
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {

‎apps/discord/src/commands/slash/info.mts‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,13 @@ const { version } = createRequire(import.meta.url)('../../../package.json') as {
1616

1717
export class InfoCommand extends TracedCommand {
1818
public override registerApplicationCommands(registry: Command.Registry) {
19-
registry.registerChatInputCommand(
20-
(builder) => {
21-
applyLocalizedBuilder(
22-
builder,
23-
'commands/names:info',
24-
'commands/descriptions:info',
25-
)
26-
},
27-
{
28-
guildIds: ['1034462346908794910'],
29-
},
30-
)
19+
registry.registerChatInputCommand((builder) => {
20+
applyLocalizedBuilder(
21+
builder,
22+
'commands/names:info',
23+
'commands/descriptions:info',
24+
)
25+
})
3126
}
3227

3328
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {

‎apps/discord/src/commands/slash/inspire.mts‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,13 @@ import { buildInspireMessage } from '../../utils/funMessages.mjs'
99
})
1010
export class InspireCommand extends TracedCommand {
1111
public override registerApplicationCommands(registry: Command.Registry) {
12-
registry.registerChatInputCommand(
13-
(builder) => {
14-
applyLocalizedBuilder(
15-
builder,
16-
'commands/names:inspire',
17-
'commands/descriptions:inspire',
18-
)
19-
},
20-
{
21-
guildIds: ['1034462346908794910'],
22-
},
23-
)
12+
registry.registerChatInputCommand((builder) => {
13+
applyLocalizedBuilder(
14+
builder,
15+
'commands/names:inspire',
16+
'commands/descriptions:inspire',
17+
)
18+
})
2419
}
2520

2621
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {

‎apps/discord/src/commands/slash/invite.mts‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@ import { TracedCommand } from '../../structures/command.mjs'
55

66
export class InviteCommand extends TracedCommand {
77
public override registerApplicationCommands(registry: Command.Registry) {
8-
registry.registerChatInputCommand(
9-
(builder) => {
10-
applyLocalizedBuilder(
11-
builder,
12-
'commands/names:invite',
13-
'commands/descriptions:invite',
14-
)
15-
},
16-
{
17-
guildIds: ['1034462346908794910'],
18-
},
19-
)
8+
registry.registerChatInputCommand((builder) => {
9+
applyLocalizedBuilder(
10+
builder,
11+
'commands/names:invite',
12+
'commands/descriptions:invite',
13+
)
14+
})
2015
}
2116

2217
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {

‎apps/discord/src/commands/slash/ping.mts‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@ import { TracedCommand } from '../../structures/command.mjs'
55

66
export class PingCommand extends TracedCommand {
77
public override registerApplicationCommands(registry: Command.Registry) {
8-
registry.registerChatInputCommand(
9-
(builder) => {
10-
applyLocalizedBuilder(
11-
builder,
12-
'commands/names:ping',
13-
'commands/descriptions:ping',
14-
)
15-
},
16-
{
17-
guildIds: ['1034462346908794910'],
18-
},
19-
)
8+
registry.registerChatInputCommand((builder) => {
9+
applyLocalizedBuilder(
10+
builder,
11+
'commands/names:ping',
12+
'commands/descriptions:ping',
13+
)
14+
})
2015
}
2116

2217
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {

0 commit comments

Comments
 (0)