Allow notes to use IDs directly

This commit is contained in:
Tarrgon
2025-06-21 13:15:24 -04:00
parent 0a7f7f2fa7
commit 7a4a75c2cb
2 changed files with 20 additions and 12 deletions
+19 -11
View File
@@ -1,8 +1,10 @@
import { ApplicationCommandOptionType, ApplicationIntegrationType, AutocompleteInteraction, ChatInputCommandInteraction, Client, GuildBasedChannel, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js'; import { ApplicationCommandOptionType, ApplicationIntegrationType, AutocompleteInteraction, ChatInputCommandInteraction, Client, GuildBasedChannel, InteractionContextType, MessageFlags, MessageMentions, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
import { Database } from '../shared/Database'; import { Database } from '../shared/Database';
import { channelIsInStaffCategory, deferInteraction, logCustomEvent } from '../utils'; import { channelIsInStaffCategory, deferInteraction, logCustomEvent } from '../utils';
import { getNoteMessage } from '../utils/note-utils'; import { getNoteMessage } from '../utils/note-utils';
const mentionRegex = new RegExp(MessageMentions.UsersPattern);
export default { export default {
name: 'notes', name: 'notes',
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@@ -18,7 +20,7 @@ export default {
.addUserOption(option => .addUserOption(option =>
option option
.setName('user') .setName('user')
.setDescription('The user to add a note to.') .setDescription('The discord user mention, or ID, to add a note to.')
.setRequired(true) .setRequired(true)
) )
.addStringOption(option => .addStringOption(option =>
@@ -32,10 +34,10 @@ export default {
subcommand subcommand
.setName('remove') .setName('remove')
.setDescription('Remove notes from a user.') .setDescription('Remove notes from a user.')
.addUserOption(option => .addStringOption(option =>
option option
.setName('user') .setName('user')
.setDescription('The user to remove a note from.') .setDescription('The discord user mention, or ID, to remove a note from.')
.setRequired(true) .setRequired(true)
) )
.addIntegerOption(option => .addIntegerOption(option =>
@@ -50,16 +52,22 @@ export default {
subcommand subcommand
.setName('list') .setName('list')
.setDescription("List a user's notes") .setDescription("List a user's notes")
.addUserOption(option => .addStringOption(option =>
option option
.setName('user') .setName('user')
.setDescription('The user to list the notes of.') .setDescription('The discord user mention, or ID, to list the notes of.')
.setRequired(true) .setRequired(true)
) )
), ),
handler: async function (client: Client, interaction: ChatInputCommandInteraction) { handler: async function (client: Client, interaction: ChatInputCommandInteraction) {
const subcommand = interaction.options.getSubcommand(true); const subcommand = interaction.options.getSubcommand(true);
const user = interaction.options.getUser('user', true);
const input = interaction.options.getString('user', true);
const matches = mentionRegex.exec(input);
mentionRegex.lastIndex = 0;
const idToUse = matches ? matches.groups!.id : input;
await deferInteraction(interaction); await deferInteraction(interaction);
@@ -85,9 +93,9 @@ export default {
] ]
}); });
await Database.putNote(user.id, reason, interaction.user.id); await Database.putNote(idToUse, reason, interaction.user.id);
interaction.editReply(`Note added to ${user}.\n\nReason:\n${reason}`); interaction.editReply(`Note added to <@${idToUse}>.\n\nReason:\n${reason}`);
} else if (subcommand == 'remove') { } else if (subcommand == 'remove') {
const user = interaction.options.getUser('user', true); const user = interaction.options.getUser('user', true);
const noteId = interaction.options.getInteger('note', true); const noteId = interaction.options.getInteger('note', true);
@@ -119,9 +127,9 @@ export default {
await Database.removeNote(noteId); await Database.removeNote(noteId);
interaction.editReply('Removed note.'); interaction.editReply('Removed note.');
} else if (subcommand == 'list') { } else if (subcommand == 'list') {
const noteMessage = await getNoteMessage(user.id, 1); const noteMessage = await getNoteMessage(idToUse, 1);
if (!noteMessage) return interaction.editReply(`No notes found for <@${user.id}>`); if (!noteMessage) return interaction.editReply(`No notes found for <@${idToUse}>`);
interaction.editReply(noteMessage); interaction.editReply(noteMessage);
} }
+1 -1
View File
@@ -14,7 +14,7 @@ export default {
.addStringOption(option => .addStringOption(option =>
option option
.setName('user') .setName('user')
.setDescription('The discord user mention, or ID to find the e621 user of.') .setDescription('The discord user mention, or ID, to find the e621 user of.')
.setRequired(true) .setRequired(true)
), ),
handler: async function (client: Client, interaction: ChatInputCommandInteraction) { handler: async function (client: Client, interaction: ChatInputCommandInteraction) {