Skip to content

Commit 36d3dee

Browse files
committed
feat: fix typos & move things around for test bot
1 parent bcffdd6 commit 36d3dee

File tree

5 files changed

+54
-56
lines changed

5 files changed

+54
-56
lines changed

apps/discord-bot/src/commands/slash/plugin.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,9 @@
1-
import { SparkCommand, CommandType, SlashCommandPlugin } from '@spark.ts/handler';
2-
3-
function mapUsers(ids: string[]) {
4-
const userMention = (s: string) => `<@!${s}>`;
5-
return ids.map((id) => `\` - \` ${userMention(id)}`).join('\n');
6-
}
7-
8-
function testPlugin(ownerIds: string[]): SlashCommandPlugin {
9-
return {
10-
description: 'Only allows the owner to run the command.',
11-
async run({ interaction, controller }) {
12-
if (ownerIds.includes(interaction.user.id)) {
13-
return controller.next();
14-
}
15-
16-
await interaction.reply({
17-
content: `Only these people can run this!\n${mapUsers(ownerIds)}`,
18-
ephemeral: true,
19-
});
20-
21-
return controller.stop();
22-
},
23-
};
24-
}
1+
import { SparkCommand, CommandType } from '@spark.ts/handler';
2+
import { ownerOnlySlash } from '../../plugins/ownerOnly';
253

264
export default new SparkCommand({
275
type: CommandType.Slash,
28-
plugins: [testPlugin(['283312847478325251'])],
6+
plugins: [ownerOnlySlash(['283312847478325251'])],
297
run({ interaction }) {
308
interaction.reply('You are allowed to use this command!');
319
},

apps/discord-bot/src/commands/test/plugin.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.
File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { SparkCommand, CommandType } from '@spark.ts/handler';
2+
import { ownerOnlyText } from '../../plugins/ownerOnly';
3+
4+
export default new SparkCommand({
5+
type: CommandType.Text,
6+
plugins: [ownerOnlyText(['283312847478325251'])],
7+
run({ message }) {
8+
message.reply('You are allowed to use this command!');
9+
},
10+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { SlashCommandPlugin, TextCommandPlugin } from '@spark.ts/handler';
2+
3+
function mapUsers(ids: string[]) {
4+
const userMention = (s: string) => `<@!${s}>`;
5+
return ids.map((id) => `\` - \` ${userMention(id)}`).join('\n');
6+
}
7+
8+
export function ownerOnlySlash(ownerIds: string[]): SlashCommandPlugin {
9+
return {
10+
description: 'Only allows the owner to run the command.',
11+
async run({ interaction, controller }) {
12+
if (ownerIds.includes(interaction.user.id)) {
13+
return controller.next();
14+
}
15+
16+
await interaction.reply({
17+
content: `Only these people can run this!\n${mapUsers(ownerIds)}`,
18+
ephemeral: true,
19+
});
20+
21+
return controller.stop();
22+
},
23+
};
24+
}
25+
26+
export function ownerOnlyText(ownerIds: string[]): TextCommandPlugin {
27+
return {
28+
description: 'Only allows the owner to run the command.',
29+
async run({ message, controller }) {
30+
if (ownerIds.includes(message.author.id)) {
31+
return controller.next();
32+
}
33+
34+
await message.reply({
35+
content: `Only these people can run this!\n${mapUsers(ownerIds)}`,
36+
});
37+
38+
return controller.stop();
39+
},
40+
};
41+
}

0 commit comments

Comments
 (0)