annotated class methods

This commit is contained in:
mmacierzanka committed 2021-09-02 21:03:52 +02:00
1 parent 69b91f82f3
commit 7701e5e4fd
6 files changed
+15 -15

No files matched your search

+2 -2
View File
@@ -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 * @param {boolean} [register=true] - if *true* or *undefined*, the bot will register all slash commands in Discord API
* @returns {Promise<boolean>} whether this operation has been completed successfully * @returns {Promise<boolean>} whether this operation has been completed successfully
*/ */
async start(port?: number, register?: boolean): Promise<boolean> { public async start(port?: number, register?: boolean): Promise<boolean> {
try { try {
console.log(`\nBot name: ${this.name}`); console.log(`\nBot name: ${this.name}`);
console.log(`Prefix: ${this.commands.prefix || "/ (only slash commands)"} \n`); 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 * Registers commands from {@link CommandManager} in Discord API
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async register(): Promise<void> { public async register(): Promise<void> {
process.stdout.write("Registering commands... "); process.stdout.write("Registering commands... ");
await axios.put( await axios.put(
`https://discord.com/api/v8/applications/${this.applicationId}/commands`, `https://discord.com/api/v8/applications/${this.applicationId}/commands`,
+2 -2
View File
@@ -116,7 +116,7 @@ export class Command {
* @param {InputParameter[]} [cmdParams] - list of processed parameters passed in a Discord interaction * @param {InputParameter[]} [cmdParams] - list of processed parameters passed in a Discord interaction
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async start(interaction?: Message | CommandInteraction, cmdParams?: InputParameter[]): Promise<void> { public async start(interaction?: Message | CommandInteraction, cmdParams?: InputParameter[]): Promise<void> {
const paramFindFn = function (query: string, returnType?: "value" | "object") { 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; 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 * Converts {@link Command} instance to object that is recognized by the Discord API
* @returns {Object} object * @returns {Object} object
*/ */
toCommandObject() { public toCommandObject() {
let options: any[] = []; let options: any[] = [];
if (this.parameters) { if (this.parameters) {
options = this.parameters.map((p) => { options = this.parameters.map((p) => {
+6 -6
View File
@@ -40,7 +40,7 @@ export class CommandManager {
* @param {string} phrase - command name, alias or keyword * @param {string} phrase - command name, alias or keyword
* @returns {Command | null} Retrieved {@link Command} object from the manager or *null* * @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; let command: Command | null = null;
this.list.map((c) => { this.list.map((c) => {
if (c.name == phrase) { if (c.name == phrase) {
@@ -60,7 +60,7 @@ export class CommandManager {
* Get list (array) of all {@link Command}s registered in a manager * Get list (array) of all {@link Command}s registered in a manager
* @returns {Command[]} Array of {@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]; const list = [...this.list];
return list; return list;
} }
@@ -70,7 +70,7 @@ export class CommandManager {
* @param {Command} command - {@link Command} instance object * @param {Command} command - {@link Command} instance object
* @returns {boolean} Whether this command has been added successfully * @returns {boolean} Whether this command has been added successfully
*/ */
add(command: Command): boolean { public add(command: Command): boolean {
try { try {
if (!(command instanceof Command)) { if (!(command instanceof Command)) {
throw new TypeError("Inavlid argument type"); throw new TypeError("Inavlid argument type");
@@ -108,7 +108,7 @@ export class CommandManager {
* @param {Message} message - {@link Message} object * @param {Message} message - {@link Message} object
* @returns {CommandMessagesStructure | null} {@link CommandMessageStructure} or *null* * @returns {CommandMessagesStructure | null} {@link CommandMessageStructure} or *null*
*/ */
fetchFromMessage(message: Message): CommandMessageStructure | null { public fetchFromMessage(message: Message): CommandMessageStructure | null {
if (!this.prefix) return null; if (!this.prefix) return null;
if (!message.author.bot && message.content.startsWith(this.prefix)) { if (!message.author.bot && message.content.startsWith(this.prefix)) {
const content = message.content.replace(this.prefix, ""); const content = message.content.replace(this.prefix, "");
@@ -167,7 +167,7 @@ export class CommandManager {
* @param {CommandInteraction} interaction - {@link CommandInteraction} object * @param {CommandInteraction} interaction - {@link CommandInteraction} object
* @returns {CommandMessagesStructure | null} {@link CommandMessageStructure} or *null* * @returns {CommandMessagesStructure | null} {@link CommandMessageStructure} or *null*
*/ */
fetchFromInteraction(interaction: CommandInteraction): CommandMessageStructure | null { public fetchFromInteraction(interaction: CommandInteraction): CommandMessageStructure | null {
const cmd = this.get(interaction.commandName); const cmd = this.get(interaction.commandName);
if (cmd) { if (cmd) {
if (interaction.options?.data) { if (interaction.options?.data) {
@@ -212,7 +212,7 @@ export class CommandManager {
return null; return null;
} }
freezeList(): void { public freezeList(): void {
if (!Object.isFrozen(this.list)) { if (!Object.isFrozen(this.list)) {
Object.freeze(this.list); Object.freeze(this.list);
} }
+1 -1
View File
@@ -152,7 +152,7 @@ export class ObjectID {
constructor(id: string) { constructor(id: string) {
this.id = id.replace(">", "").replace("<@!", "").replace("<#!", ""); this.id = id.replace(">", "").replace("<@!", "").replace("<#!", "");
} }
async toObject( public async toObject(
guild: Guild, guild: Guild,
type: "channel" | "user" | "role" type: "channel" | "user" | "role"
): Promise<Role | TextChannel | VoiceChannel | CategoryChannel | GuildMember | NewsChannel | StoreChannel | StageChannel | null> { ): Promise<Role | TextChannel | VoiceChannel | CategoryChannel | GuildMember | NewsChannel | StoreChannel | StageChannel | null> {
+1 -1
View File
@@ -152,7 +152,7 @@ export class SystemMessageManager {
* @param {Message | CommandInteraction} [interaction] - if specified, the generated message will be sent in this channel * @param {Message | CommandInteraction} [interaction] - if specified, the generated message will be sent in this channel
* @returns {Promise<MessageEmbed | Message | void>} A message that got sent or *void* * @returns {Promise<MessageEmbed | Message | void>} A message that got sent or *void*
*/ */
async send(type: MessageType, data?: SystemMessageData, interaction?: Message | CommandInteraction): Promise<MessageEmbed | Message | void> { public async send(type: MessageType, data?: SystemMessageData, interaction?: Message | CommandInteraction): Promise<MessageEmbed | Message | void> {
if (this[type]) { if (this[type]) {
if (this[type].enabled === false) { if (this[type].enabled === false) {
return; return;
+3 -3
View File
@@ -16,7 +16,7 @@ export class PermissionsError extends Error {
this.command = command; this.command = command;
this.user = user || null; this.user = user || null;
} }
toString() { public toString() {
return `User ${this.user?.user.tag} doesn't have enough permissions to run "${this.command.name}" command`; 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.stringContent = s;
this.type = type; this.type = type;
} }
toString() { public toString() {
return `Parameter "${this.stringContent}" cannot be converted to ${this.type}`; return `Parameter "${this.stringContent}" cannot be converted to ${this.type}`;
} }
} }
@@ -50,7 +50,7 @@ export class MissingParameterError extends ReferenceError {
super(); super();
this.argument = a; this.argument = a;
} }
toString() { public toString() {
return `Your request is missing a "${this.argument.name}" parameter which is not optional`; return `Your request is missing a "${this.argument.name}" parameter which is not optional`;
} }
} }