From 7701e5e4fde920fc5a086cafd0ec86454975fe4a Mon Sep 17 00:00:00 2001 From: GRZ4NA Date: Thu, 2 Sep 2021 21:03:52 +0200 Subject: [PATCH] annotated class methods --- src/Bot.ts | 4 ++-- src/Command.ts | 4 ++-- src/CommandManager.ts | 12 ++++++------ src/Parameter.ts | 2 +- src/SystemMessage.ts | 2 +- src/errors.ts | 6 +++--- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Bot.ts b/src/Bot.ts index 7f04a01..5818264 100644 --- a/src/Bot.ts +++ b/src/Bot.ts @@ -116,7 +116,7 @@ export class Bot extends EventEmitter { * @param {boolean} [register=true] - if *true* or *undefined*, the bot will register all slash commands in Discord API * @returns {Promise} whether this operation has been completed successfully */ - async start(port?: number, register?: boolean): Promise { + public async start(port?: number, register?: boolean): Promise { try { console.log(`\nBot name: ${this.name}`); console.log(`Prefix: ${this.commands.prefix || "/ (only slash commands)"} \n`); @@ -244,7 +244,7 @@ export class Bot extends EventEmitter { * Registers commands from {@link CommandManager} in Discord API * @returns {Promise} */ - async register(): Promise { + public async register(): Promise { process.stdout.write("Registering commands... "); await axios.put( `https://discord.com/api/v8/applications/${this.applicationId}/commands`, diff --git a/src/Command.ts b/src/Command.ts index eedc174..18f5386 100644 --- a/src/Command.ts +++ b/src/Command.ts @@ -116,7 +116,7 @@ export class Command { * @param {InputParameter[]} [cmdParams] - list of processed parameters passed in a Discord interaction * @returns {Promise} */ - async start(interaction?: Message | CommandInteraction, cmdParams?: InputParameter[]): Promise { + public async start(interaction?: Message | CommandInteraction, cmdParams?: InputParameter[]): Promise { 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; }; @@ -173,7 +173,7 @@ export class Command { * Converts {@link Command} instance to object that is recognized by the Discord API * @returns {Object} object */ - toCommandObject() { + public toCommandObject() { let options: any[] = []; if (this.parameters) { options = this.parameters.map((p) => { diff --git a/src/CommandManager.ts b/src/CommandManager.ts index 2fd10b3..5f9bfae 100644 --- a/src/CommandManager.ts +++ b/src/CommandManager.ts @@ -40,7 +40,7 @@ export class CommandManager { * @param {string} phrase - command name, alias or keyword * @returns {Command | null} Retrieved {@link Command} object from the manager or *null* */ - get(phrase: string): Command | null { + public get(phrase: string): Command | null { let command: Command | null = null; this.list.map((c) => { if (c.name == phrase) { @@ -60,7 +60,7 @@ export class CommandManager { * Get list (array) of all {@link Command}s registered in a manager * @returns {Command[]} Array of {@link Command}s registered in a manager */ - getList(): Command[] { + public getList(): Command[] { const list = [...this.list]; return list; } @@ -70,7 +70,7 @@ export class CommandManager { * @param {Command} command - {@link Command} instance object * @returns {boolean} Whether this command has been added successfully */ - add(command: Command): boolean { + public add(command: Command): boolean { try { if (!(command instanceof Command)) { throw new TypeError("Inavlid argument type"); @@ -108,7 +108,7 @@ export class CommandManager { * @param {Message} message - {@link Message} object * @returns {CommandMessagesStructure | null} {@link CommandMessageStructure} or *null* */ - fetchFromMessage(message: Message): CommandMessageStructure | null { + public fetchFromMessage(message: Message): CommandMessageStructure | null { if (!this.prefix) return null; if (!message.author.bot && message.content.startsWith(this.prefix)) { const content = message.content.replace(this.prefix, ""); @@ -167,7 +167,7 @@ export class CommandManager { * @param {CommandInteraction} interaction - {@link CommandInteraction} object * @returns {CommandMessagesStructure | null} {@link CommandMessageStructure} or *null* */ - fetchFromInteraction(interaction: CommandInteraction): CommandMessageStructure | null { + public fetchFromInteraction(interaction: CommandInteraction): CommandMessageStructure | null { const cmd = this.get(interaction.commandName); if (cmd) { if (interaction.options?.data) { @@ -212,7 +212,7 @@ export class CommandManager { return null; } - freezeList(): void { + public freezeList(): void { if (!Object.isFrozen(this.list)) { Object.freeze(this.list); } diff --git a/src/Parameter.ts b/src/Parameter.ts index 85ddc35..970ea5c 100644 --- a/src/Parameter.ts +++ b/src/Parameter.ts @@ -152,7 +152,7 @@ export class ObjectID { constructor(id: string) { this.id = id.replace(">", "").replace("<@!", "").replace("<#!", ""); } - async toObject( + public async toObject( guild: Guild, type: "channel" | "user" | "role" ): Promise { diff --git a/src/SystemMessage.ts b/src/SystemMessage.ts index 9006f2b..a7bace9 100644 --- a/src/SystemMessage.ts +++ b/src/SystemMessage.ts @@ -152,7 +152,7 @@ export class SystemMessageManager { * @param {Message | CommandInteraction} [interaction] - if specified, the generated message will be sent in this channel * @returns {Promise} A message that got sent or *void* */ - async send(type: MessageType, data?: SystemMessageData, interaction?: Message | CommandInteraction): Promise { + public async send(type: MessageType, data?: SystemMessageData, interaction?: Message | CommandInteraction): Promise { if (this[type]) { if (this[type].enabled === false) { return; diff --git a/src/errors.ts b/src/errors.ts index 8b7d1d0..c60ba37 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -16,7 +16,7 @@ export class PermissionsError extends Error { this.command = command; this.user = user || null; } - toString() { + public toString() { return `User ${this.user?.user.tag} doesn't have enough permissions to run "${this.command.name}" command`; } } @@ -34,7 +34,7 @@ export class ParameterTypeError extends TypeError { this.stringContent = s; this.type = type; } - toString() { + public toString() { return `Parameter "${this.stringContent}" cannot be converted to ${this.type}`; } } @@ -50,7 +50,7 @@ export class MissingParameterError extends ReferenceError { super(); this.argument = a; } - toString() { + public toString() { return `Your request is missing a "${this.argument.name}" parameter which is not optional`; } }