Skip to content

Commit

Permalink
feat(utility): add spoonfeed commands
Browse files Browse the repository at this point in the history
  • Loading branch information
D4isDAVID committed Sep 16, 2024
1 parent ba86f7c commit 6178f4d
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/components/utility/commands/spoonfeed/chat-input-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
ApplicationCommandOptionType,
ApplicationCommandType,
} from '@discordjs/core';
import { spoonfeedMessage } from './message.js';
import { ChatInputCommand } from '/components/types.js';
import { mapChatInputOptionValues } from '/utils/interactions.js';

export const spoonfeedCommand = {
data: {
type: ApplicationCommandType.ChatInput,
name: 'spoonfeed',
description: 'Send information about how to learn',
options: [
{
type: ApplicationCommandOptionType.Mentionable,
name: 'mention',
description: 'An optional user to mention',
},
],
},
async execute({ api, data: interaction }) {
const { mention } = mapChatInputOptionValues(interaction.data) as {
mention: string | undefined;
};

await api.interactions.reply(interaction.id, interaction.token, {
content: spoonfeedMessage(mention),
});
},
} satisfies ChatInputCommand;
33 changes: 33 additions & 0 deletions src/components/utility/commands/spoonfeed/message-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ApplicationCommandType, MessageFlags } from '@discordjs/core';
import { messageLink } from '@discordjs/formatters';
import { spoonfeedMessage } from './message.js';
import { MessageCommand } from '/components/types.js';

export const spoonfeedMessageCommand = {
data: {
type: ApplicationCommandType.Message,
name: 'How to Learn',
},
guildSpecific: true,
async execute({ api, data: interaction }) {
await api.interactions.defer(interaction.id, interaction.token, {
flags: MessageFlags.Ephemeral,
});

const message = await api.channels.createMessage(
interaction.channel.id,
{
content: spoonfeedMessage(),
message_reference: { message_id: interaction.data.target_id },
},
);

await api.interactions.editReply(
interaction.application_id,
interaction.token,
{
content: messageLink(message.channel_id, message.id),
},
);
},
} satisfies MessageCommand;
35 changes: 35 additions & 0 deletions src/components/utility/commands/spoonfeed/message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Snowflake } from '@discordjs/core';
import {
bold,
hideLinkEmbed,
hyperlink,
unorderedList,
userMention,
} from '@discordjs/formatters';

export function spoonfeedMessage(userId?: Snowflake) {
const content = [
bold('Information will not be spoonfed to you.'),
'You are expected to be able to learn and understand programming concepts.',
'Understand that even if you are "new to this dev stuff", we all started off with no knowledge in the space.',
'Just as we take our time and learn, you are advised to do the same. Here are a few links to help you start:',
unorderedList([
hyperlink('Lua Docs', hideLinkEmbed('https://lua.org/docs.html')),
hyperlink(
'Programming in Lua e-book',
hideLinkEmbed('https://lua.org/pil/contents.html'),
),
hyperlink(
'FiveM Docs',
hideLinkEmbed('https://docs.fivem.net/docs/'),
),
hyperlink(
'Effective FiveM Lua',
hideLinkEmbed('https://manason.github.io/effective-fivem-lua/'),
),
]),
];
if (userId) content.unshift(userMention(userId));

return content.join('\n');
}
4 changes: 4 additions & 0 deletions src/components/utility/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { Component } from '../types.js';
import { guildCommand } from './commands/guild.js';
import { plshelpCommand } from './commands/plshelp/chat-input-command.js';
import { plshelpMessageCommand } from './commands/plshelp/message-command.js';
import { spoonfeedCommand } from './commands/spoonfeed/chat-input-command.js';
import { spoonfeedMessageCommand } from './commands/spoonfeed/message-command.js';

export default {
commands: [
guildCommand,
plshelpCommand,
plshelpMessageCommand,
spoonfeedCommand,
spoonfeedMessageCommand,
],
} satisfies Component;

0 comments on commit 6178f4d

Please sign in to comment.