MAJOR CHANGE: swapped calling function arguments + replaced parameters list with function that fetches parameter (earlier getParam)

This commit is contained in:
mmacierzanka committed 2021-08-08 04:03:00 +02:00
1 parent 207b358535
commit 4173c96a55
3 files changed
+46 -32

No files matched your search

+35 -26
View File
@@ -28,8 +28,11 @@ export class Command {
guilds?: string[];
visible: boolean;
private function: (
interaction?: Message | CommandInteraction,
cmdParams?: InputParameter[]
params: (
query: string,
returnType?: "value" | "object"
) => ParameterResolvable | InputParameter | null,
interaction?: Message | CommandInteraction
) =>
| void
| string
@@ -103,15 +106,21 @@ export class Command {
) {
const fnResult = await this.function.call(
this,
interaction,
cmdParams
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
);
if (
"content" in (fnResult as ReplyMessageOptions) ||
"embeds" in (fnResult as ReplyMessageOptions) ||
"files" in (fnResult as ReplyMessageOptions) ||
"components" in (fnResult as ReplyMessageOptions) ||
"sticker" in (fnResult as ReplyMessageOptions)
fnResult instanceof Object &&
("content" in (fnResult as any) ||
"embeds" in (fnResult as any) ||
"files" in (fnResult as any) ||
"components" in (fnResult as any) ||
"sticker" in (fnResult as any))
) {
await interaction.reply(fnResult as ReplyMessageOptions);
} else if (typeof fnResult == "string") {
@@ -144,16 +153,26 @@ export class Command {
}, 2000);
const fnResult = await this.function.call(
this,
interaction,
cmdParams
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 (
"content" in (fnResult as ReplyMessageOptions) ||
"embeds" in (fnResult as ReplyMessageOptions) ||
"files" in (fnResult as ReplyMessageOptions) ||
"components" in (fnResult as ReplyMessageOptions) ||
"sticker" in (fnResult as ReplyMessageOptions)
fnResult instanceof Object &&
("content" in (fnResult as any) ||
"embeds" in (fnResult as any) ||
"files" in (fnResult as any) ||
"components" in (fnResult as any) ||
"sticker" in (fnResult as any))
) {
interaction.replied
? await interaction.editReply(
@@ -251,16 +270,6 @@ export class Command {
};
}
getParam(
query: string,
list: InputParameter[],
returnType?: "value" | "object"
): ParameterResolvable | InputParameter | null {
return returnType === "object"
? list.find((p) => p.name === query) || null
: list.find((p) => p.name === query)?.value || null;
}
private static processPhrase(
phrase?: string | string[]
): string[] | undefined {
+6 -4
View File
@@ -23,15 +23,15 @@ export class HelpMessage extends Command {
type: "string",
},
],
function: (_, a) => {
function: (param, _) => {
const helpMsg = new MessageEmbed();
helpMsg.setColor(params.color);
helpMsg.setTimestamp();
helpMsg.setFooter(botName || "");
if (helpMsg != null) {
if (a && a[0]) {
if (param("command_name")) {
const cmd: Command | null = cmdManager.get(
a[0].value?.toString() || "",
param("command_name")?.toString() || "",
"ALL"
);
if (cmd) {
@@ -75,7 +75,9 @@ export class HelpMessage extends Command {
}
} else {
throw new ReferenceError(
`Command "${a[0].value}" does not exist`
`Command "${param(
"command_name"
)}" does not exist`
);
}
} else {
+5 -2
View File
@@ -30,8 +30,11 @@ export interface CommandBuilder {
guilds?: string[];
visible?: boolean;
function: (
interaction?: Message | CommandInteraction,
cmdParams?: InputParameter[]
params: (
query: string,
returnType?: "value" | "object"
) => ParameterResolvable | InputParameter | null,
interaction?: Message | CommandInteraction
) =>
| void
| string