Skip to content

Commit e3cf467

Browse files
committed
Add a /docs command for linking to documentation pages
1 parent 806685d commit e3cf467

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

src/interactions/commands/command-manager.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { saySlashCommand } from './handlers/say-slash';
1818
import { sendToQuestionsContextMenuCommand } from './handlers/send-to-questions-context';
1919
import { sendToIssuesContextMenuCommand } from './handlers/send-to-issues-context';
2020
import { randomFeaturedSlashCommand } from './handlers/random-featured-slash';
21+
import { docsSlashCommand } from './handlers/docs/docs-slash';
2122

2223
class CommandManager implements IInteractionManager {
2324
private handlers: ICommandHandler[] = [];
@@ -38,6 +39,7 @@ class CommandManager implements IInteractionManager {
3839
sendToIssuesContextMenuCommand,
3940
sendToQuestionsContextMenuCommand,
4041
randomFeaturedSlashCommand,
42+
docsSlashCommand,
4143
];
4244

4345
for (const handler of commandsToRegister) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const documentationPages: Array<{
2+
name: string;
3+
url: string;
4+
}> = [
5+
{
6+
name: 'Custom Scripts',
7+
url: 'https://docs.firebot.app/v5/dev/scripts',
8+
},
9+
{
10+
name: 'Dev Environment Setup',
11+
url: 'https://docs.firebot.app/v5/dev/environment-setup',
12+
},
13+
];
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { SlashCommandBuilder } from 'discord.js';
2+
import { CommandType, ICommandHandler } from '../../command-handler.interface';
3+
import { documentationPages } from './doc-pages';
4+
5+
const config = new SlashCommandBuilder()
6+
.setName('docs')
7+
.setDescription('Link to Firebot Docs')
8+
.addStringOption((option) =>
9+
option
10+
.setName('page')
11+
.setDescription('The page to link to')
12+
.setRequired(false)
13+
.setChoices(
14+
documentationPages.map((p) => ({
15+
name: p.name,
16+
value: p.name,
17+
}))
18+
)
19+
);
20+
21+
export const docsSlashCommand: ICommandHandler = {
22+
type: CommandType.SlashCommand,
23+
config,
24+
async onTrigger(interaction) {
25+
await interaction.deferReply();
26+
27+
const pageName = interaction.options.getString('page');
28+
29+
if (!pageName) {
30+
await interaction.editReply({
31+
content:
32+
'Firebot documentation is available at https://docs.firebot.app',
33+
});
34+
return;
35+
}
36+
37+
const page = documentationPages.find((p) => p.name === pageName);
38+
39+
await interaction.editReply({
40+
content: `Check out the ${page.name} documentation here: ${page.url}`,
41+
});
42+
},
43+
};

0 commit comments

Comments
 (0)