cumsystem
Version:
simple command system and command handler
217 lines (216 loc) • 8.16 kB
TypeScript
import * as Discord from 'discord.js';
import { System } from './System';
/**
* Represents a command the bot can run (for example, a help command)
*
* `content` is a variable that is the message's content without the prefix. For example:
*
* `msg.content`: `!say abcdefg aa aa`
*
* `content`: `abcdefg aa aa`
*/
export declare class Command {
/** The name of the command, also what the command uses to be invoked */
name: string;
/** The function to run when the command is invoked */
cfunc: (message: Discord.Message, content: string) => any | undefined;
/** A description of the command; shows up in the help command */
description: string;
/** The category the command belongs in */
category: string;
/** The usage of the command. Used for checking the syntax */
usage: string;
/** The usage of the command, but only used for the help command */
displayUsage: string;
/** An array of permissions the client needs to run the command */
clientPermissions: Discord.PermissionResolvable[];
/** An array of permissions the user needs to invoke the command */
userPermissions: Discord.PermissionResolvable[];
/** The command can only be ran in a DM */
needsDM: boolean;
/** The command can only be ran in a guild/server */
needsGuild: boolean;
/** The comand wont show up in the help commands */
hidden: boolean;
/** The command can only be ran by the owner */
ownerOnly: boolean;
/** The command will ignore prefix overrides */
ignorePrefix: boolean;
/** The command can only be ran in an NSFW channel or in DMs */
nsfwOnly: boolean;
/** An array of alternative names that can be used to invoke the command */
aliases: string[];
/** An array of example usages of the command. Only show up in help */
examples: string[];
/** The function used to check the usage of the command, will use the default one if not provided */
usageCheck: ((content: string) => boolean) | undefined;
/** Amount of ms until anyone can use the command since it was last used */
globalCooldown: number;
/** Amount of ms until a user can use the command again */
userCooldown: number;
private globalCooldowns;
private userCooldowns;
/**
* Create a command
* @example
* ```typescript
* let command = new CommandSystem.Command('test', msg => {
* msg.channel.send('Testing!');
* });
* ```
* @param {string} name The name, also what invokes the command
* @param {function} cfunction The function to run after the command is ran
*/
constructor(name: string, cfunction: (message: Discord.Message, content: string) => any | null);
/**
* Change the command name
* @param {string} name The name to use for the command
* @returns {Command} Itself
*/
setName(name: string): Command;
/**
* Sets the usage of the command. Will be used for checking the syntax!!, use `Command#setDisplayUsage` to set a display usage.
*
* Types available:
* - `user`
* - `number`
* - `id`
* - `url`
* - `string` / `any`
*
* @example
* ```typescript
* new Command('', message => {
* message.channel.send('usage test passed!');
* })
* .setUsage('(string) (number) (user)')
* .setDisplayUsage('(parameter 1) (parameter 2) (parameter 3)');
* ```
* @param {string} usage the usage, use () for necessary and [] for optional arguments
* @returns {Command} Itself
*/
setUsage(usage: string): Command;
/**
* Changes the usage in the help command. Isn't parsed
* @param {string} usage the usage
* @returns {Command} Itself
*/
setDisplayUsage(usage: string): Command;
/**
* Add an example usage to the command
* @example
* ```typescript
* new Command('', message => {
* message.channel.send('usage test passed!');
* })
* .setUsage('(string) (number) (user)')
* .setDisplayUsage('(parameter 1) (parameter 2) (parameter 3)')
* .addExample('text 1 551929694019256333');
* ```
* @param {string} example an example usage of the command
* @returns {Command} Itself
*/
addExample(example: string): Command;
/**
* Adds an alias which the command can be invoked with
* @param {string} alias the name of the alias
* @returns {Command} Itself
*/
addAlias(alias: string): Command;
/**
* Adds aliases which the command can be invoked with
* @param {string[]} aliases an array of alias names
* @returns {Command} Itself
*/
addAliases(aliases: string[]): Command;
/**
* Sets the command's decription, display only
* @param {string} desc the description, leave empty to remove
* @returns {Command} Itself
*/
setDescription(desc?: string): Command;
/**
* Sets the command's category, display only
* @param {string} category the category, leave empty to remove
* @returns {Command} Itself
*/
setCategory(category?: string): Command;
/**
* Change the command's visibility in the help command
* @param {boolean} hide
* @returns {Command} Itself
*/
setHidden(hide?: boolean): Command;
/**
* Set the command to be ran as owner only
* @param {boolean} owner
* @returns {Command} Itself
*/
setOwnerOnly(owner?: boolean): Command;
/**
* Set whether the command is able to be ran outside dms or not
* @param {boolean} needs
* @returns {Command} Itself
*/
setDMOnly(needs?: boolean): Command;
/**
* Set whether the command is able to be ran outside servers or not
* @param {boolean} needs
* @returns {Command} Itself
*/
setGuildOnly(needs?: boolean): Command;
/**
* Set whether the command can only be ran in an NSFW channel or a DM
* @param {boolean} needs
* @returns {Command} Itself
*/
setNSFW(needs?: boolean): Command;
/**
* Set whether the command ignores any given custom prefixes (only really useful for commands that change the prefix)
* @param {boolean} needs
* @returns {Command} Itself
*/
setIgnorePrefix(needs?: boolean): Command;
/**
* Add a permission required for the client to run the command
* @param {Discord.PermissionResolvable} perm The permission to add
* @returns {Command} Itself
*/
addClientPermission(perm: Discord.PermissionResolvable): Command;
/**
* add a permission required for the user to invoke the command
* @param {Discord.PermissionResolvable} perm the permission to add
* @returns {Command} Itself
*/
addUserPermission(perm: Discord.PermissionResolvable): Command;
/**
* add multiple permissions required for the client to run the command
* @param {Discord.PermissionResolvable[]} perms an array of permissions to add
* @returns {Command} Itself
*/
addClientPermissions(perms: Discord.PermissionResolvable[]): Command;
/**
* add multiple permissions required for the user to invoke the command
* @param {Discord.PermissionResolvable[]} perms an array of permissions to add
* @returns {Command} Itself
*/
addUserPermissions(perms: Discord.PermissionResolvable[]): Command;
/**
* Set a per-user cooldown on the command to prevent it from being spammed
* @param {number} time the cooldown in ms
* @returns {Command} Itself
*/
setUserCooldown(time: number): Command;
/**
* Set a global cooldown on the command to prevent it from being spammed
* @param {number} time the cooldown in ms
* @returns {Command} Itself
*/
setGlobalCooldown(time: number): Command;
/**
* check if you can run the command with a message, and if so run it
* @param {Discord.Message} message the message that invoked the command
* @param {Discord.Client} client the client of the bot that recieved the command
*/
runCommand(message: Discord.Message, system: System): Promise<Discord.Message> | Promise<Discord.MessageReaction> | undefined;
}