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