Archived
code cleanup (command proccessing)
This commit is contained in:
1 parent
6144f3e577
commit
d94f2ec92e
1 file changed
+26
-46
+26
-46
@@ -95,25 +95,42 @@ export class Command {
|
||||
interaction?: Message | CommandInteraction,
|
||||
cmdParams?: InputParameter[]
|
||||
): Promise<void> {
|
||||
if (interaction instanceof Message) {
|
||||
const paramFindFn = function (
|
||||
query: string,
|
||||
returnType?: "value" | "object"
|
||||
) {
|
||||
return returnType === "object"
|
||||
? cmdParams?.find((p) => p.name === query) || null
|
||||
: cmdParams?.find((p) => p.name === query)?.value || null;
|
||||
};
|
||||
const memberPermissions: Readonly<Permissions> =
|
||||
interaction?.member?.permissions || new Permissions();
|
||||
(interaction?.member?.permissions as Permissions) ||
|
||||
new Permissions();
|
||||
if (
|
||||
!this.permissions ||
|
||||
(this.permissionCheck == "ALL"
|
||||
? memberPermissions.has(this.permissions, true)
|
||||
: memberPermissions.any(this.permissions, true))
|
||||
) {
|
||||
if (interaction instanceof CommandInteraction) {
|
||||
setTimeout(async () => {
|
||||
if (!interaction.replied) {
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setColor("#ffff00")
|
||||
.setTitle("🔄 Please wait..."),
|
||||
],
|
||||
});
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
const fnResult = await this.function.call(
|
||||
this,
|
||||
function (query: string, returnType?: "value" | "object") {
|
||||
return returnType === "object"
|
||||
? cmdParams?.find((p) => p.name === query) || null
|
||||
: cmdParams?.find((p) => p.name === query)?.value ||
|
||||
null;
|
||||
},
|
||||
paramFindFn,
|
||||
interaction
|
||||
);
|
||||
if (interaction instanceof Message) {
|
||||
if (
|
||||
fnResult instanceof Object &&
|
||||
("content" in (fnResult as any) ||
|
||||
@@ -128,43 +145,7 @@ export class Command {
|
||||
} else if (fnResult instanceof MessageEmbed) {
|
||||
await interaction?.channel.send({ embeds: [fnResult] });
|
||||
}
|
||||
} else {
|
||||
throw new PermissionsError(this, interaction?.member);
|
||||
}
|
||||
} else if (interaction instanceof CommandInteraction) {
|
||||
const memberPermissions = interaction.member?.permissions;
|
||||
if (memberPermissions instanceof Permissions) {
|
||||
if (
|
||||
!this.permissions ||
|
||||
(this.permissionCheck === "ALL"
|
||||
? memberPermissions.has(this.permissions, true)
|
||||
: memberPermissions.any(this.permissions, true))
|
||||
) {
|
||||
setTimeout(async () => {
|
||||
if (!interaction.replied) {
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
new MessageEmbed()
|
||||
.setColor("#ffff00")
|
||||
.setTitle("🔄 Please wait..."),
|
||||
],
|
||||
});
|
||||
}
|
||||
}, 2000);
|
||||
const fnResult = await this.function.call(
|
||||
this,
|
||||
function (
|
||||
query: string,
|
||||
returnType?: "value" | "object"
|
||||
) {
|
||||
return returnType === "object"
|
||||
? cmdParams?.find((p) => p.name === query) ||
|
||||
null
|
||||
: cmdParams?.find((p) => p.name === query)
|
||||
?.value || null;
|
||||
},
|
||||
interaction
|
||||
);
|
||||
try {
|
||||
if (
|
||||
fnResult instanceof Object &&
|
||||
@@ -227,11 +208,10 @@ export class Command {
|
||||
} else {
|
||||
throw new PermissionsError(
|
||||
this,
|
||||
interaction.member as GuildMember
|
||||
interaction?.member as GuildMember
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toCommandObject() {
|
||||
let options: any[] = [];
|
||||
|
||||
Reference in new issue
Block a user