improved code safety by adding readonly keywords

This commit is contained in:
mmacierzanka committed 2021-08-31 18:21:52 +02:00
1 parent 7d05248fdb
commit 4473e7f404
6 files changed
+39 -39

No files matched your search

+6 -6
View File
@@ -26,32 +26,32 @@ export class Bot extends EventEmitter {
* Bot name
* @type {string}
*/
name: string;
public readonly name: string;
/**
* Discord.js {@link Client} instance
* @type {Client}
*/
client: Client;
public readonly client: Client;
/**
* Instance command manager
* @type {CommandManager}
*/
commands: CommandManager;
public readonly commands: CommandManager;
/**
* Discord bot token
* @type {string}
*/
token: string;
public readonly token: string;
/**
* Discord API application ID
* @type {string}
*/
applicationId: string;
public readonly applicationId: string;
/**
* Built-in messages configuration
* @type {Object}
*/
messages: {
public readonly messages: {
/**
* Help message configuration
* @type {HelpMessageParams}
+12 -12
View File
@@ -14,58 +14,58 @@ export class Command {
* Command name
* @type {string}
*/
name: string;
public readonly name: string;
/**
* List of parameters that can passed to this command
* @type {Array} {@link Parameter}
*/
parameters: Parameter[];
public readonly parameters: Parameter[];
/**
* List of different names that can be used to invoke a command (when using prefix interactions)
* @type {Array} *string*
*/
aliases?: string[];
public readonly aliases?: string[];
/**
* Command description displayed in the help message (Default description: "No description")
* @type {string}
*/
description: string;
public readonly description: string;
/**
* Command usage displayed in the help message
* @type {string}
*/
usage?: string;
public readonly usage?: string;
/**
* Whether to check if a caller has all defined in *permissions* property permissions or at least one of them (doesn't apply to custom function permissions)
* @type {PermissionCheckTypes} "ALL" | "ANY"
*/
permissionCheck: PermissionCheckTypes;
public readonly permissionCheck: PermissionCheckTypes;
/**
* Command permissions (if *undefined*, no permissions check will be performed)
* @type {PermissionResolvable}
* @type {Function} should return boolean value
*/
permissions?: Permissions | ((m?: Message | CommandInteraction) => boolean);
public readonly permissions?: Permissions | ((m?: Message | CommandInteraction) => boolean);
/**
* List of Discord guild (server) IDs in which this command can be used
* @type {Array} *string*
*/
guilds?: string[];
public readonly guilds?: string[];
/**
* Whether this command is visible in the help message (default: true)
* @type {boolean}
*/
visible: boolean;
public readonly visible: boolean;
/**
* Whether this command should be registered as a slash command (default: true)
* @type {boolean}
*/
slash: boolean;
public readonly slash: boolean;
/**
* Whether to send a SUCCESS message if no other response is defined (default: true)
* @type {boolean}
*/
announceSuccess: boolean;
public readonly announceSuccess: boolean;
/**
* Command execution function (triggered when someone invokes the command)
* @type {Function}
@@ -73,7 +73,7 @@ export class Command {
* @param {Message | CommandInteraction} i - interaction object
* @private
*/
private function: (
private readonly function: (
params: (query: string, returnType?: "value" | "object") => ParameterResolvable | InputParameter | null,
interaction?: Message | CommandInteraction
) => void | string | MessageEmbed | ReplyMessageOptions | Promise<void | string | MessageEmbed | ReplyMessageOptions>;
+3 -3
View File
@@ -12,17 +12,17 @@ export class CommandManager {
* List of commands registered in the manager
* @type {Array} {@link Command}
*/
list: Command[];
public readonly list: Command[];
/**
* Prefix used as a way to trigger the bot using messages
* @type {string}
*/
prefix?: string;
public readonly prefix?: string;
/**
* Separator used to split user input to a list of {@link InputParameter}s (applies to prefix interactions)
* @type {string}
*/
parameterSeparator: string;
public readonly parameterSeparator: string;
/**
* @constructor
+7 -7
View File
@@ -37,26 +37,26 @@ export class Parameter {
* Parameter name
* @type {string}
*/
name: string;
public readonly name: string;
/**
* Parameter description
* @type {string}
*/
description: string;
public readonly description: string;
/**
* Whether this parameter is optional
* @type {boolean}
*/
optional: boolean;
public readonly optional: boolean;
/**
* Parameter input type
* @type {ParameterType}
*/
type: ParameterType;
public readonly type: ParameterType;
/**
* List of value choices (available only when type is set to "STRING")
*/
choices?: string[];
public readonly choices?: string[];
constructor(options: ParameterSchema) {
this.name = options.name;
@@ -93,7 +93,7 @@ export class InputParameter extends Parameter {
* Input value
* @type {ParameterResolvable}
*/
value: ParameterResolvable;
public readonly value: ParameterResolvable;
constructor(parameter: Parameter, value: ParameterResolvable) {
super(parameter);
@@ -148,7 +148,7 @@ export class ObjectParameter extends InputParameter {
}
}
export class ObjectID {
id: string;
public readonly id: string;
constructor(id: string) {
this.id = id.replace(">", "").replace("<@!", "").replace("<#!", "");
}
+5 -5
View File
@@ -84,27 +84,27 @@ export class SystemMessageManager {
* "Insufficient permissions" message
* @type {SystemMessageAppearance}
*/
PERMISSION: SystemMessageAppearance;
public PERMISSION: SystemMessageAppearance;
/**
* Error message
* @type {SystemMessageAppearance}
*/
ERROR: SystemMessageAppearance;
public ERROR: SystemMessageAppearance;
/**
* "Command not found" message
* @type {SystemMessageAppearance}
*/
NOT_FOUND: SystemMessageAppearance;
public NOT_FOUND: SystemMessageAppearance;
/**
* "Task completed successfully" message
* @type {SystemMessageAppearance}
*/
SUCCESS: SystemMessageAppearance;
public SUCCESS: SystemMessageAppearance;
/**
* Global time (in ms) after a message gets deleted
* @type {number}
*/
deleteTimeout: number;
public deleteTimeout: number;
constructor(botName?: string) {
this.PERMISSION = {
+6 -6
View File
@@ -9,8 +9,8 @@ import { ParameterType } from "./types.js";
* @exports
*/
export class PermissionsError extends Error {
private command: Command;
private user: GuildMember | null;
private readonly command: Command;
private readonly user: GuildMember | null;
constructor(command: Command, user?: GuildMember | null) {
super();
this.command = command;
@@ -27,8 +27,8 @@ export class PermissionsError extends Error {
* @exports
*/
export class ParameterTypeError extends TypeError {
private stringContent: string;
private type: ParameterType;
private readonly stringContent: string;
private readonly type: ParameterType;
constructor(s: string, type: ParameterType) {
super();
this.stringContent = s;
@@ -45,7 +45,7 @@ export class ParameterTypeError extends TypeError {
* @exports
*/
export class MissingParameterError extends ReferenceError {
private argument: Parameter;
private readonly argument: Parameter;
constructor(a: Parameter) {
super();
this.argument = a;
@@ -60,7 +60,7 @@ export class MissingParameterError extends ReferenceError {
* @exports
*/
export class OperationSuccess {
command: Command;
public readonly command: Command;
constructor(c: Command) {
this.command = c;
}