Archived
created dedicated directory for types
This commit is contained in:
1 parent
7701e5e4fd
commit
50be804169
13 files changed
+225
-203
No files matched your search
+3
-1
@@ -7,7 +7,9 @@ import { CommandManager } from "./CommandManager.js";
|
||||
import { OperationSuccess, PermissionsError } from "./errors.js";
|
||||
import { HelpMessage } from "./Help.js";
|
||||
import { SystemMessageManager } from "./SystemMessage.js";
|
||||
import { CommandMessageStructure, InitOptions, HelpMessageParams } from "./types.js";
|
||||
import { CommandMessageStructure } from "./types/Command.js";
|
||||
import { InitOptions } from "./types/Bot.js";
|
||||
import { HelpMessageParams } from "./types/HelpMessage.js";
|
||||
|
||||
export declare interface Bot {
|
||||
on(event: "READY", listener: Function): this;
|
||||
|
||||
+3
-3
@@ -1,10 +1,10 @@
|
||||
//IMPORTS
|
||||
import { Permissions, Message, MessageEmbed, CommandInteraction, GuildMember, ReplyMessageOptions, PermissionResolvable } from "discord.js";
|
||||
import { CommandBuilder, ParameterResolvable, PermissionCheckTypes } from "./types.js";
|
||||
import { CommandBuilder } from "./types/Command.js";
|
||||
import { ParameterResolvable } from "./types/Parameter.js";
|
||||
import { PermissionCheckTypes } from "./types/permissions.js";
|
||||
import { OperationSuccess, PermissionsError } from "./errors.js";
|
||||
import { DefaultParameter, InputParameter, Parameter } from "./Parameter.js";
|
||||
|
||||
//CLASSES
|
||||
/**
|
||||
* @class Class that represents a command instance
|
||||
* @exports
|
||||
|
||||
@@ -2,7 +2,7 @@ import { CommandInteraction, Message } from "discord.js";
|
||||
import { MissingParameterError } from "./errors.js";
|
||||
import { BooleanParameter, InputParameter, NumberParameter, ObjectParameter, StringParameter } from "./Parameter.js";
|
||||
import { Command } from "./Command.js";
|
||||
import { CommandMessageStructure, PhraseOccurrenceData } from "./types.js";
|
||||
import { CommandMessageStructure, PhraseOccurrenceData } from "./types/Command.js";
|
||||
|
||||
/**
|
||||
* @class Command manager
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import { MessageEmbed } from "discord.js";
|
||||
import { Command } from "./Command.js";
|
||||
import { CommandManager } from "./CommandManager.js";
|
||||
import { HelpMessageParams } from "./types.js";
|
||||
import { HelpMessageParams } from "./types/HelpMessage.js";
|
||||
|
||||
export class HelpMessage extends Command {
|
||||
constructor(cmdManager: CommandManager, params: HelpMessageParams, botName?: string) {
|
||||
|
||||
+8
-28
@@ -1,33 +1,6 @@
|
||||
import { CategoryChannel, Guild, GuildMember, NewsChannel, Role, StageChannel, StoreChannel, TextChannel, VoiceChannel } from "discord.js";
|
||||
import { ParameterType, ParameterResolvable } from "./types.js";
|
||||
/**
|
||||
* @interface
|
||||
* Properties required to build a {@link Parameter} object
|
||||
* @exports
|
||||
*/
|
||||
export interface ParameterSchema {
|
||||
/**
|
||||
* Parameter name
|
||||
* @type {string}
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Parameter description
|
||||
* @type {string}
|
||||
*/
|
||||
description?: string;
|
||||
/**
|
||||
* Whether this parameter is optional
|
||||
* @type {boolean}
|
||||
*/
|
||||
optional: boolean;
|
||||
import { ParameterType, ParameterResolvable, ParameterSchema } from "./types/Parameter.js";
|
||||
|
||||
type: ParameterType;
|
||||
/**
|
||||
* List of value choices (available only when type is set to "STRING")
|
||||
*/
|
||||
choices?: string[];
|
||||
}
|
||||
/**
|
||||
* @class Representation of command parameter
|
||||
* @exports
|
||||
@@ -73,6 +46,7 @@ export class Parameter {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
export class DefaultParameter extends Parameter {
|
||||
constructor() {
|
||||
super({
|
||||
@@ -83,6 +57,7 @@ export class DefaultParameter extends Parameter {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @class Representation of input parameter (argument) coming from a message or an interaction
|
||||
* @extends Parameter
|
||||
@@ -100,6 +75,7 @@ export class InputParameter extends Parameter {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
export class StringParameter extends InputParameter {
|
||||
constructor(parameter: Parameter, value: ParameterResolvable) {
|
||||
if (parameter.type != "string") {
|
||||
@@ -117,6 +93,7 @@ export class StringParameter extends InputParameter {
|
||||
super(parameter, value?.toString());
|
||||
}
|
||||
}
|
||||
|
||||
export class BooleanParameter extends InputParameter {
|
||||
constructor(parameter: Parameter, value: ParameterResolvable) {
|
||||
if (parameter.type != "boolean") {
|
||||
@@ -131,6 +108,7 @@ export class BooleanParameter extends InputParameter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class NumberParameter extends InputParameter {
|
||||
constructor(parameter: Parameter, value: ParameterResolvable) {
|
||||
if (parameter.type != "number") {
|
||||
@@ -139,6 +117,7 @@ export class NumberParameter extends InputParameter {
|
||||
super(parameter, parseFloat(value ? value.toString() : ""));
|
||||
}
|
||||
}
|
||||
|
||||
export class ObjectParameter extends InputParameter {
|
||||
constructor(parameter: Parameter, value: ParameterResolvable) {
|
||||
if (parameter.type != "channel" && parameter.type != "mentionable" && parameter.type != "user" && parameter.type != "role") {
|
||||
@@ -147,6 +126,7 @@ export class ObjectParameter extends InputParameter {
|
||||
super(parameter, new ObjectID(value?.toString() || ""));
|
||||
}
|
||||
}
|
||||
|
||||
export class ObjectID {
|
||||
public readonly id: string;
|
||||
constructor(id: string) {
|
||||
|
||||
+2
-80
@@ -1,83 +1,5 @@
|
||||
import { ColorResolvable, CommandInteraction, GuildMember, Message, MessageEmbed, User } from "discord.js";
|
||||
import { Command } from "./Command.js";
|
||||
import { PermissionsError } from "./errors.js";
|
||||
|
||||
/**
|
||||
* @type Type of message
|
||||
*/
|
||||
export type MessageType = "PERMISSION" | "ERROR" | "NOT_FOUND" | "SUCCESS";
|
||||
/**
|
||||
* @interface
|
||||
* Configuration of system message
|
||||
*/
|
||||
export interface SystemMessageAppearance {
|
||||
/**
|
||||
* Whether this type of message is enabled
|
||||
* @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}
|
||||
*/
|
||||
deleteTimeout?: number;
|
||||
}
|
||||
/**
|
||||
* @interface
|
||||
* System message data definition
|
||||
*/
|
||||
export interface SystemMessageData {
|
||||
/**
|
||||
* A {@link Command} instance
|
||||
* @type {Command}
|
||||
*/
|
||||
command?: Command;
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
error?: Error | PermissionsError | string;
|
||||
}
|
||||
import { CommandInteraction, Message, MessageEmbed } from "discord.js";
|
||||
import { SystemMessageAppearance, SystemMessageData, MessageType } from "./types/SystemMessage";
|
||||
|
||||
export class SystemMessageManager {
|
||||
/**
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import { Command } from "./Command.js";
|
||||
import { GuildMember } from "discord.js";
|
||||
import { Parameter } from "./Parameter.js";
|
||||
import { ParameterType } from "./types.js";
|
||||
import { ParameterType } from "./types/Parameter.js";
|
||||
|
||||
/**
|
||||
* @class Error indicating that a caller doesn't have enough permissions to execute a command
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { ClientOptions } from "discord.js";
|
||||
|
||||
/**
|
||||
* @interface
|
||||
* Main object initialization options
|
||||
*/
|
||||
export interface InitOptions {
|
||||
/**
|
||||
* Bot name
|
||||
* @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}
|
||||
*/
|
||||
applicationId: string;
|
||||
}
|
||||
@@ -1,46 +1,9 @@
|
||||
import { ClientOptions, ColorResolvable, CommandInteraction, ReplyMessageOptions } from "discord.js";
|
||||
import { InputParameter, ObjectID, ParameterSchema } from "./Parameter.js";
|
||||
import { PermissionResolvable, Message, MessageEmbed } from "discord.js";
|
||||
import type { Command } from "./Command.js";
|
||||
import { CommandInteraction, ReplyMessageOptions, PermissionResolvable, Message, MessageEmbed } from "discord.js";
|
||||
import { ParameterSchema, ParameterResolvable } from "./Parameter.js";
|
||||
import { InputParameter } from "../Parameter.js";
|
||||
import { Command } from "../Command.js";
|
||||
import { PermissionCheckTypes } from "./permissions.js";
|
||||
|
||||
/**
|
||||
* @interface
|
||||
* Main object initialization options
|
||||
*/
|
||||
export interface InitOptions {
|
||||
/**
|
||||
* Bot name
|
||||
* @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}
|
||||
*/
|
||||
applicationId: string;
|
||||
}
|
||||
export type GetMode = "ALL" | "PREFIX" | "NO_PREFIX";
|
||||
export type PermissionCheckTypes = "ALL" | "ANY";
|
||||
/**
|
||||
* @interface
|
||||
* Options for building a {@link Command} object
|
||||
@@ -113,54 +76,15 @@ export interface CommandBuilder {
|
||||
interaction?: Message | CommandInteraction
|
||||
) => void | string | MessageEmbed | ReplyMessageOptions | Promise<void | string | MessageEmbed | ReplyMessageOptions>;
|
||||
}
|
||||
export interface PhraseOccurrenceData {
|
||||
command: Command;
|
||||
type: "NAME" | "ALIAS";
|
||||
}
|
||||
|
||||
export interface CommandMessageStructure {
|
||||
command: Command;
|
||||
parameters: InputParameter[];
|
||||
}
|
||||
/**
|
||||
* @interface
|
||||
* Help message properties
|
||||
*/
|
||||
export interface HelpMessageParams {
|
||||
/**
|
||||
* Whether help message is enabled
|
||||
* @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}
|
||||
*/
|
||||
visible: boolean;
|
||||
|
||||
export type GetMode = "ALL" | "PREFIX" | "NO_PREFIX";
|
||||
|
||||
export interface PhraseOccurrenceData {
|
||||
command: Command;
|
||||
type: "NAME" | "ALIAS";
|
||||
}
|
||||
export type ParameterType = "string" | "boolean" | "number" | "user" | "role" | "channel" | "mentionable";
|
||||
export type ParameterResolvable = string | boolean | number | ObjectID | undefined;
|
||||
@@ -0,0 +1,39 @@
|
||||
import { ColorResolvable } from "discord.js";
|
||||
|
||||
export interface HelpMessageParams {
|
||||
/**
|
||||
* Whether help message is enabled
|
||||
* @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}
|
||||
*/
|
||||
visible: boolean;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { ObjectID } from "../Parameter.js";
|
||||
|
||||
export type ParameterType = "string" | "boolean" | "number" | "user" | "role" | "channel" | "mentionable";
|
||||
|
||||
export type ParameterResolvable = string | boolean | number | ObjectID | undefined;
|
||||
|
||||
/**
|
||||
* @interface
|
||||
* Properties required to build a {@link Parameter} object
|
||||
* @exports
|
||||
*/
|
||||
export interface ParameterSchema {
|
||||
/**
|
||||
* Parameter name
|
||||
* @type {string}
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Parameter description
|
||||
* @type {string}
|
||||
*/
|
||||
description?: string;
|
||||
/**
|
||||
* Whether this parameter is optional
|
||||
* @type {boolean}
|
||||
*/
|
||||
optional: boolean;
|
||||
|
||||
type: ParameterType;
|
||||
/**
|
||||
* List of value choices (available only when type is set to "STRING")
|
||||
*/
|
||||
choices?: string[];
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { ColorResolvable, GuildMember, User } from "discord.js";
|
||||
import { Command } from "../Command.js";
|
||||
import { PermissionsError } from "../errors.js";
|
||||
|
||||
/**
|
||||
* @type Type of message
|
||||
*/
|
||||
export type MessageType = "PERMISSION" | "ERROR" | "NOT_FOUND" | "SUCCESS";
|
||||
|
||||
/**
|
||||
* @interface
|
||||
* Configuration of system message
|
||||
*/
|
||||
export interface SystemMessageAppearance {
|
||||
/**
|
||||
* Whether this type of message is enabled
|
||||
* @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}
|
||||
*/
|
||||
deleteTimeout?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
* System message data definition
|
||||
*/
|
||||
export interface SystemMessageData {
|
||||
/**
|
||||
* A {@link Command} instance
|
||||
* @type {Command}
|
||||
*/
|
||||
command?: Command;
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
error?: Error | PermissionsError | string;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export type PermissionCheckTypes = "ALL" | "ANY";
|
||||
Reference in new issue
Block a user