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,
|
interaction?: Message | CommandInteraction,
|
||||||
cmdParams?: InputParameter[]
|
cmdParams?: InputParameter[]
|
||||||
): Promise<void> {
|
): 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> =
|
const memberPermissions: Readonly<Permissions> =
|
||||||
interaction?.member?.permissions || new Permissions();
|
(interaction?.member?.permissions as Permissions) ||
|
||||||
|
new Permissions();
|
||||||
if (
|
if (
|
||||||
!this.permissions ||
|
!this.permissions ||
|
||||||
(this.permissionCheck == "ALL"
|
(this.permissionCheck == "ALL"
|
||||||
? memberPermissions.has(this.permissions, true)
|
? memberPermissions.has(this.permissions, true)
|
||||||
: memberPermissions.any(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(
|
const fnResult = await this.function.call(
|
||||||
this,
|
this,
|
||||||
function (query: string, returnType?: "value" | "object") {
|
paramFindFn,
|
||||||
return returnType === "object"
|
|
||||||
? cmdParams?.find((p) => p.name === query) || null
|
|
||||||
: cmdParams?.find((p) => p.name === query)?.value ||
|
|
||||||
null;
|
|
||||||
},
|
|
||||||
interaction
|
interaction
|
||||||
);
|
);
|
||||||
|
if (interaction instanceof Message) {
|
||||||
if (
|
if (
|
||||||
fnResult instanceof Object &&
|
fnResult instanceof Object &&
|
||||||
("content" in (fnResult as any) ||
|
("content" in (fnResult as any) ||
|
||||||
@@ -128,43 +145,7 @@ export class Command {
|
|||||||
} else if (fnResult instanceof MessageEmbed) {
|
} else if (fnResult instanceof MessageEmbed) {
|
||||||
await interaction?.channel.send({ embeds: [fnResult] });
|
await interaction?.channel.send({ embeds: [fnResult] });
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new PermissionsError(this, interaction?.member);
|
|
||||||
}
|
|
||||||
} else if (interaction instanceof CommandInteraction) {
|
} 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 {
|
try {
|
||||||
if (
|
if (
|
||||||
fnResult instanceof Object &&
|
fnResult instanceof Object &&
|
||||||
@@ -227,11 +208,10 @@ export class Command {
|
|||||||
} else {
|
} else {
|
||||||
throw new PermissionsError(
|
throw new PermissionsError(
|
||||||
this,
|
this,
|
||||||
interaction.member as GuildMember
|
interaction?.member as GuildMember
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
toCommandObject() {
|
toCommandObject() {
|
||||||
let options: any[] = [];
|
let options: any[] = [];
|
||||||
|
|||||||
Reference in new issue
Block a user