From 6178f4d654e0914c71b089b627e93bc9d729cd4e Mon Sep 17 00:00:00 2001 From: David Malchin Date: Mon, 16 Sep 2024 13:59:13 +0300 Subject: [PATCH] feat(utility): add `spoonfeed` commands --- .../commands/spoonfeed/chat-input-command.ts | 31 ++++++++++++++++ .../commands/spoonfeed/message-command.ts | 33 +++++++++++++++++ .../utility/commands/spoonfeed/message.ts | 35 +++++++++++++++++++ src/components/utility/index.ts | 4 +++ 4 files changed, 103 insertions(+) create mode 100644 src/components/utility/commands/spoonfeed/chat-input-command.ts create mode 100644 src/components/utility/commands/spoonfeed/message-command.ts create mode 100644 src/components/utility/commands/spoonfeed/message.ts diff --git a/src/components/utility/commands/spoonfeed/chat-input-command.ts b/src/components/utility/commands/spoonfeed/chat-input-command.ts new file mode 100644 index 0000000..667bdf5 --- /dev/null +++ b/src/components/utility/commands/spoonfeed/chat-input-command.ts @@ -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; diff --git a/src/components/utility/commands/spoonfeed/message-command.ts b/src/components/utility/commands/spoonfeed/message-command.ts new file mode 100644 index 0000000..966ab53 --- /dev/null +++ b/src/components/utility/commands/spoonfeed/message-command.ts @@ -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; diff --git a/src/components/utility/commands/spoonfeed/message.ts b/src/components/utility/commands/spoonfeed/message.ts new file mode 100644 index 0000000..ee79447 --- /dev/null +++ b/src/components/utility/commands/spoonfeed/message.ts @@ -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'); +} diff --git a/src/components/utility/index.ts b/src/components/utility/index.ts index 8047359..4c90c18 100644 --- a/src/components/utility/index.ts +++ b/src/components/utility/index.ts @@ -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;