From 417cc02bbd68feacb4d311d69bfab9296985a2a2 Mon Sep 17 00:00:00 2001 From: Tarrgon <61888458+Tarrgon@users.noreply.github.com> Date: Wed, 4 Jun 2025 15:08:08 -0400 Subject: [PATCH] Remove optionals from whois and finduser --- src/commands/finduser.ts | 21 +++++---------------- src/commands/whois.ts | 26 ++++++++++---------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/src/commands/finduser.ts b/src/commands/finduser.ts index c1d647c..5c1773b 100644 --- a/src/commands/finduser.ts +++ b/src/commands/finduser.ts @@ -13,30 +13,19 @@ export default { .setDefaultMemberPermissions(PermissionFlagsBits.BanMembers) .addStringOption(option => option - .setName('username') - .setDescription('The e621 username to find the discord user of.') - .setRequired(false) - ) - .addStringOption(option => - option - .setName('id') - .setDescription('The e621 user id to find the discord user of.') - .setRequired(false) + .setName('user') + .setDescription('The e621 username or e621 id to find the discord user of.') + .setRequired(true) ), handler: async function (client: Client, interaction: ChatInputCommandInteraction) { await deferInteraction(interaction); if (!interaction.guild) return interaction.editReply('This command must be used in a server'); - const username = interaction.options.getString('username'); - const id = interaction.options.getString('id'); - - if (!username && !id) { - return interaction.editReply({ content: 'No username or id given.' }); - } + const user = interaction.options.getString('user', true); try { - const e621User = await getE621User((id ?? username) as string); + const e621User = await getE621User(user); if (!e621User) { return interaction.editReply('I got lost along the way. Who again?'); diff --git a/src/commands/whois.ts b/src/commands/whois.ts index fd50af4..bb65ce5 100644 --- a/src/commands/whois.ts +++ b/src/commands/whois.ts @@ -1,6 +1,8 @@ -import { ApplicationIntegrationType, BitFieldResolvable, ChatInputCommandInteraction, Client, GuildBasedChannel, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js'; +import { ApplicationIntegrationType, BitFieldResolvable, ChatInputCommandInteraction, Client, GuildBasedChannel, InteractionContextType, MessageFlags, MessageMentions, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js'; import { channelIsInStaffCategory, handleWhoIsInteraction } from '../utils'; +const mentionRegex = new RegExp(MessageMentions.UsersPattern); + export default { name: 'whois', data: new SlashCommandBuilder() @@ -9,27 +11,19 @@ export default { .setIntegrationTypes(ApplicationIntegrationType.GuildInstall) .setContexts(InteractionContextType.Guild) .setDefaultMemberPermissions(PermissionFlagsBits.BanMembers) - .addUserOption(option => - option - .setName('user') - .setDescription('The discord user to find the e621 user of.') - .setRequired(false) - ) .addStringOption(option => option - .setName('id') - .setDescription('The discord user id to find the e621 user of.') - .setRequired(false) + .setName('user') + .setDescription('The discord user mention, or ID to find the e621 user of.') + .setRequired(true) ), handler: async function (client: Client, interaction: ChatInputCommandInteraction) { - const user = interaction.options.getUser('user'); - const id = interaction.options.getString('id'); + const input = interaction.options.getString('user', true); - if (!user && !id) { - return interaction.reply({ content: 'No user or id given.', flags: [MessageFlags.Ephemeral] }); - } + const matches = mentionRegex.exec(input); + mentionRegex.lastIndex = 0; - const idToUse = (user?.id ?? id) as string; + const idToUse = matches ? matches.groups!.id : input; handleWhoIsInteraction(interaction, idToUse, !(await channelIsInStaffCategory(interaction.channel as GuildBasedChannel))); }