feat: handleCommand update

This commit is contained in:
MARCROCK22 2024-07-02 21:16:54 +00:00
parent 8e655ee1c7
commit eb1a999c45

View File

@ -461,20 +461,28 @@ export class HandleCommand {
return false; return false;
} }
async fetchChannel(_option: CommandOptionWithType, id: string) { async fetchChannel(_option: CommandOptionWithType, query: string) {
return this.client.channels.raw(id); const id = query.match(/[0-9]{17,19}/g)?.[0];
if (id) return this.client.channels.raw(id);
return null;
} }
async fetchUser(_option: CommandOptionWithType, id: string) { async fetchUser(_option: CommandOptionWithType, query: string) {
return this.client.users.raw(id); const id = query.match(/[0-9]{17,19}/g)?.[0];
if (id) return this.client.users.raw(id);
return null;
} }
async fetchMember(_option: CommandOptionWithType, id: string, guildId: string) { async fetchMember(_option: CommandOptionWithType, query: string, guildId: string) {
return this.client.members.raw(guildId, id); const id = query.match(/[0-9]{17,19}/g)?.[0];
if (id) return this.client.members.raw(guildId, id);
return null;
} }
async fetchRole(_option: CommandOptionWithType, id: string, guildId?: string) { async fetchRole(_option: CommandOptionWithType, query: string, guildId?: string) {
return guildId ? (await this.client.roles.listRaw(guildId)).find(x => x.id === id) : undefined; const id = query.match(/[0-9]{17,19}/g)?.[0];
if (id && guildId) return (await this.client.roles.listRaw(guildId)).find(x => x.id === id);
return null;
} }
async runGlobalMiddlewares( async runGlobalMiddlewares(
@ -585,11 +593,12 @@ export class HandleCommand {
break; break;
case ApplicationCommandOptionType.Channel: case ApplicationCommandOptionType.Channel:
{ {
const rawId = const rawQuery =
message.content.match(/(?<=<#)[0-9]{17,19}(?=>)/g)?.find(x => args[i.name]?.includes(x)) || message.content.match(/(?<=<#)[0-9]{17,19}(?=>)/g)?.find(x => args[i.name]?.includes(x)) ||
args[i.name]?.match(/[0-9]{17,19}/g)?.[0]; args[i.name];
if (!rawId) continue; if (!rawQuery) continue;
const channel = (await this.client.cache.channels?.raw(rawId)) ?? (await this.fetchChannel(i, rawId)); const channel =
(await this.client.cache.channels?.raw(rawQuery)) ?? (await this.fetchChannel(i, rawQuery));
if (channel) { if (channel) {
if ('channel_types' in i) { if ('channel_types' in i) {
if (!(i as SeyfertChannelOption).channel_types!.includes(channel.type)) { if (!(i as SeyfertChannelOption).channel_types!.includes(channel.type)) {
@ -603,15 +612,15 @@ export class HandleCommand {
break; break;
} }
} }
value = rawId; value = channel.id;
//discord funny memoentnt!!!!!!!! //discord funny memoentnt!!!!!!!!
resolved.channels[rawId] = channel as APIInteractionDataResolvedChannel; resolved.channels[channel.id] = channel as APIInteractionDataResolvedChannel;
} }
} }
break; break;
case ApplicationCommandOptionType.Mentionable: case ApplicationCommandOptionType.Mentionable:
{ {
const matches = message.content.match(/<@[0-9]{17,19}(?=>)|<@&[0-9]{17,19}(?=>)/g) ?? []; const matches = args[i.name]?.match(/<@[0-9]{17,19}(?=>)|<@&[0-9]{17,19}(?=>)/g) ?? [];
for (const match of matches) { for (const match of matches) {
if (match.includes('&')) { if (match.includes('&')) {
const rawId = match.slice(3); const rawId = match.slice(3);
@ -640,36 +649,33 @@ export class HandleCommand {
break; break;
case ApplicationCommandOptionType.Role: case ApplicationCommandOptionType.Role:
{ {
const rawId = const rawQuery = message.mention_roles.find(x => args[i.name]?.includes(x)) || args[i.name];
message.mention_roles.find(x => args[i.name]?.includes(x)) || args[i.name]?.match(/[0-9]{17,19}/g)?.[0]; if (!rawQuery) continue;
if (!rawId) continue;
const role = const role =
(await this.client.cache.roles?.raw(rawId)) ?? (await this.fetchRole(i, rawId, message.guild_id)); (await this.client.cache.roles?.raw(rawQuery)) ?? (await this.fetchRole(i, rawQuery, message.guild_id));
if (role) { if (role) {
value = rawId; value = role.id;
resolved.roles[rawId] = role; resolved.roles[role.id] = role;
} }
} }
break; break;
case ApplicationCommandOptionType.User: case ApplicationCommandOptionType.User:
{ {
const rawId = const rawQuery = message.mentions.find(x => args[i.name]?.includes(x.id))?.id || args[i.name];
message.mentions.find(x => args[i.name]?.includes(x.id))?.id || if (!rawQuery) continue;
args[i.name]?.match(/[0-9]{17,19}/g)?.[0];
if (!rawId) continue;
const raw = const raw =
message.mentions.find(x => args[i.name]?.includes(x.id)) ?? message.mentions.find(x => args[i.name]?.includes(x.id)) ??
(await this.client.cache.users?.raw(rawId)) ?? (await this.client.cache.users?.raw(rawQuery)) ??
(await this.fetchUser(i, rawId)); (await this.fetchUser(i, rawQuery));
if (raw) { if (raw) {
value = raw.id; value = raw.id;
resolved.users[raw.id] = raw; resolved.users[raw.id] = raw;
if (message.guild_id) { if (message.guild_id) {
const member = const member =
message.mentions.find(x => args[i.name]?.includes(x.id))?.member ?? message.mentions.find(x => args[i.name]?.includes(x.id))?.member ??
(await this.client.cache.members?.raw(rawId, message.guild_id)) ?? (await this.client.cache.members?.raw(value, message.guild_id)) ??
(await this.fetchMember(i, rawId, message.guild_id)); (await this.fetchMember(i, value, message.guild_id));
if (member) resolved.members[raw.id] = member; if (member) resolved.members[value] = member;
} }
} }
} }