feat: add tag mentions and deletions

This commit is contained in:
Ryan Cao 2022-09-12 15:01:26 +08:00
parent 6673a8a36c
commit ff5882730d
No known key found for this signature in database
3 changed files with 38 additions and 2 deletions

View file

@ -27,6 +27,12 @@ export const reuploadCommands = async () => {
.setDescription('The tag name') .setDescription('The tag name')
.setRequired(true) .setRequired(true)
.addChoices(...tags.map((b) => ({ name: b.name, value: b.name }))) .addChoices(...tags.map((b) => ({ name: b.name, value: b.name })))
)
.addUserOption((option) =>
option
.setName('user')
.setDescription('The user to mention')
.setRequired(false)
), ),
new SlashCommandBuilder() new SlashCommandBuilder()
.setName('modrinth') .setName('modrinth')

View file

@ -10,6 +10,8 @@ export const tagsCommand = async (
) => { ) => {
const tags = await getTags(); const tags = await getTags();
const tagName = i.options.getString('name', true); const tagName = i.options.getString('name', true);
const mention = i.options.getUser('user', false);
const tag = tags.find( const tag = tags.find(
(tag) => tag.name === tagName || tag.aliases?.includes(tagName) (tag) => tag.name === tagName || tag.aliases?.includes(tagName)
); );
@ -23,7 +25,9 @@ export const tagsCommand = async (
} }
await i.reply({ await i.reply({
content: tag.text ? `**${tag.name}**\n\n` + tag.text : tag.text, content:
(mention ? `<@${mention.id}> ` : '') +
(tag.text ? `**${tag.name}**\n\n` + tag.text : ''),
embeds: tag.embed embeds: tag.embed
? [ ? [
new EmbedBuilder(tag.embed).setFooter({ new EmbedBuilder(tag.embed).setFooter({

View file

@ -1,4 +1,10 @@
import { Client, GatewayIntentBits, Partials, OAuth2Scopes } from 'discord.js'; import {
Client,
GatewayIntentBits,
Partials,
OAuth2Scopes,
InteractionType,
} from 'discord.js';
import { reuploadCommands } from './_reupload'; import { reuploadCommands } from './_reupload';
import * as BuildConfig from './constants'; import * as BuildConfig from './constants';
@ -125,6 +131,26 @@ client.on('interactionCreate', async (interaction) => {
} }
}); });
client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.partial) {
try {
await reaction.fetch();
} catch (error) {
console.error('Something went wrong when fetching the message:', error);
return;
}
}
if (
reaction.message.interaction &&
reaction.message.interaction?.type === InteractionType.ApplicationCommand &&
reaction.message.interaction?.user === user &&
reaction.emoji.name === '❌'
) {
await reaction.message.delete();
}
});
reuploadCommands() reuploadCommands()
.then(() => { .then(() => {
client.login(process.env.DISCORD_TOKEN); client.login(process.env.DISCORD_TOKEN);