Archived
removed keywords
This commit is contained in:
1 parent
b74dff1af9
commit
f9c586dd14
4 files changed
+13
-71
No files matched your search
@@ -20,7 +20,6 @@ export class Command {
|
|||||||
name: string;
|
name: string;
|
||||||
parameters: Parameter[];
|
parameters: Parameter[];
|
||||||
aliases?: string[];
|
aliases?: string[];
|
||||||
keywords?: string[];
|
|
||||||
description: string;
|
description: string;
|
||||||
usage?: string;
|
usage?: string;
|
||||||
permissionCheck: PermissionCheckTypes;
|
permissionCheck: PermissionCheckTypes;
|
||||||
@@ -64,7 +63,6 @@ export class Command {
|
|||||||
this.parameters = options.parameters.map((ps) => new Parameter(ps));
|
this.parameters = options.parameters.map((ps) => new Parameter(ps));
|
||||||
}
|
}
|
||||||
this.aliases = Command.processPhrase(options.aliases);
|
this.aliases = Command.processPhrase(options.aliases);
|
||||||
this.keywords = Command.processPhrase(options.keywords);
|
|
||||||
this.description = options.description || "No description";
|
this.description = options.description || "No description";
|
||||||
this.usage = options.usage || this.generateUsageFromArguments();
|
this.usage = options.usage || this.generateUsageFromArguments();
|
||||||
this.permissionCheck =
|
this.permissionCheck =
|
||||||
|
|||||||
+12
-59
@@ -31,48 +31,18 @@ export class CommandManager {
|
|||||||
* @param {GetMode} [mode='ALL'] - specifies which types of command triggers will be used to find the command [*NO_PREFIX* - only keywords; *PREFIX* - names and aliases]
|
* @param {GetMode} [mode='ALL'] - specifies which types of command triggers will be used to find the command [*NO_PREFIX* - only keywords; *PREFIX* - names and aliases]
|
||||||
* @returns *Command* | *null*
|
* @returns *Command* | *null*
|
||||||
*/
|
*/
|
||||||
get(phrase: string, mode?: GetMode): Command | null {
|
get(phrase: string): Command | null {
|
||||||
if (!mode) mode = "ALL";
|
|
||||||
let command: Command | null = null;
|
let command: Command | null = null;
|
||||||
this.list.map((c) => {
|
this.list.map((c) => {
|
||||||
switch (mode) {
|
if (c.name == phrase) {
|
||||||
case "PREFIX":
|
command = c;
|
||||||
if (c.name == phrase) {
|
|
||||||
command = c;
|
|
||||||
}
|
|
||||||
c.aliases &&
|
|
||||||
c.aliases.map((a) => {
|
|
||||||
if (a == phrase) {
|
|
||||||
command = c;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case "NO_PREFIX":
|
|
||||||
c.keywords &&
|
|
||||||
c.keywords.map((k) => {
|
|
||||||
if (k == phrase) {
|
|
||||||
command = c;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case "ALL":
|
|
||||||
if (c.name == phrase) {
|
|
||||||
command = c;
|
|
||||||
}
|
|
||||||
c.aliases &&
|
|
||||||
c.aliases.map((a) => {
|
|
||||||
if (a == phrase) {
|
|
||||||
command = c;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
c.keywords &&
|
|
||||||
c.keywords.map((k) => {
|
|
||||||
if (k == phrase) {
|
|
||||||
command = c;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
c.aliases &&
|
||||||
|
c.aliases.map((a) => {
|
||||||
|
if (a == phrase) {
|
||||||
|
command = c;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
@@ -105,17 +75,6 @@ export class CommandManager {
|
|||||||
ar.splice(i, 1);
|
ar.splice(i, 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.list.map((c) => {
|
|
||||||
command.keywords &&
|
|
||||||
command.keywords.map((k, i, a) => {
|
|
||||||
if (c.keywords && c.keywords.indexOf(k) != -1) {
|
|
||||||
console.warn(
|
|
||||||
`[⚠ WARN] The name "${k}" is already a registered KEYWORD for the "${c.name}" command. It will be removed from the "${command.name}" command`
|
|
||||||
);
|
|
||||||
a.splice(i, 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
this.list.push(command);
|
this.list.push(command);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -130,16 +89,10 @@ export class CommandManager {
|
|||||||
* @returns *CommandMessagesStructure* | *null*
|
* @returns *CommandMessagesStructure* | *null*
|
||||||
*/
|
*/
|
||||||
fetchFromMessage(message: Message): CommandMessageStructure | null {
|
fetchFromMessage(message: Message): CommandMessageStructure | null {
|
||||||
if (!message.author.bot) {
|
if (!message.author.bot && message.content.startsWith(this.prefix)) {
|
||||||
let prefix = false;
|
const content = message.content.replace(this.prefix, "");
|
||||||
if (message.content.startsWith(this.prefix)) {
|
|
||||||
prefix = true;
|
|
||||||
}
|
|
||||||
const content = prefix
|
|
||||||
? message.content.replace(this.prefix, "")
|
|
||||||
: message.content;
|
|
||||||
const name = content.split(" ")[0];
|
const name = content.split(" ")[0];
|
||||||
const command = this.get(name, prefix ? "PREFIX" : "NO_PREFIX");
|
const command = this.get(name);
|
||||||
if (command) {
|
if (command) {
|
||||||
const argumentsText = content.replace(name, "");
|
const argumentsText = content.replace(name, "");
|
||||||
const paramsList = argumentsText
|
const paramsList = argumentsText
|
||||||
|
|||||||
+1
-9
@@ -31,8 +31,7 @@ export class HelpMessage extends Command {
|
|||||||
if (helpMsg != null) {
|
if (helpMsg != null) {
|
||||||
if (param("command_name")) {
|
if (param("command_name")) {
|
||||||
const cmd: Command | null = cmdManager.get(
|
const cmd: Command | null = cmdManager.get(
|
||||||
param("command_name")?.toString() || "",
|
param("command_name")?.toString() || ""
|
||||||
"ALL"
|
|
||||||
);
|
);
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
helpMsg.setTitle(
|
helpMsg.setTitle(
|
||||||
@@ -66,13 +65,6 @@ export class HelpMessage extends Command {
|
|||||||
});
|
});
|
||||||
helpMsg.addField("Aliases:", aList, false);
|
helpMsg.addField("Aliases:", aList, false);
|
||||||
}
|
}
|
||||||
if (cmd.keywords && cmd.keywords.length > 0) {
|
|
||||||
let kwrdList: string = "";
|
|
||||||
cmd.keywords.map((k) => {
|
|
||||||
kwrdList += k + "\n";
|
|
||||||
});
|
|
||||||
helpMsg.addField("Keywords:", kwrdList, false);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new ReferenceError(
|
throw new ReferenceError(
|
||||||
`Command "${param(
|
`Command "${param(
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ export interface CommandBuilder {
|
|||||||
name: string;
|
name: string;
|
||||||
parameters?: ParameterSchema[] | "simple" | "no_input";
|
parameters?: ParameterSchema[] | "simple" | "no_input";
|
||||||
aliases?: string[] | string;
|
aliases?: string[] | string;
|
||||||
keywords?: string[] | string;
|
|
||||||
description?: string;
|
description?: string;
|
||||||
usage?: string;
|
usage?: string;
|
||||||
permissionCheck?: PermissionCheckTypes;
|
permissionCheck?: PermissionCheckTypes;
|
||||||
|
|||||||
Reference in new issue
Block a user