changed interface and classes code appearance

This commit is contained in:
mmacierzanka committed 2021-09-05 01:52:33 +02:00
1 parent 976bd15c70
commit 95d538d5a1
9 files changed
+52

No files matched your search

+9
View File
@@ -10,12 +10,15 @@ import { ParameterType } from "./types/Parameter.js";
*/ */
export class PermissionsError extends Error { export class PermissionsError extends Error {
private readonly command: BaseCommand; private readonly command: BaseCommand;
private readonly user: GuildMember | null; private readonly user: GuildMember | null;
constructor(command: BaseCommand, user?: GuildMember | null) { constructor(command: BaseCommand, user?: GuildMember | null) {
super(); super();
this.command = command; this.command = command;
this.user = user || null; this.user = user || null;
} }
public 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`;
} }
@@ -28,12 +31,15 @@ export class PermissionsError extends Error {
*/ */
export class ParameterTypeError extends TypeError { export class ParameterTypeError extends TypeError {
private readonly stringContent: string; private readonly stringContent: string;
private readonly type: ParameterType; private readonly type: ParameterType;
constructor(s: string, type: ParameterType) { constructor(s: string, type: ParameterType) {
super(); super();
this.stringContent = s; this.stringContent = s;
this.type = type; this.type = type;
} }
public toString() { public toString() {
return `Parameter "${this.stringContent}" cannot be converted to ${this.type}`; return `Parameter "${this.stringContent}" cannot be converted to ${this.type}`;
} }
@@ -46,10 +52,12 @@ export class ParameterTypeError extends TypeError {
*/ */
export class MissingParameterError extends ReferenceError { export class MissingParameterError extends ReferenceError {
private readonly argument: Parameter; private readonly argument: Parameter;
constructor(a: Parameter) { constructor(a: Parameter) {
super(); super();
this.argument = a; this.argument = a;
} }
public 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`;
} }
@@ -61,6 +69,7 @@ export class MissingParameterError extends ReferenceError {
*/ */
export class OperationSuccess { export class OperationSuccess {
public readonly command: BaseCommand; public readonly command: BaseCommand;
constructor(c: BaseCommand) { constructor(c: BaseCommand) {
this.command = c; this.command = c;
} }
+4
View File
@@ -12,13 +12,17 @@ import { MessageCommand } from "../structures/MessageCommand.js";
*/ */
export class CommandManager { export class CommandManager {
private readonly _textCommandsList: TextCommand[] = []; private readonly _textCommandsList: TextCommand[] = [];
private readonly _messagesCommandsList: BaseCommand[] = []; private readonly _messagesCommandsList: BaseCommand[] = [];
private readonly _userCommandsList: BaseCommand[] = []; private readonly _userCommandsList: BaseCommand[] = [];
/** /**
* Prefix used as a way to trigger the bot using messages * Prefix used as a way to trigger the bot using messages
* @type {string} * @type {string}
*/ */
public readonly prefix?: string; public readonly prefix?: string;
/** /**
* Separator used to split user input to a list of {@link InputParameter}s (applies to prefix interactions) * Separator used to split user input to a list of {@link InputParameter}s (applies to prefix interactions)
* @type {string} * @type {string}
+4
View File
@@ -7,21 +7,25 @@ export class SystemMessageManager {
* @type {SystemMessageAppearance} * @type {SystemMessageAppearance}
*/ */
public PERMISSION: SystemMessageAppearance; public PERMISSION: SystemMessageAppearance;
/** /**
* Error message * Error message
* @type {SystemMessageAppearance} * @type {SystemMessageAppearance}
*/ */
public ERROR: SystemMessageAppearance; public ERROR: SystemMessageAppearance;
/** /**
* "Command not found" message * "Command not found" message
* @type {SystemMessageAppearance} * @type {SystemMessageAppearance}
*/ */
public NOT_FOUND: SystemMessageAppearance; public NOT_FOUND: SystemMessageAppearance;
/** /**
* "Task completed successfully" message * "Task completed successfully" message
* @type {SystemMessageAppearance} * @type {SystemMessageAppearance}
*/ */
public SUCCESS: SystemMessageAppearance; public SUCCESS: SystemMessageAppearance;
/** /**
* Global time (in ms) after a message gets deleted * Global time (in ms) after a message gets deleted
* @type {number} * @type {number}
+5
View File
@@ -30,26 +30,31 @@ export class Bot extends EventEmitter {
* @type {string} * @type {string}
*/ */
public readonly name: string; public readonly name: string;
/** /**
* Discord.js {@link Client} instance * Discord.js {@link Client} instance
* @type {Client} * @type {Client}
*/ */
public readonly client: Client; public readonly client: Client;
/** /**
* Instance command manager * Instance command manager
* @type {CommandManager} * @type {CommandManager}
*/ */
public readonly commands: CommandManager; public readonly commands: CommandManager;
/** /**
* Discord bot token * Discord bot token
* @type {string} * @type {string}
*/ */
public readonly token: string; public readonly token: string;
/** /**
* Discord API application ID * Discord API application ID
* @type {string} * @type {string}
*/ */
public readonly applicationId: string; public readonly applicationId: string;
/** /**
* Built-in messages configuration * Built-in messages configuration
* @type {Object} * @type {Object}
+6
View File
@@ -11,21 +11,25 @@ export class Parameter {
* @type {string} * @type {string}
*/ */
public readonly name: string; public readonly name: string;
/** /**
* Parameter description * Parameter description
* @type {string} * @type {string}
*/ */
public readonly description: string; public readonly description: string;
/** /**
* Whether this parameter is optional * Whether this parameter is optional
* @type {boolean} * @type {boolean}
*/ */
public readonly optional: boolean; public readonly optional: boolean;
/** /**
* Parameter input type * Parameter input type
* @type {ParameterType} * @type {ParameterType}
*/ */
public readonly type: ParameterType; public readonly type: ParameterType;
/** /**
* List of value choices (available only when type is set to "STRING") * List of value choices (available only when type is set to "STRING")
*/ */
@@ -129,9 +133,11 @@ export class ObjectParameter extends InputParameter {
export class ObjectID { export class ObjectID {
public readonly id: string; public readonly id: string;
constructor(id: string) { constructor(id: string) {
this.id = id.replace(">", "").replace("<@!", "").replace("<#!", ""); this.id = id.replace(">", "").replace("<@!", "").replace("<#!", "");
} }
public async toObject( public async toObject(
guild: Guild, guild: Guild,
type: "channel" | "user" | "role" type: "channel" | "user" | "role"
+5
View File
@@ -10,26 +10,31 @@ export interface InitOptions {
* @type {string} * @type {string}
*/ */
name: string; name: string;
/** /**
* Prefix used as a way to trigger the bot using messages * Prefix used as a way to trigger the bot using messages
* @type {string} * @type {string}
*/ */
prefix?: string; prefix?: string;
/** /**
* Separator used to split user input to a list of {@link InputParameter}s (applies to prefix interactions) * Separator used to split user input to a list of {@link InputParameter}s (applies to prefix interactions)
* @type {string} * @type {string}
*/ */
parameterSeparator?: string; parameterSeparator?: string;
/** /**
* Additional {@link ClientOptions} for Discord.js {@link Client} object * Additional {@link ClientOptions} for Discord.js {@link Client} object
* @type {ClientOptions} * @type {ClientOptions}
*/ */
clientOptions?: ClientOptions; clientOptions?: ClientOptions;
/** /**
* Discord bot token * Discord bot token
* @type {string} * @type {string}
*/ */
token: string; token: string;
/** /**
* Discord API application ID * Discord API application ID
* @type {string} * @type {string}
+6
View File
@@ -6,31 +6,37 @@ export interface HelpMessageParams {
* @type {boolean} * @type {boolean}
*/ */
enabled: boolean; enabled: boolean;
/** /**
* Title field * Title field
* @type {string} * @type {string}
*/ */
title: string; title: string;
/** /**
* Text below the title * Text below the title
* @type {string} * @type {string}
*/ */
bottomText: string; bottomText: string;
/** /**
* Color of a message * Color of a message
* @type {ColorResolvable} * @type {ColorResolvable}
*/ */
color: ColorResolvable; color: ColorResolvable;
/** /**
* Description of the "help" command * Description of the "help" command
* @type {string} * @type {string}
*/ */
description: string; description: string;
/** /**
* Usage of the "help" command * Usage of the "help" command
* @type {string} * @type {string}
*/ */
usage: string; usage: string;
/** /**
* Whether the "help" command should be visible in the help message * Whether the "help" command should be visible in the help message
* @type {boolean} * @type {boolean}
+3
View File
@@ -15,11 +15,13 @@ export interface ParameterSchema {
* @type {string} * @type {string}
*/ */
name: string; name: string;
/** /**
* Parameter description * Parameter description
* @type {string} * @type {string}
*/ */
description?: string; description?: string;
/** /**
* Whether this parameter is optional * Whether this parameter is optional
* @type {boolean} * @type {boolean}
@@ -27,6 +29,7 @@ export interface ParameterSchema {
optional: boolean; optional: boolean;
type: ParameterType; type: ParameterType;
/** /**
* List of value choices (available only when type is set to "STRING") * List of value choices (available only when type is set to "STRING")
*/ */
+10
View File
@@ -17,36 +17,43 @@ export interface SystemMessageAppearance {
* @type {boolean} * @type {boolean}
*/ */
enabled: boolean; enabled: boolean;
/** /**
* Title field * Title field
* @type {string} * @type {string}
*/ */
title: string; title: string;
/** /**
* Text below the title * Text below the title
* @type {string} * @type {string}
*/ */
bottomText?: string; bottomText?: string;
/** /**
* Color of a message * Color of a message
* @type {ColorResolvable} * @type {ColorResolvable}
*/ */
accentColor?: ColorResolvable; accentColor?: ColorResolvable;
/** /**
* Whether to display detailed informations in the message * Whether to display detailed informations in the message
* @type {boolean} * @type {boolean}
*/ */
displayDetails?: boolean; displayDetails?: boolean;
/** /**
* Whether to show current time and date in a footer * Whether to show current time and date in a footer
* @type {boolean} * @type {boolean}
*/ */
showTimestamp?: boolean; showTimestamp?: boolean;
/** /**
* Footer text * Footer text
* @type {string} * @type {string}
*/ */
footer?: string; footer?: string;
/** /**
* Time (in ms) after a message of this type gets deleted (set to *Infinity* to not delete the message) * Time (in ms) after a message of this type gets deleted (set to *Infinity* to not delete the message)
* @type {number} * @type {number}
@@ -64,16 +71,19 @@ export interface SystemMessageData {
* @type {TextCommand} * @type {TextCommand}
*/ */
command?: TextCommand; command?: TextCommand;
/** /**
* Phrase received from a Discord channel * Phrase received from a Discord channel
* @type {string} * @type {string}
*/ */
phrase?: string; phrase?: string;
/** /**
* User who used the bot * User who used the bot
* @type {GuildMember | User} * @type {GuildMember | User}
*/ */
user?: GuildMember | User; user?: GuildMember | User;
/** /**
* Error object * Error object
* @type {Error | PermissionsError | string} * @type {Error | PermissionsError | string}