Skip to content

Commit

Permalink
feat: utility component
Browse files Browse the repository at this point in the history
  • Loading branch information
D4isDAVID committed Sep 15, 2024
1 parent d1083aa commit 07a3005
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
- [`core/`](./core/) - core features
- [`ping/`](./ping/) - ping command
- [`qbox/`](./qbox/) - qbox-specific features
- [`utility/`](./utility/) - utility commands
- [`loader.ts`](./loader.ts) - code to load components
- [`types.d.ts`](./types.d.ts) - typings used by components
54 changes: 54 additions & 0 deletions src/components/utility/commands/guild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {
APIInteractionResponseCallbackData,
ApplicationCommandOptionType,
ApplicationCommandType,
MessageFlags,
} from '@discordjs/core';
import { ChatInputCommand } from '/components/types.js';
import { mapChatInputOptionValues } from '/utils/interactions.js';

const invites: Record<string, string> = {
ox: 'https://discord.overextended.dev/',
'project-error': 'https://discord.gg/uy5N7jT5aJ',
txAdmin: 'https://discord.gg/yWxjt9zPWR',
cfx: 'https://discord.gg/fivem',
};

export const guildCommand = {
data: {
type: ApplicationCommandType.ChatInput,
name: 'guild',
description: 'Send an invite link to a server',
options: [
{
type: ApplicationCommandOptionType.String,
name: 'name',
description: 'The server name',
required: true,
choices: [
{ name: 'Overextended', value: 'ox' },
{ name: 'Project Error', value: 'project-error' },
{ name: 'txAdmin', value: 'txAdmin' },
{ name: 'Cfx.re', value: 'cfx' },
],
},
],
},
async execute({ api, data: interaction }) {
const { name: guild } = mapChatInputOptionValues(interaction.data) as {
name: string;
};

const invite = invites[guild];
const message: APIInteractionResponseCallbackData = {
content: invite ?? 'Unknown guild selected.',
};
if (invite) message.flags = MessageFlags.Ephemeral;

await api.interactions.reply(
interaction.id,
interaction.token,
message,
);
},
} satisfies ChatInputCommand;
6 changes: 6 additions & 0 deletions src/components/utility/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Component } from '../types.js';
import { guildCommand } from './commands/guild.js';

export default {
commands: [guildCommand],
} satisfies Component;

0 comments on commit 07a3005

Please sign in to comment.