Attempt to resolve usernames
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { ApplicationIntegrationType, BitFieldResolvable, ChatInputCommandInteraction, Client, GuildBasedChannel, InteractionContextType, MessageFlags, MessageMentions, PermissionFlagsBits, SlashCommandBuilder, User } from 'discord.js';
|
import { ApplicationIntegrationType, BitFieldResolvable, ChatInputCommandInteraction, Client, GuildBasedChannel, InteractionContextType, MessageFlags, MessageMentions, PermissionFlagsBits, SlashCommandBuilder, User } from 'discord.js';
|
||||||
import { channelIsInStaffCategory, handleWhoIsInteraction, logCustomEvent } from '../utils';
|
import { channelIsInStaffCategory, handleWhoIsInteraction, logCustomEvent, resolveUser } from '../utils';
|
||||||
import { Database } from '../shared/Database';
|
import { Database } from '../shared/Database';
|
||||||
import { config } from '../config';
|
import { config } from '../config';
|
||||||
|
|
||||||
@@ -59,13 +59,7 @@ export default {
|
|||||||
|
|
||||||
const idToUse = matches ? matches.groups!.id : discordUserInput;
|
const idToUse = matches ? matches.groups!.id : discordUserInput;
|
||||||
|
|
||||||
let user: User | null = null;
|
const user = await resolveUser(client, idToUse);
|
||||||
|
|
||||||
try {
|
|
||||||
user = await client.users.fetch(idToUse);
|
|
||||||
} catch (e) {
|
|
||||||
return interaction.editReply('An error has occurred. Are you using the right format? You can provide a user ID (ex `324007235137044482`) or a user mention (you must have text previews enabled, Settings -> Chat -> Text Box).');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!user) return interaction.editReply("Couldn't find user.");
|
if (!user) return interaction.editReply("Couldn't find user.");
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { ApplicationCommandOptionType, ApplicationIntegrationType, AutocompleteInteraction, ChatInputCommandInteraction, Client, GuildBasedChannel, InteractionContextType, MessageFlags, MessageMentions, PermissionFlagsBits, SlashCommandBuilder, User } from 'discord.js';
|
import { ApplicationCommandOptionType, ApplicationIntegrationType, AutocompleteInteraction, ChatInputCommandInteraction, Client, GuildBasedChannel, InteractionContextType, MessageFlags, MessageMentions, PermissionFlagsBits, SlashCommandBuilder, User } from 'discord.js';
|
||||||
import { Database } from '../shared/Database';
|
import { Database } from '../shared/Database';
|
||||||
import { channelIsInStaffCategory, deferInteraction, logCustomEvent } from '../utils';
|
import { channelIsInStaffCategory, deferInteraction, logCustomEvent, resolveUser } from '../utils';
|
||||||
import { getNoteMessage } from '../utils/note-utils';
|
import { getNoteMessage } from '../utils/note-utils';
|
||||||
|
|
||||||
const mentionRegex = new RegExp(MessageMentions.UsersPattern);
|
const mentionRegex = new RegExp(MessageMentions.UsersPattern);
|
||||||
@@ -95,13 +95,7 @@ export default {
|
|||||||
|
|
||||||
await deferInteraction(interaction);
|
await deferInteraction(interaction);
|
||||||
|
|
||||||
let user: User | null = null;
|
const user = await resolveUser(client, idToUse);
|
||||||
|
|
||||||
try {
|
|
||||||
user = await client.users.fetch(idToUse);
|
|
||||||
} catch (e) {
|
|
||||||
return interaction.editReply('An error has occurred. Are you using the right format? You can provide a user ID (ex `324007235137044482`) or a user mention (you must have text previews enabled, Settings -> Chat -> Text Box).');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!user) return interaction.editReply('User not found');
|
if (!user) return interaction.editReply('User not found');
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { Client, User } from 'discord.js';
|
||||||
|
|
||||||
|
export async function resolveUser(client: Client, value: string): Promise<User | null | undefined> {
|
||||||
|
let user: User | null | undefined = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
user = await client.users.fetch(value);
|
||||||
|
} catch (e) {
|
||||||
|
user = client.users.cache.find(u => u.username == value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
@@ -5,9 +5,12 @@ export * from './ban-events';
|
|||||||
export * from './ban-utils';
|
export * from './ban-utils';
|
||||||
export * from './channel-utils';
|
export * from './channel-utils';
|
||||||
export * from './commands';
|
export * from './commands';
|
||||||
|
export * from './debug-utils';
|
||||||
|
export * from './discord-user-utils';
|
||||||
export * from './e621-utils';
|
export * from './e621-utils';
|
||||||
export * from './event-log-utils';
|
export * from './event-log-utils';
|
||||||
export * from './file-utils';
|
export * from './file-utils';
|
||||||
|
export * from './github-user-utils';
|
||||||
export * from './interaction-utils';
|
export * from './interaction-utils';
|
||||||
export * from './message-utils';
|
export * from './message-utils';
|
||||||
export * from './ms-to-human';
|
export * from './ms-to-human';
|
||||||
|
|||||||
Reference in New Issue
Block a user