From bc9dbbfc9f6145dfef345a2cbbe4fc95343d187d Mon Sep 17 00:00:00 2001 From: kyraNET Date: Tue, 19 Sep 2017 18:21:28 +0200 Subject: [PATCH 01/12] Typings --- .gitattributes | 1 + src/lib/Client.js | 3 +- src/lib/parsers/ArgResolver.js | 6 +-- src/lib/parsers/Resolver.js | 4 +- src/lib/parsers/SettingResolver.js | 4 +- src/lib/structures/CommandStore.js | 2 +- src/lib/structures/interfaces/Store.js | 2 +- tslint.json | 61 ++++++++++++++++++++++++++ 8 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 .gitattributes create mode 100644 tslint.json diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..6313b56c57 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/src/lib/Client.js b/src/lib/Client.js index 9095980dcf..941b35820b 100644 --- a/src/lib/Client.js +++ b/src/lib/Client.js @@ -320,6 +320,7 @@ class KlasaClient extends Discord.Client { /** * Use this to login to Discord with your bot * @param {string} token Your bot token + * @returns {Promise} */ async login(token) { const start = now(); @@ -331,7 +332,7 @@ class KlasaClient extends Discord.Client { this.emit('log', loaded.join('\n')); this.settings = new Settings(this); this.emit('log', `Loaded in ${(now() - start).toFixed(2)}ms.`); - super.login(token); + return super.login(token); } /** diff --git a/src/lib/parsers/ArgResolver.js b/src/lib/parsers/ArgResolver.js index 56ad009bf2..a3c74f4ea1 100644 --- a/src/lib/parsers/ArgResolver.js +++ b/src/lib/parsers/ArgResolver.js @@ -13,7 +13,7 @@ class ArgResolver extends Resolver { * @param {number} possible This possible usage id * @param {boolean} repeat If it is a looping/repeating arg * @param {external:Message} msg The message that triggered the command - * @returns {Command} + * @returns {Piece} */ async piece(arg, currentUsage, possible, repeat, msg) { for (const store of this.client.pieceStores.values()) { @@ -31,7 +31,7 @@ class ArgResolver extends Resolver { * @param {number} possible This possible usage id * @param {boolean} repeat If it is a looping/repeating arg * @param {external:Message} msg The message that triggered the command - * @returns {Command} + * @returns {Store} */ async store(arg, currentUsage, possible, repeat, msg) { const store = this.client.pieceStores.get(arg); @@ -92,7 +92,7 @@ class ArgResolver extends Resolver { * @param {number} possible This possible usage id * @param {boolean} repeat If it is a looping/repeating arg * @param {external:Message} msg The message that triggered the command - * @returns {?Event} + * @returns {?Extendable} */ async extendable(arg, currentUsage, possible, repeat, msg) { const extendable = this.client.extendables.get(arg); diff --git a/src/lib/parsers/Resolver.js b/src/lib/parsers/Resolver.js index 910df5747f..28dff59631 100644 --- a/src/lib/parsers/Resolver.js +++ b/src/lib/parsers/Resolver.js @@ -19,7 +19,7 @@ class Resolver { /** * Fetch a Message object by its Snowflake or instanceof Message. - * @param {Snowflake} message The message snowflake to validate. + * @param {Message|Snowflake} message The message snowflake to validate. * @param {Channel} channel The Channel object in which the message can be found. * @returns {?external:Message} */ @@ -30,7 +30,7 @@ class Resolver { /** * Resolve a User object by its instance of User, GuildMember, or by its Snowflake. - * @param {User} user The user to validate. + * @param {(User|GuildMember|Message|Snowflake)} user The user to validate. * @returns {?external:User} */ async user(user) { diff --git a/src/lib/parsers/SettingResolver.js b/src/lib/parsers/SettingResolver.js index f68d6696d6..9b454d973a 100644 --- a/src/lib/parsers/SettingResolver.js +++ b/src/lib/parsers/SettingResolver.js @@ -178,7 +178,7 @@ class SettingResolver extends Resolver { * @param {any} data The data to resolve * @param {external:Guild} guild The guild to resolve for * @param {string} name The name of the key being resolved - * @returns {Command} + * @returns {Language} */ async language(data, guild, name) { const language = this.client.languages.get(data); @@ -197,7 +197,7 @@ class SettingResolver extends Resolver { * @param {string} [suffix=''] The suffix to apply to the error messages * @returns {boolean} */ - static async maxOrMin(guild, value, min, max, name, suffix = '') { + static maxOrMin(guild, value, min, max, name, suffix = '') { if (min && max) { if (value >= min && value <= max) return true; if (min === max) throw guild.language.get('RESOLVER_MINMAX_EXACTLY', name, min, suffix); diff --git a/src/lib/structures/CommandStore.js b/src/lib/structures/CommandStore.js index 009e47cb64..64f01b4ffe 100644 --- a/src/lib/structures/CommandStore.js +++ b/src/lib/structures/CommandStore.js @@ -121,7 +121,7 @@ class CommandStore extends Collection { /** * Loads a command file into Klasa so it can saved in this store. * @param {string} dir The user directory or core directory where this file is saved. - * @param {Array} file An array containing information about it's category structure. + * @param {string[]} file An array containing information about it's category structure. * @returns {Command} */ load(dir, file) { diff --git a/src/lib/structures/interfaces/Store.js b/src/lib/structures/interfaces/Store.js index a3e460109a..ea271555dc 100644 --- a/src/lib/structures/interfaces/Store.js +++ b/src/lib/structures/interfaces/Store.js @@ -26,7 +26,7 @@ class Store { * Loads a piece into Klasa so it can be saved in this store. * @param {string} dir The user directory or core directory where this file is saved. * @param {string} file A string showing where the file is located. - * @returns {Finalizer} + * @returns {Piece} */ load(dir, file) { const piece = this.set(new (require(join(dir, file)))(this.client, dir, file)); diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000000..8fdeff66f5 --- /dev/null +++ b/tslint.json @@ -0,0 +1,61 @@ +{ + "rules": { + "no-inferrable-types": [false], + "no-unused-expression": true, + "no-duplicate-variable": true, + "no-unused-variable": [true, {"ignore-pattern": "^_"}], + "no-shadowed-variable": true, + "comment-format": [ + true, "check-space" + ], + "indent": [ + true, "tabs" + ], + "curly": false, + "class-name": true, + "semicolon": [true], + "triple-equals": true, + "eofline": true, + "no-bitwise": false, + "no-console": [false], + "member-access": [true, "check-accessor", "check-constructor"], + "no-consecutive-blank-lines": [true], + "no-parameter-properties": true, + "one-line": [ + false + ], + "variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore"], + "interface-name": [true, "always-prefix"], + "no-conditional-assignment": true, + "use-isnan": true, + "no-trailing-whitespace": true, + "quotemark": [true, "single", "avoid-escape"], + "no-use-before-declare": true, + "whitespace": [true, + "check-branch", + "check-decl", + "check-operator", + "check-module", + "check-separator", + "check-type", + "check-typecast" + ], + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + }, + { + "call-signature": "onespace", + "index-signature": "onespace", + "parameter": "onespace", + "property-declaration": "onespace", + "variable-declaration": "onespace" + } + ] + } +} From c6cac4f4b619c9637db4ea634c5c4608fe2e93a1 Mon Sep 17 00:00:00 2001 From: kyraNET Date: Tue, 19 Sep 2017 18:24:31 +0200 Subject: [PATCH 02/12] why u don't upload --- typings/index.d.ts | 356 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 356 insertions(+) create mode 100644 typings/index.d.ts diff --git a/typings/index.d.ts b/typings/index.d.ts new file mode 100644 index 0000000000..f7f31b34fd --- /dev/null +++ b/typings/index.d.ts @@ -0,0 +1,356 @@ +declare module 'klasa' { + + import { + Client, + ClientOptions, + Collection, + Snowflake, + MessageEmbed, + MessageCollector, + WebhookClient, + User, + Message, + GuildMember, + Guild, + Role, + Channel, + TextChannel, + VoiceChannel + } from 'discord.js'; + + class KlasaClient extends Client { + constructor(options?: KlasaClientConfig); + config: KlasaClientConfig; + coreBaseDir: string; + clientBaseDir: string; + console: Console; + argResolver: ArgResolver; + commands: CommandStore; + inhibitors: InhibitorStore; + finalizers: FinalizerStore; + monitors: MonitorStore; + languages: LanguageStore; + providers: ProviderStore; + events: EventStore; + extendables: ExtendableStore; + pieceStores: Collection; + commandMessages: Collection; + permissionLevels: PermissionLevels; + commandMessageLifetime: number; + commandMessageSweep: number; + ready: false; + methods: { + Collection: typeof Collection; + Embed: typeof MessageEmbed; + MessageCollector: typeof MessageCollector; + Webhook: typeof WebhookClient; + CommandMessage: typeof CommandMessage; + util: object; + }; + settings: object; + application: object; + + static readonly invite: string; + static readonly owner: User; + public validatePermissionLevels(): PermissionLevels; + public registerStore(store: Store): KlasaClient; + public unregisterStore(store: Store): KlasaClient; + + public registerPiece(pieceName: string, store: Store): KlasaClient; + public unregisterPiece(pieceName: string): KlasaClient; + + public login(token: string): Promise; + private _ready(): void; + + public sweepCommandMessages(lifetime: number): number; + public defaultPermissionLevels: PermissionLevels; + } + + class Resolver { + public constructor(client: KlasaClient); + public client: KlasaClient; + + public msg(message: Message|Snowflake, channel: Channel): Promise; + public user(user: User|GuildMember|Message|Snowflake): Promise; + public member(member: User|GuildMember|Snowflake, guild: Guild): Promise; + public channel(channel: Channel|Snowflake): Promise; + public guild(guild: Guild|Snowflake): Promise; + public role(role: Role|Snowflake, guild: Guild): Promise; + public boolean(bool: boolean|string): Promise; + public string(string: string): Promise; + public integer(integer: string|number): Promise; + public float(number: string|number): Promise; + public url(hyperlink: string): Promise; + + static readonly regex: { + userOrMember: RegExp, + channel: RegExp, + role: RegExp, + snowflake: RegExp, + } + } + + class ArgResolver extends Resolver { + public piece(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public store(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + + public cmd(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public command(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public event(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public extendable(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public finalizer(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public inhibitor(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public monitor(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public language(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public provider(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + + public msg(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public message(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public user(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public mention(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public member(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public channel(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public guild(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public role(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public literal(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public bool(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public boolean(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public str(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public string(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public int(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public integer(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public num(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public number(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public float(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public reg(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public regex(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public regexp(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public url(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + + static minOrMax(value: number, min: number, max: number, currentUsage: Object, possible: number, repeat: boolean, msg: Message, suffix: string): boolean; + } + + class SettingResolver extends Resolver { + public user(data: any, guild: Guild, name: string): Promise; + public channel(data: any, guild: Guild, name: string): Promise; + public textchannel(data: any, guild: Guild, name: string): Promise; + public voicechannel(data: any, guild: Guild, name: string): Promise; + public guild(data: any, guild: Guild, name: string): Promise; + public role(data: any, guild: Guild, name: string): Promise; + public boolean(data: any, guild: Guild, name: string): Promise; + public string(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; + public integer(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; + public float(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; + public url(data: any, guild: Guild, name: string): Promise; + public command(data: any, guild: Guild, name: string): Promise; + public language(data: any, guild: Guild, name: string): Promise; + + static maxOrMin(guild: Guild, value: number, min: number, max: number, name: string, suffix: string): boolean; + } + + class PermissionLevels extends Collection { + public constructor(levels: number); + public requiredLevels: number; + + public addLevel(level: number, brk: boolean, check: Function); + public set(level: number, obj: PermissionLevel): this; + public isValid(): boolean; + public debug(): string; + + public run(msg: Message, min: number): permissionLevelResponse; + } + + class CommandStore extends Collection { + public constructor(client: KlasaClient); + public client: KlasaClient; + public aliases: Collection; + public coreDir: string; + public userDir: string; + public holds: Command; + public name: 'commands'; + + public readonly help: Object[]; + public get(name: string): Command; + public has(name: string): boolean; + public set(command: Command): Command; + public delete(name: Command|string): boolean; + public clear(): void; + + public load(dir: string, file: string[]): Command; + public loadAll(): Promise; + + public init(): any; + public resolve(): any; + + static walk(store: CommandStore, dir: string, subs: string[]): Promise; + } + + class Piece { + public reload(): Promise; + public unload(): void; + public enable(): Piece; + public disable(): Piece; + + static applyToClass(structure: Object, skips: string[]): void; + } + + abstract class Command { + public constructor(client: KlasaClient, dir: string, file: string[], options: CommandOptions); + public client: KlasaClient; + public type: 'command'; + + public enabled: boolean; + public name: string; + public aliases: string[]; + public runIn: string[]; + public botPerms: string[]; + public requiredSettings: string[]; + public cooldown: number; + public permLevel: number; + public description: string; + public usageDelim: string; + public extendedHelp: string; + public quotedStringSupport: boolean; + + public fullCategory: string[]; + public category: string; + public subCategory: string; + public usage: ParsedUsage; + private cooldowns: Map; + + public abstract run(msg: CommandMessage, params: any[]): Promise; + public abstract init(): any; + + public abstract reload(): any; + public abstract unload(): any; + public abstract enable(): any; + public abstract disable(): any; + } + + abstract class Event { + public constructor(client: KlasaClient, dir: string, file: string[], options: EventOptions); + public client: KlasaClient; + public type: 'event'; + + public enabled: boolean; + public name: string; + public dir: string; + public file: string; + + private _run(param: any): void; + + public abstract run(...params: any[]): void; + public abstract init(): any; + + public abstract reload(): any; + public abstract unload(): any; + public abstract enable(): any; + public abstract disable(): any; + } + + abstract class Extendable { + public constructor(client: KlasaClient, dir: string, file: string[], options: ExtendableOptions); + public client: KlasaClient; + public type: 'extendable'; + + public enabled: boolean; + public name: string; + public dir: string; + public file: string; + + public appliesTo: string[]; + public target: boolean; + + public abstract extend(...params: any[]): any; + private init(): any; + + public enable(): Piece; + public disable(): Piece; + public abstract reload(): any; + public abstract unload(): any; + } + + class Store { + init(): Promise; + load(dir: string, file: string): Piece; + loadAll(): Promise; + resolve(name: Piece|string): Piece; + + static applyToClass(structure: Object, skips: string[]): void; + } + + type KlasaClientConfig = { + prefix: string; + permissionLevels: PermissionLevels; + clientBaseDir: string; + commandMessageLifetime: number; + commandMessageSweep: number; + provider: object; + console: KlasaConsoleConfig; + consoleEvents: KlasaConsoleEvents; + ignoreBots: boolean; + ignoreSelf: boolean; + prefixMention: RegExp; + cmdPrompt: boolean; + cmdEditing: boolean; + cmdLogging: boolean; + typing: boolean; + quotedStringSupport: boolean; + readyMessage: string|Function; + string: string; + } & ClientOptions; + + type KlasaConsoleConfig = { + stdout: NodeJS.WritableStream; + stderr: NodeJS.WritableStream; + useColor: boolean; + colors: Colors; + timestamps: boolean|string; + }; + + type KlasaConsoleEvents = { + log: boolean; + warn: boolean; + error: boolean; + debug: boolean; + verbose: boolean; + wtf: boolean; + }; + + type PermissionLevel = { + break: boolean; + check: Function; + } + + type permissionLevelResponse = { + broke: boolean; + permission: boolean; + } + + type CommandOptions = { + enabled: boolean; + name: string; + aliases: string[]; + runIn: string[]; + botPerms: string[]; + requiredSettings: string[]; + cooldown: number; + permLevel: number; + description: string; + usage: string; + usageDelim: string; + extendedHelp: string; + quotedStringSupport: boolean; + } + + type EventOptions = { + enabled: boolean; + name: string; + } + + type ExtendableOptions = { + enabled: boolean; + name: string; + klasa: boolean; + } +} From b3469250d903bd3911c9898023d9870007bdc280 Mon Sep 17 00:00:00 2001 From: kyraNET Date: Tue, 19 Sep 2017 21:22:35 +0200 Subject: [PATCH 03/12] More changes --- src/lib/structures/CommandStore.js | 9 - src/lib/structures/Extendable.js | 1 - src/lib/structures/Finalizer.js | 2 +- src/lib/util/Console.js | 83 ++--- typings/index.d.ts | 574 +++++++++++++++++++++++++++-- 5 files changed, 580 insertions(+), 89 deletions(-) diff --git a/src/lib/structures/CommandStore.js b/src/lib/structures/CommandStore.js index 64f01b4ffe..c3e906f483 100644 --- a/src/lib/structures/CommandStore.js +++ b/src/lib/structures/CommandStore.js @@ -56,15 +56,6 @@ class CommandStore extends Collection { this.name = 'commands'; } - /** - * The specific command information needed to make our help command. - * @type {Array} - * @readonly - */ - get help() { - return this.map(command => ({ name: command.name, usage: command.parsedUsage.fullUsage, description: command.description })); - } - /** * Returns a command in the store if it exists by its name or by an alias. * @param {string} name A command or alias name. diff --git a/src/lib/structures/Extendable.js b/src/lib/structures/Extendable.js index e4f3ece915..74327ceb38 100644 --- a/src/lib/structures/Extendable.js +++ b/src/lib/structures/Extendable.js @@ -85,7 +85,6 @@ class Extendable { /** * The init method to apply the extend method to the Discord.js Class - * @private */ async init() { if (this.enabled) this.enable(); diff --git a/src/lib/structures/Finalizer.js b/src/lib/structures/Finalizer.js index 0e243db300..b23a99ebf8 100644 --- a/src/lib/structures/Finalizer.js +++ b/src/lib/structures/Finalizer.js @@ -18,7 +18,7 @@ class Finalizer { /** * @param {KlasaClient} client The Klasa Client * @param {string} dir The path to the core or user finalizer pieces folder - * @param {Array} file The path from the pieces folder to the finalizer file + * @param {string[]} file The path from the pieces folder to the finalizer file * @param {FinalizerOptions} [options = {}] Optional Finalizer settings */ constructor(client, dir, file, options = {}) { diff --git a/src/lib/util/Console.js b/src/lib/util/Console.js index 07bc6698b1..c55df0c86c 100644 --- a/src/lib/util/Console.js +++ b/src/lib/util/Console.js @@ -83,24 +83,25 @@ class KlasaConsole extends Console { /** * @memberof KlasaConsole * @typedef {object} Colors - Time is for the timestamp of the log, message is for the actual output. - * @property {ColorObjects} debug An object containing a message and time color object. - * @property {ColorObjects} error An object containing a message and time color object. - * @property {ColorObjects} log An object containing a message and time color object. - * @property {ColorObjects} verbose An object containing a message and time color object. - * @property {ColorObjects} warn An object containing a message and time color object. - * @property {ColorObjects} wtf An object containing a message and time Color Object. + * @property {KlasaConsoleColorObjects} debug An object containing a message and time color object. + * @property {KlasaConsoleColorObjects} error An object containing a message and time color object. + * @property {KlasaConsoleColorObjects} log An object containing a message and time color object. + * @property {KlasaConsoleColorObjects} verbose An object containing a message and time color object. + * @property {KlasaConsoleColorObjects} warn An object containing a message and time color object. + * @property {KlasaConsoleColorObjects} wtf An object containing a message and time Color Object. */ /** * @memberof KlasaConsole - * @typedef {object} ColorObjects - * @property {MessageObject} message A message object containing colors and styles. - * @property {TimeObject} time A time object containing colors and styles. + * @typedef {object} KlasaConsoleColorObjects + * @property {string} [type='log'] The method from Console this color object should call. + * @property {KlasaConsoleMessageObject} message A message object containing colors and styles. + * @property {KlasaConsoleTimeObject} time A time object containing colors and styles. */ /** * @memberof KlasaConsole - * @typedef {object} MessageObject + * @typedef {object} KlasaConsoleMessageObject * @property {BackgroundColorTypes} background The background color. Can be a basic string like "red", a hex string, or a RGB array. * @property {TextColorTypes} text The text color. Can be a basic string like "red", a hex string, or a RGB array. * @property {StyleTypes} style A style string from StyleTypes. @@ -108,7 +109,7 @@ class KlasaConsole extends Console { /** * @memberof KlasaConsole - * @typedef {object} TimeObject + * @typedef {object} KlasaConsoleTimeObject * @property {BackgroundColorTypes} background The background color. Can be a basic string like "red", a hex string, or a RGB array. * @property {TextColorTypes} text The text color. Can be a basic string like "red", a hex string, a RGB array, or HSL array. * @property {StyleTypes} style A style string from StyleTypes. @@ -181,77 +182,77 @@ class KlasaConsole extends Console { /** * Logs everything to the console/writable stream. - * @param {*} stuff The stuff we want to print. + * @param {*} data The data we want to print. * @param {string} [type="log"] The type of log, particularly useful for coloring. */ - write(stuff, type = 'log') { - stuff = KlasaConsole.flatten(stuff, this.useColors); + write(data, type = 'log') { + data = KlasaConsole.flatten(data, this.useColors); const color = this.colors[type.toLowerCase()] || {}; const message = color.message || {}; const time = color.time || {}; const timestamp = this.timestamps ? `${this.timestamp(`[${moment().format(this.timestamps)}]`, time)} ` : ''; - super[color.type || 'log'](stuff.split('\n').map(str => `${timestamp}${this.messages(str, message)}`).join('\n')); + super[color.type || 'log'](data.split('\n').map(str => `${timestamp}${this.messages(str, message)}`).join('\n')); } /** * Calls a log write with everything to the console/writable stream. - * @param {...*} stuff The stuff we want to print. - * @returns {undefined} + * @param {...*} data The data we want to print. + * @returns {void} */ - log(...stuff) { - this.write(stuff, 'log'); + log(...data) { + this.write(data, 'log'); } /** * Calls a warn write with everything to the console/writable stream. - * @param {...*} stuff The stuff we want to print. - * @returns {undefined} + * @param {...*} data The data we want to print. + * @returns {void} */ - warn(...stuff) { - this.write(stuff, 'warn'); + warn(...data) { + this.write(data, 'warn'); } /** * Calls an error write with everything to the console/writable stream. - * @param {...*} stuff The stuff we want to print. - * @returns {undefined} + * @param {...*} data The data we want to print. + * @returns {void} */ - error(...stuff) { - this.write(stuff, 'error'); + error(...data) { + this.write(data, 'error'); } /** * Calls a debug write with everything to the console/writable stream. - * @param {...*} stuff The stuff we want to print. - * @returns {undefined} + * @param {...*} data The data we want to print. + * @returns {void} */ - debug(...stuff) { - this.write(stuff, 'debug'); + debug(...data) { + this.write(data, 'debug'); } /** * Calls a verbose write with everything to the console/writable stream. - * @param {...*} stuff The stuff we want to print. - * @returns {undefined} + * @param {...*} data The data we want to print. + * @returns {void} */ - verbose(...stuff) { - this.write(stuff, 'verbose'); + verbose(...data) { + this.write(data, 'verbose'); } /** * Calls a wtf (what a terrible failure) write with everything to the console/writable stream. - * @param {...*} stuff The stuff we want to print. - * @returns {undefined} + * @param {...*} data The data we want to print. + * @returns {void} */ - wtf(...stuff) { - this.write(stuff, 'wtf'); + wtf(...data) { + this.write(data, 'wtf'); } /** * Logs everything to the console/writable stream. * @param {Date} timestamp The timestamp to maybe format * @param {string} time The time format used for coloring - * @returns {string} + * @returns {string} */ timestamp(timestamp, time) { if (!this.useColors) return timestamp; @@ -260,7 +261,7 @@ class KlasaConsole extends Console { /** * Logs everything to the console/writable stream. - * @param {string} string The stuff we want to print. + * @param {string} string The data we want to print. * @param {string} message The message format used for coloring * @returns {string} */ diff --git a/typings/index.d.ts b/typings/index.d.ts index f7f31b34fd..900677d7f2 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -77,7 +77,7 @@ declare module 'klasa' { public guild(guild: Guild|Snowflake): Promise; public role(role: Role|Snowflake, guild: Guild): Promise; public boolean(bool: boolean|string): Promise; - public string(string: string): Promise; + public string(string: string): Promise; public integer(integer: string|number): Promise; public float(number: string|number): Promise; public url(hyperlink: string): Promise; @@ -160,29 +160,101 @@ declare module 'klasa' { public run(msg: Message, min: number): permissionLevelResponse; } - class CommandStore extends Collection { - public constructor(client: KlasaClient); - public client: KlasaClient; - public aliases: Collection; - public coreDir: string; - public userDir: string; - public holds: Command; - public name: 'commands'; + // Usage + class ParsedUsage { + public constructor(client: KlasaClient, command: Command); + public readonly client: KlasaClient; + public names: string[]; + public commands: string; + public deliminatedUsage: string; + public usageString: string; + public parsedUsage: Tag[]; + public nearlyFullUsage: string; + + public fullUsage(msg: Message): string; + static parseUsage(usageString: string): Tag[]; + static tagOpen(usage: Object, char: string): Object; + static tagClose(usage: Object, char: string): Object; + static tagSpace(usage: Object, char: string): Object; + } - public readonly help: Object[]; - public get(name: string): Command; - public has(name: string): boolean; - public set(command: Command): Command; - public delete(name: Command|string): boolean; - public clear(): void; + class Possible { + public constructor(regexResults: string[]); + public name: string; + public type: string; + public min: number; + public max: number; + public regex: RegExp; - public load(dir: string, file: string[]): Command; - public loadAll(): Promise; + static resolveLimit(limit: string, type: string): number; + } - public init(): any; - public resolve(): any; + class Tag { + public constructor(members: string, count: number, required: boolean); + public type: string; + public possibles: Possible[]; - static walk(store: CommandStore, dir: string, subs: string[]): Promise; + static parseMembers(members: string, count: number): Possible[]; + static parseTrueMembers(members: string): string[]; + } + + // Util + class Colors { + public constructor(); + public CLOSE: ColorsClose; + public STYLES: ColorsStyles; + public TEXTS: ColorsTexts; + public BACKGROUNDS: ColorsBackgrounds; + + static hexToRGB(hex: string): number[]; + static hslToRGB(hsl: number[]): number[]; + static hueToRGB(p: number, q: number, t: number): number; + static formatArray(array: string[]): string|number[]; + + public format(string: string, type: { style: string|string[], background: string|number|string[], text: string|number|string[] }): string; + } + + class KlasaConsole extends Console { + public constructor(options: KlasaConsoleConfig); + public readonly stdout: NodeJS.WritableStream; + public readonly stderr: NodeJS.WritableStream; + public timestaamps: boolean|string; + public useColors: boolean; + public colors: boolean|KlasaConsoleColors; + + public write(data: any, type: string): void; + public log(...data: any[]): void; + public warn(...data: any[]): void; + public error(...data: any[]): void; + public debug(...data: any[]): void; + public verbose(...data: any[]): void; + public wtf(...data: any[]): void; + + public timestamp(timestamp: Date, time: string): string; + public messages(string: string, message: string): string; + + static flatten(data: any, useColors: boolean): string; + } + + // Structures + class CommandMessage { + public constructor(msg: Message, cmd: Command, prefix: string, prefixLength: number); + public readonly client: KlasaClient; + public msg: Message; + public cmd: Command; + public prefix: string; + public prefixLength: number; + public args: string[]; + public params: any[]; + public reprompted: false; + private _currentUsage: Object; + private _repeat: boolean; + + private validateArgs(): Promise; + private multiPossibles(possible: number, validated: boolean): Promise; + + static getArgs(cmdMsg: CommandMessage): string[]; + static getQuotedStringArgs(cmdMsg: CommandMessage): string[]; } class Piece { @@ -194,7 +266,7 @@ declare module 'klasa' { static applyToClass(structure: Object, skips: string[]): void; } - abstract class Command { + abstract class Command implements Piece { public constructor(client: KlasaClient, dir: string, file: string[], options: CommandOptions); public client: KlasaClient; public type: 'command'; @@ -221,13 +293,13 @@ declare module 'klasa' { public abstract run(msg: CommandMessage, params: any[]): Promise; public abstract init(): any; - public abstract reload(): any; + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; public abstract unload(): any; - public abstract enable(): any; - public abstract disable(): any; } - abstract class Event { + abstract class Event implements Piece { public constructor(client: KlasaClient, dir: string, file: string[], options: EventOptions); public client: KlasaClient; public type: 'event'; @@ -242,13 +314,13 @@ declare module 'klasa' { public abstract run(...params: any[]): void; public abstract init(): any; - public abstract reload(): any; + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; public abstract unload(): any; - public abstract enable(): any; - public abstract disable(): any; } - abstract class Extendable { + abstract class Extendable implements Piece { public constructor(client: KlasaClient, dir: string, file: string[], options: ExtendableOptions); public client: KlasaClient; public type: 'extendable'; @@ -262,11 +334,113 @@ declare module 'klasa' { public target: boolean; public abstract extend(...params: any[]): any; - private init(): any; + public abstract init(): any; - public enable(): Piece; - public disable(): Piece; - public abstract reload(): any; + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; + public abstract unload(): any; + } + + abstract class Finalizer implements Piece { + public constructor(client: KlasaClient, dir: string, file: string[], options: FinalizerOptions); + public client: KlasaClient; + public type: 'finalizer'; + + public enabled: boolean; + public name: string; + public dir: string; + public file: string; + + public abstract run(msg: CommandMessage, mes: Message, start: Now): void; + public abstract init(): any; + + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; + public abstract unload(): any; + } + + abstract class Inhibitor implements Piece { + public constructor(client: KlasaClient, dir: string, file: string[], options: InhibitorOptions); + public client: KlasaClient; + public type: 'inhibitor'; + + public enabled: boolean; + public name: string; + public dir: string; + public file: string; + + public abstract run(msg: Message, cmd: Command): Promise; + public abstract init(): any; + + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; + public abstract unload(): any; + } + + abstract class Language implements Piece { + public constructor(client: KlasaClient, dir: string, file: string[], options: LanguageOptions); + public client: KlasaClient; + public type: 'language'; + + public enabled: boolean; + public name: string; + public dir: string; + public file: string; + + public get(term: string, ...args: any[]): string|Function; + public abstract init(): any; + + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; + public abstract unload(): any; + } + + abstract class Monitor implements Piece { + public constructor(client: KlasaClient, dir: string, file: string[], options: MonitorOptions); + public client: KlasaClient; + public type: 'monitor'; + + public enabled: boolean; + public name: string; + public dir: string; + public file: string; + + public ignoreBots: boolean; + public ignoreSelf: boolean; + + public abstract run(msg: Message): void; + public abstract init(): any; + + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; + public abstract unload(): any; + } + + abstract class Provider implements Piece { + public constructor(client: KlasaClient, dir: string, file: string[], options: ProviderOptions); + public client: KlasaClient; + public type: 'monitor'; + + public enabled: boolean; + public name: string; + public dir: string; + public file: string; + + public description: string; + public sql: boolean; + + public abstract run(msg: Message): void; + public abstract init(): any; + public abstract shutdown(): Promise; + + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; public abstract unload(): any; } @@ -279,6 +453,154 @@ declare module 'klasa' { static applyToClass(structure: Object, skips: string[]): void; } + class CommandStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public aliases: Collection; + public coreDir: string; + public userDir: string; + public holds: Command; + public name: 'commands'; + + public get(name: string): Command; + public has(name: string): boolean; + public set(command: Command): Command; + public delete(name: Command|string): boolean; + public clear(): void; + public load(dir: string, file: string[]): Command; + public loadAll(): Promise; + + public init(): any; + public resolve(): any; + + static walk(store: CommandStore, dir: string, subs: string[]): Promise; + } + + class EventStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public coreDir: string; + public userDir: string; + public holds: Event; + public name: 'events'; + + public clear(): void; + public delete(name: Event|string): boolean; + public set(event: Event): Event; + + public init(): any; + public load(): any; + public loadAll(): Promise; + public resolve(): any; + } + + class ExtendableStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public coreDir: string; + public userDir: string; + public holds: Extendable; + public name: 'extendables'; + + public delete(name: Extendable|string): boolean; + public clear(): void; + public set(extendable: Extendable): Extendable; + + public init(): any; + public load(): any; + public loadAll(): Promise; + public resolve(): any; + } + + class FinalizerStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public coreDir: string; + public userDir: string; + public holds: Finalizer; + public name: 'finalizers'; + + public delete(name: Finalizer|string): boolean; + public run(msg: CommandMessage, mes: Message, start: Now): void; + public set(finalizer: Finalizer): Finalizer; + + public init(): any; + public load(): any; + public loadAll(): Promise; + public resolve(): any; + } + + class InhibitorStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public coreDir: string; + public userDir: string; + public holds: Inhibitor; + public name: 'inhibitors'; + + public delete(name: Inhibitor|string): boolean; + public run(msg: Message, cmd: Command, selective: boolean): void; + public set(inhibitor: Inhibitor): Inhibitor; + + public init(): any; + public load(): any; + public loadAll(): Promise; + public resolve(): any; + } + + class LanguageStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public coreDir: string; + public userDir: string; + public holds: Language; + public name: 'languages'; + + public readonly default: Language; + public delete(name: Language|string): boolean; + public set(language: Language): Language; + + public init(): any; + public load(): any; + public loadAll(): Promise; + public resolve(): any; + } + + class MonitorStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public coreDir: string; + public userDir: string; + public holds: Monitor; + public name: 'monitors'; + + public delete(name: Monitor|string): boolean; + public run(msg: Message): void; + public set(monitor: Monitor): Monitor; + + public init(): any; + public load(): any; + public loadAll(): Promise; + public resolve(): any; + } + + class ProviderStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public coreDir: string; + public userDir: string; + public holds: Provider; + public name: 'providers'; + + public delete(name: Provider|string): boolean; + public set(provider: Provider): Provider; + + public init(): any; + public load(): any; + public loadAll(): Promise; + public resolve(): any; + } + type KlasaClientConfig = { prefix: string; permissionLevels: PermissionLevels; @@ -320,12 +642,12 @@ declare module 'klasa' { type PermissionLevel = { break: boolean; check: Function; - } + }; type permissionLevelResponse = { broke: boolean; permission: boolean; - } + }; type CommandOptions = { enabled: boolean; @@ -341,16 +663,194 @@ declare module 'klasa' { usageDelim: string; extendedHelp: string; quotedStringSupport: boolean; - } + }; type EventOptions = { enabled: boolean; name: string; - } + }; type ExtendableOptions = { enabled: boolean; name: string; klasa: boolean; + }; + + type FinalizerOptions = { + enabled: boolean; + name: string; + }; + + type InhibitorOptions = { + enabled: boolean; + name: string; + spamProtection: boolean; + }; + + type LanguageOptions = { + enabled: boolean; + name: string; + }; + + type MonitorOptions = { + enabled: boolean; + name: string; + ignoreBots: boolean; + ignoreSelf: boolean; + }; + + type ProviderOptions = { + enabled: boolean; + name: string; + description: string; + sql: boolean; + }; + + type ColorsClose = { + normal: 0; + bold: 22; + dim: 22; + italic: 23; + underline: 24; + inverse: 27; + hidden: 28; + strikethrough: 29; + text: 39; + background: 49; + }; + + type ColorsStyles = { + normal: 0; + bold: 1; + dim: 2; + italic: 3; + underline: 4; + inverse: 7; + hidden: 8; + strikethrough: 9; + }; + + type ColorsTexts = { + black: 30; + red: 31; + green: 32; + yellow: 33; + blue: 34; + magenta: 35; + cyan: 36; + lightgray: 37; + lightgrey: 37; + gray: 90; + grey: 90; + lightred: 91; + lightgreen: 92; + lightyellow: 93; + lightblue: 94; + lightmagenta: 95; + lightcyan: 96; + white: 97; + }; + + type ColorsBackgrounds = { + black: 40; + red: 41; + green: 42; + yellow: 43; + blue: 44; + magenta: 45; + cyan: 46; + gray: 47; + grey: 47; + lightgray: 100; + lightgrey: 100; + lightred: 101; + lightgreen: 102; + lightyellow: 103; + lightblue: 104; + lightmagenta: 105; + lightcyan: 106; + white: 107; + }; + + type KlasaConsoleColors = { + debug: KlasaConsoleColorObjects; + error: KlasaConsoleColorObjects; + log: KlasaConsoleColorObjects; + verbose: KlasaConsoleColorObjects; + warn: KlasaConsoleColorObjects; + wtf: KlasaConsoleColorObjects; + }; + + type KlasaConsoleColorObjects = { + log: string; + message: KlasaConsoleMessageObject; + time: KlasaConsoleTimeObject; } + + type KlasaConsoleMessageObject = { + background: BackgroundColorTypes; + text: TextColorTypes; + style: StyleTypes; + } + + type KlasaConsoleTimeObject = { + background: BackgroundColorTypes; + text: TextColorTypes; + style: StyleTypes; + } + + type TextColorTypes = { + black: string; + red: string; + green: string; + yellow: string; + blue: string; + magenta: string; + cyan: string; + gray: string; + grey: string; + lightgray: string; + lightgrey: string; + lightred: string; + lightgreen: string; + lightyellow: string; + lightblue: string; + lightmagenta: string; + lightcyan: string; + white: string; + } | number[] | string[]; + + type BackgroundColorTypes = { + black: string; + red: string; + green: string; + blue: string; + magenta: string; + cyan: string; + gray: string; + grey: string; + lightgray: string; + lightgrey: string; + lightred: string; + lightgreen: string; + lightyellow: string; + lightblue: string; + lightmagenta: string; + lightcyan: string; + white: string; + } | number[] | string[]; + + type StyleTypes = { + normal: string; + bold: string; + dim: string; + italic: string; + underline: string; + inverse: string; + hidden: string; + strikethrough: string; + } + + // Simulates what performance-now's now() does. + type Now = () => number; } From 6bc0102e51d11b1ef3a9838a699c6af53817fd03 Mon Sep 17 00:00:00 2001 From: kyraNET Date: Wed, 20 Sep 2017 00:36:51 +0200 Subject: [PATCH 04/12] Added overloads to fix TS issues. --- src/lib/structures/CommandStore.js | 2 +- typings/index.d.ts | 69 +++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 7 deletions(-) diff --git a/src/lib/structures/CommandStore.js b/src/lib/structures/CommandStore.js index c3e906f483..011c3e8033 100644 --- a/src/lib/structures/CommandStore.js +++ b/src/lib/structures/CommandStore.js @@ -123,7 +123,7 @@ class CommandStore extends Collection { /** * Loads all of our commands from both the user and core directories. - * @returns {number[]} The number of commands and aliases loaded. + * @returns {number} The number of commands and aliases loaded. */ async loadAll() { this.clear(); diff --git a/typings/index.d.ts b/typings/index.d.ts index 900677d7f2..f44971f6c9 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -80,7 +80,7 @@ declare module 'klasa' { public string(string: string): Promise; public integer(integer: string|number): Promise; public float(number: string|number): Promise; - public url(hyperlink: string): Promise; + public url(hyperlink: string): Promise; static readonly regex: { userOrMember: RegExp, @@ -104,46 +104,95 @@ declare module 'klasa' { public language(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; public provider(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public msg(message: string|Message, channel: Channel): Promise; public msg(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public message(message: string|Message, channel: Channel): Promise; public message(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + + public user(user: User|GuildMember|Message|Snowflake): Promise; public user(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public mention(user: User|GuildMember|Message|Snowflake): Promise; public mention(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + + public member(member: User|GuildMember|Snowflake, guild: Guild): Promise; public member(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + + public channel(channel: Channel|Snowflake): Promise; public channel(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + + public guild(guild: Guild|Snowflake): Promise; public guild(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + + public role(role: Role|Snowflake, guild: Guild): Promise; public role(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public literal(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + + public bool(bool: boolean|string): Promise; public bool(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public boolean(bool: boolean|string): Promise; public boolean(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + + public str(string: string): Promise; public str(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public string(string: string): Promise; public string(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + + public int(integer: string|number): Promise; public int(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public integer(integer: string|number): Promise; public integer(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + + public num(number: string|number): Promise; public num(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public number(number: string|number): Promise; public number(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public float(number: string|number): Promise; public float(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public reg(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; public regex(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; public regexp(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + + public url(hyperlink: string): Promise; public url(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; static minOrMax(value: number, min: number, max: number, currentUsage: Object, possible: number, repeat: boolean, msg: Message, suffix: string): boolean; } class SettingResolver extends Resolver { + public command(data: any, guild: Guild, name: string): Promise; + public language(data: any, guild: Guild, name: string): Promise; + + public user(user: User|GuildMember|Message|Snowflake): Promise; public user(data: any, guild: Guild, name: string): Promise; + + public channel(channel: Channel|Snowflake): Promise; public channel(data: any, guild: Guild, name: string): Promise; + public textchannel(data: any, guild: Guild, name: string): Promise; public voicechannel(data: any, guild: Guild, name: string): Promise; + + public guild(guild: Guild|Snowflake): Promise; public guild(data: any, guild: Guild, name: string): Promise; + + public role(role: Role|Snowflake, guild: Guild): Promise; public role(data: any, guild: Guild, name: string): Promise; + + public boolean(bool: boolean|string): Promise; public boolean(data: any, guild: Guild, name: string): Promise; + + public string(string: string): Promise; public string(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; + + public integer(integer: string|number): Promise; public integer(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; + + public float(number: string|number): Promise; public float(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; + + public url(hyperlink: string): Promise; public url(data: any, guild: Guild, name: string): Promise; - public command(data: any, guild: Guild, name: string): Promise; - public language(data: any, guild: Guild, name: string): Promise; static maxOrMin(guild: Guild, value: number, min: number, max: number, name: string, suffix: string): boolean; } @@ -446,7 +495,7 @@ declare module 'klasa' { class Store { init(): Promise; - load(dir: string, file: string): Piece; + load(dir: string, file: string|string[]): Piece; loadAll(): Promise; resolve(name: Piece|string): Piece; @@ -464,11 +513,12 @@ declare module 'klasa' { public get(name: string): Command; public has(name: string): boolean; + public set(key: string, value: Command): this; public set(command: Command): Command; public delete(name: Command|string): boolean; public clear(): void; public load(dir: string, file: string[]): Command; - public loadAll(): Promise; + public loadAll(): Promise; public init(): any; public resolve(): any; @@ -476,7 +526,7 @@ declare module 'klasa' { static walk(store: CommandStore, dir: string, subs: string[]): Promise; } - class EventStore extends Collection implements Store { + class EventStore extends Collection implements Store { public constructor(client: KlasaClient); public client: KlasaClient; public coreDir: string; @@ -486,6 +536,7 @@ declare module 'klasa' { public clear(): void; public delete(name: Event|string): boolean; + public set(key: string, value: Event): this; public set(event: Event): Event; public init(): any; @@ -504,6 +555,7 @@ declare module 'klasa' { public delete(name: Extendable|string): boolean; public clear(): void; + public set(key: string, value: Extendable): this; public set(extendable: Extendable): Extendable; public init(): any; @@ -522,6 +574,7 @@ declare module 'klasa' { public delete(name: Finalizer|string): boolean; public run(msg: CommandMessage, mes: Message, start: Now): void; + public set(key: string, value: Finalizer): this; public set(finalizer: Finalizer): Finalizer; public init(): any; @@ -540,6 +593,7 @@ declare module 'klasa' { public delete(name: Inhibitor|string): boolean; public run(msg: Message, cmd: Command, selective: boolean): void; + public set(key: string, value: Inhibitor): this; public set(inhibitor: Inhibitor): Inhibitor; public init(): any; @@ -558,6 +612,7 @@ declare module 'klasa' { public readonly default: Language; public delete(name: Language|string): boolean; + public set(key: string, value: Language): this; public set(language: Language): Language; public init(): any; @@ -576,6 +631,7 @@ declare module 'klasa' { public delete(name: Monitor|string): boolean; public run(msg: Message): void; + public set(key: string, value: Monitor): this; public set(monitor: Monitor): Monitor; public init(): any; @@ -593,6 +649,7 @@ declare module 'klasa' { public name: 'providers'; public delete(name: Provider|string): boolean; + public set(key: string, value: Provider): this; public set(provider: Provider): Provider; public init(): any; From 05b149b3cde5d2852a4affd55f863446e10a2a9f Mon Sep 17 00:00:00 2001 From: kyraNET Date: Wed, 20 Sep 2017 02:13:40 +0200 Subject: [PATCH 05/12] Multiple bugfixes, all typings for all pieces. --- src/index.js | 4 +- src/lib/settings/SQL.js | 8 +- src/lib/settings/SchemaManager.js | 3 +- src/lib/settings/SettingGateway.js | 2 +- typings/index.d.ts | 343 +++++++++++++++++------------ 5 files changed, 218 insertions(+), 142 deletions(-) diff --git a/src/index.js b/src/index.js index 56791f2ef3..27289acd13 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,8 @@ module.exports = { Client: require('./lib/Client'), util: require('./lib/util/util'), - colors: require('./lib/util/util'), - console: require('./lib/util/util'), + Colors: require('./lib/util/Colors'), + Console: require('./lib/util/Console'), Command: require('./lib/structures/Command'), CommandMessage: require('./lib/structures/CommandMessage'), Event: require('./lib/structures/Event'), diff --git a/src/lib/settings/SQL.js b/src/lib/settings/SQL.js index bba60ec244..a90289d77b 100644 --- a/src/lib/settings/SQL.js +++ b/src/lib/settings/SQL.js @@ -53,7 +53,7 @@ class SQL { buildSQLSchema(schema) { const output = ['id TEXT NOT NULL UNIQUE']; for (const [key, value] of Object.entries(schema)) { - output.push(`${key} ${this.buildSingleSQLSchema(key, value)}`); + output.push(`${key} ${this.buildSingleSQLSchema(value)}`); } return output; } @@ -74,7 +74,11 @@ class SQL { */ deserializer(data) { const deserialize = this.deserializeKeys; - for (let i = 0; i < deserialize.length; i++) data[deserialize[i]] = JSON.parse(data[deserialize[i]]); + for (let i = 0; i < deserialize.length; i++) { + if (typeof data[deserialize[i]] !== 'undefined') { + data[deserialize[i]] = JSON.parse(data[deserialize[i]]); + } + } } /** diff --git a/src/lib/settings/SchemaManager.js b/src/lib/settings/SchemaManager.js index 662dd11228..97e1c92d3c 100644 --- a/src/lib/settings/SchemaManager.js +++ b/src/lib/settings/SchemaManager.js @@ -63,7 +63,7 @@ class SchemaManager extends CacheManager { /** * @typedef {Object} AddOptions * @property {string} type The type for the key. - * @property {string} default The default value for the key. + * @property {any} default The default value for the key. * @property {number} min The min value for the key (String.length for String, value for number). * @property {number} max The max value for the key (String.length for String, value for number). * @property {boolean} array Whether the key should be stored as Array or not. @@ -123,6 +123,7 @@ class SchemaManager extends CacheManager { * Modify all configurations. Do NOT use this directly. * @param {string} action Whether reset, add, or delete. * @param {string} key The key to update. + * @private * @returns {void} */ async force(action, key) { diff --git a/src/lib/settings/SettingGateway.js b/src/lib/settings/SettingGateway.js index af654f09bf..1f1a1bda14 100644 --- a/src/lib/settings/SettingGateway.js +++ b/src/lib/settings/SettingGateway.js @@ -115,7 +115,7 @@ class SettingGateway extends SchemaManager { /** * Updates an entry. * @param {(Object|string)} input An object containing a id property, like Discord.js objects, or a string. - * @param {(Object|string)} [guild=null] A Guild resolvable, useful for when the instance of SG doesn't aim for Guild settings. + * @param {external:Guild} [guild=null] A Guild resolvable, useful for when the instance of SG doesn't aim for Guild settings. * @returns {Object} */ async getResolved(input, guild = null) { diff --git a/typings/index.d.ts b/typings/index.d.ts index f44971f6c9..6c4a3303bb 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -18,7 +18,9 @@ declare module 'klasa' { VoiceChannel } from 'discord.js'; - class KlasaClient extends Client { + export const version: string; + + export class KlasaClient extends Client { constructor(options?: KlasaClientConfig); config: KlasaClientConfig; coreBaseDir: string; @@ -50,8 +52,8 @@ declare module 'klasa' { settings: object; application: object; - static readonly invite: string; - static readonly owner: User; + public static readonly invite: string; + public static readonly owner: User; public validatePermissionLevels(): PermissionLevels; public registerStore(store: Store): KlasaClient; public unregisterStore(store: Store): KlasaClient; @@ -66,7 +68,17 @@ declare module 'klasa' { public defaultPermissionLevels: PermissionLevels; } - class Resolver { + export class util { + public static codeBlock(lang: string, expression: string): string; + public static clean(text: string): string; + private static initClean(client: KlasaClient): void; + public static toTitleCase(str: string): string; + public static newError(error: Error, code: number): Error; + public static regExpEsc(str: string): string; + public static applyToClass(base: object, structure: object, skips: string[]): void; + } + + export class Resolver { public constructor(client: KlasaClient); public client: KlasaClient; @@ -82,7 +94,7 @@ declare module 'klasa' { public float(number: string|number): Promise; public url(hyperlink: string): Promise; - static readonly regex: { + public static readonly regex: { userOrMember: RegExp, channel: RegExp, role: RegExp, @@ -90,77 +102,77 @@ declare module 'klasa' { } } - class ArgResolver extends Resolver { - public piece(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; - public store(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + export class ArgResolver extends Resolver { + public piece(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public store(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public cmd(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; - public command(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; - public event(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; - public extendable(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; - public finalizer(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; - public inhibitor(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; - public monitor(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; - public language(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; - public provider(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public cmd(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public command(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public event(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public extendable(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public finalizer(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public inhibitor(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public monitor(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public language(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public provider(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public msg(message: string|Message, channel: Channel): Promise; - public msg(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public msg(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public message(message: string|Message, channel: Channel): Promise; - public message(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public message(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public user(user: User|GuildMember|Message|Snowflake): Promise; - public user(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public user(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public mention(user: User|GuildMember|Message|Snowflake): Promise; - public mention(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public mention(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public member(member: User|GuildMember|Snowflake, guild: Guild): Promise; - public member(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public member(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public channel(channel: Channel|Snowflake): Promise; - public channel(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public channel(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public guild(guild: Guild|Snowflake): Promise; - public guild(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public guild(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public role(role: Role|Snowflake, guild: Guild): Promise; - public role(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public role(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public literal(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public literal(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public bool(bool: boolean|string): Promise; - public bool(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public bool(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public boolean(bool: boolean|string): Promise; - public boolean(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public boolean(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public str(string: string): Promise; - public str(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public str(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public string(string: string): Promise; - public string(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public string(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public int(integer: string|number): Promise; - public int(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public int(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public integer(integer: string|number): Promise; - public integer(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public integer(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public num(number: string|number): Promise; - public num(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public num(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public number(number: string|number): Promise; - public number(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public number(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public float(number: string|number): Promise; - public float(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public float(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public reg(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; - public regex(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; - public regexp(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public reg(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public regex(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public regexp(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public url(hyperlink: string): Promise; - public url(arg: string, currentUsage: Object, possible: number, repeat: boolean, msg: Message): Promise; + public url(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - static minOrMax(value: number, min: number, max: number, currentUsage: Object, possible: number, repeat: boolean, msg: Message, suffix: string): boolean; + public static minOrMax(value: number, min: number, max: number, currentUsage: object, possible: number, repeat: boolean, msg: Message, suffix: string): boolean; } - class SettingResolver extends Resolver { + export class SettingResolver extends Resolver { public command(data: any, guild: Guild, name: string): Promise; public language(data: any, guild: Guild, name: string): Promise; @@ -194,10 +206,10 @@ declare module 'klasa' { public url(hyperlink: string): Promise; public url(data: any, guild: Guild, name: string): Promise; - static maxOrMin(guild: Guild, value: number, min: number, max: number, name: string, suffix: string): boolean; + public static maxOrMin(guild: Guild, value: number, min: number, max: number, name: string, suffix: string): boolean; } - class PermissionLevels extends Collection { + export class PermissionLevels extends Collection { public constructor(levels: number); public requiredLevels: number; @@ -210,7 +222,7 @@ declare module 'klasa' { } // Usage - class ParsedUsage { + export class ParsedUsage { public constructor(client: KlasaClient, command: Command); public readonly client: KlasaClient; public names: string[]; @@ -221,13 +233,13 @@ declare module 'klasa' { public nearlyFullUsage: string; public fullUsage(msg: Message): string; - static parseUsage(usageString: string): Tag[]; - static tagOpen(usage: Object, char: string): Object; - static tagClose(usage: Object, char: string): Object; - static tagSpace(usage: Object, char: string): Object; + public static parseUsage(usageString: string): Tag[]; + public static tagOpen(usage: object, char: string): object; + public static tagClose(usage: object, char: string): object; + public static tagSpace(usage: object, char: string): object; } - class Possible { + export class Possible { public constructor(regexResults: string[]); public name: string; public type: string; @@ -235,30 +247,111 @@ declare module 'klasa' { public max: number; public regex: RegExp; - static resolveLimit(limit: string, type: string): number; + public static resolveLimit(limit: string, type: string): number; } - class Tag { + export class Tag { public constructor(members: string, count: number, required: boolean); public type: string; public possibles: Possible[]; - static parseMembers(members: string, count: number): Possible[]; - static parseTrueMembers(members: string): string[]; + public static parseMembers(members: string, count: number): Possible[]; + public static parseTrueMembers(members: string): string[]; + } + + // Settings + export class CacheManager { + public constructor(client: KlasaClient); + public readonly cacheEngine: string; + public data: Collection|Provider; + + public get(key: string): object; + public getAll(): object[]; + public set(key: string, value: object): any; + public delete(key: string): any; + } + + export class SchemaManager extends CacheManager { + public constructor(client: KlasaClient); + public schema: object; + public defaults: object; + + public initSchema(): Promise; + public validateSchema(schema: object): void; + public add(key: string, options: AddOptions, force: boolean): Promise; + public remove(key: string, force: boolean): Promise; + private force(action: string, key: string): Promise; + } + + export class SettingGateway extends SchemaManager { + constructor(store: SettingCache, type: T, validateFunction: Function, schema: object); + public readonly store: SettingCache; + public type: T; + public engine: string; + public sql: SQL; + public validate: Function; + public defaultDataSchema: object; + + public initSchema(): Promise; + public create(input: object|string): Promise; + public destroy(input: string): Promise; + public get(input: string): object; + public getResolved(input: object|string, guild: SettingGatewayGuildResolvable): Promise; + public sync(input: object|string): Promise; + public reset(input: object|string, key: string): Promise; + public update(input: object|string, object: object, guild: SettingGatewayGuildResolvable): object; + public ensureCreate(target: object|string): true; + public updateArray(input: object|string, action: 'add'|'remove', key: string, data: any): Promise; + private _resolveGuild(guild: Guild|TextChannel|VoiceChannel|Snowflake): Guild; + + public readonly client: KlasaClient; + public readonly resolver: Resolver; + public readonly provider: Provider; + } + + export class SettingCache { + constructor(client: KlasaClient); + public client: KlasaClient; + public resolver: SettingResolver; + public guilds: SettingGateway<'guilds'>; + + public add(name: T, validateFunction: Function, schema: object): Promise>; + public validate(resolver: SettingResolver, guild: object|string); + + public readonly defaultDataSchema: { prefix: SchemaPiece, language: SchemaPiece, disabledCommands: SchemaPiece }; + } + + export class SQL { + constructor(client: KlasaClient, gateway: SettingGateway); + public readonly client: KlasaClient; + public readonly gateway: SettingGateway; + + public buildSingleSQLSchema(value: SchemaPiece): string; + public buildSQLSchema(schema: object): string[]; + + public initDeserialize(): void; + public deserializer(data: SchemaPiece): void; + public updateColumns(schema: object, defaults: object, key: string): Promise; + + public readonly constants: object; + public readonly sanitizer: Function; + public readonly schema: object; + public readonly defaults: object; + public readonly provider: Provider; } // Util - class Colors { + export class Colors { public constructor(); public CLOSE: ColorsClose; public STYLES: ColorsStyles; public TEXTS: ColorsTexts; public BACKGROUNDS: ColorsBackgrounds; - static hexToRGB(hex: string): number[]; - static hslToRGB(hsl: number[]): number[]; - static hueToRGB(p: number, q: number, t: number): number; - static formatArray(array: string[]): string|number[]; + public static hexToRGB(hex: string): number[]; + public static hslToRGB(hsl: number[]): number[]; + public static hueToRGB(p: number, q: number, t: number): number; + public static formatArray(array: string[]): string|number[]; public format(string: string, type: { style: string|string[], background: string|number|string[], text: string|number|string[] }): string; } @@ -282,11 +375,13 @@ declare module 'klasa' { public timestamp(timestamp: Date, time: string): string; public messages(string: string, message: string): string; - static flatten(data: any, useColors: boolean): string; + public static flatten(data: any, useColors: boolean): string; } + export { KlasaConsole as Console } + // Structures - class CommandMessage { + export class CommandMessage { public constructor(msg: Message, cmd: Command, prefix: string, prefixLength: number); public readonly client: KlasaClient; public msg: Message; @@ -296,26 +391,26 @@ declare module 'klasa' { public args: string[]; public params: any[]; public reprompted: false; - private _currentUsage: Object; + private _currentUsage: object; private _repeat: boolean; private validateArgs(): Promise; private multiPossibles(possible: number, validated: boolean): Promise; - static getArgs(cmdMsg: CommandMessage): string[]; - static getQuotedStringArgs(cmdMsg: CommandMessage): string[]; + public static getArgs(cmdMsg: CommandMessage): string[]; + public static getQuotedStringArgs(cmdMsg: CommandMessage): string[]; } - class Piece { + export class Piece { public reload(): Promise; public unload(): void; public enable(): Piece; public disable(): Piece; - static applyToClass(structure: Object, skips: string[]): void; + public static applyToClass(structure: object, skips: string[]): void; } - abstract class Command implements Piece { + export abstract class Command implements Piece { public constructor(client: KlasaClient, dir: string, file: string[], options: CommandOptions); public client: KlasaClient; public type: 'command'; @@ -339,7 +434,7 @@ declare module 'klasa' { public usage: ParsedUsage; private cooldowns: Map; - public abstract run(msg: CommandMessage, params: any[]): Promise; + public abstract run(msg: ProxyCommand, params: any[]): Promise; public abstract init(): any; public abstract enable(): Piece; @@ -348,7 +443,7 @@ declare module 'klasa' { public abstract unload(): any; } - abstract class Event implements Piece { + export abstract class Event implements Piece { public constructor(client: KlasaClient, dir: string, file: string[], options: EventOptions); public client: KlasaClient; public type: 'event'; @@ -369,7 +464,7 @@ declare module 'klasa' { public abstract unload(): any; } - abstract class Extendable implements Piece { + export abstract class Extendable implements Piece { public constructor(client: KlasaClient, dir: string, file: string[], options: ExtendableOptions); public client: KlasaClient; public type: 'extendable'; @@ -391,7 +486,7 @@ declare module 'klasa' { public abstract unload(): any; } - abstract class Finalizer implements Piece { + export abstract class Finalizer implements Piece { public constructor(client: KlasaClient, dir: string, file: string[], options: FinalizerOptions); public client: KlasaClient; public type: 'finalizer'; @@ -410,7 +505,7 @@ declare module 'klasa' { public abstract unload(): any; } - abstract class Inhibitor implements Piece { + export abstract class Inhibitor implements Piece { public constructor(client: KlasaClient, dir: string, file: string[], options: InhibitorOptions); public client: KlasaClient; public type: 'inhibitor'; @@ -429,7 +524,7 @@ declare module 'klasa' { public abstract unload(): any; } - abstract class Language implements Piece { + export abstract class Language implements Piece { public constructor(client: KlasaClient, dir: string, file: string[], options: LanguageOptions); public client: KlasaClient; public type: 'language'; @@ -448,7 +543,7 @@ declare module 'klasa' { public abstract unload(): any; } - abstract class Monitor implements Piece { + export abstract class Monitor implements Piece { public constructor(client: KlasaClient, dir: string, file: string[], options: MonitorOptions); public client: KlasaClient; public type: 'monitor'; @@ -470,7 +565,7 @@ declare module 'klasa' { public abstract unload(): any; } - abstract class Provider implements Piece { + export abstract class Provider implements Piece { public constructor(client: KlasaClient, dir: string, file: string[], options: ProviderOptions); public client: KlasaClient; public type: 'monitor'; @@ -493,16 +588,16 @@ declare module 'klasa' { public abstract unload(): any; } - class Store { + export class Store { init(): Promise; load(dir: string, file: string|string[]): Piece; loadAll(): Promise; resolve(name: Piece|string): Piece; - static applyToClass(structure: Object, skips: string[]): void; + public static applyToClass(structure: object, skips: string[]): void; } - class CommandStore extends Collection implements Store { + export class CommandStore extends Collection implements Store { public constructor(client: KlasaClient); public client: KlasaClient; public aliases: Collection; @@ -523,10 +618,10 @@ declare module 'klasa' { public init(): any; public resolve(): any; - static walk(store: CommandStore, dir: string, subs: string[]): Promise; + public static walk(store: CommandStore, dir: string, subs: string[]): Promise; } - class EventStore extends Collection implements Store { + export class EventStore extends Collection implements Store { public constructor(client: KlasaClient); public client: KlasaClient; public coreDir: string; @@ -545,7 +640,7 @@ declare module 'klasa' { public resolve(): any; } - class ExtendableStore extends Collection implements Store { + export class ExtendableStore extends Collection implements Store { public constructor(client: KlasaClient); public client: KlasaClient; public coreDir: string; @@ -564,7 +659,7 @@ declare module 'klasa' { public resolve(): any; } - class FinalizerStore extends Collection implements Store { + export class FinalizerStore extends Collection implements Store { public constructor(client: KlasaClient); public client: KlasaClient; public coreDir: string; @@ -583,7 +678,7 @@ declare module 'klasa' { public resolve(): any; } - class InhibitorStore extends Collection implements Store { + export class InhibitorStore extends Collection implements Store { public constructor(client: KlasaClient); public client: KlasaClient; public coreDir: string; @@ -602,7 +697,7 @@ declare module 'klasa' { public resolve(): any; } - class LanguageStore extends Collection implements Store { + export class LanguageStore extends Collection implements Store { public constructor(client: KlasaClient); public client: KlasaClient; public coreDir: string; @@ -621,7 +716,7 @@ declare module 'klasa' { public resolve(): any; } - class MonitorStore extends Collection implements Store { + export class MonitorStore extends Collection implements Store { public constructor(client: KlasaClient); public client: KlasaClient; public coreDir: string; @@ -640,7 +735,7 @@ declare module 'klasa' { public resolve(): any; } - class ProviderStore extends Collection implements Store { + export class ProviderStore extends Collection implements Store { public constructor(client: KlasaClient); public client: KlasaClient; public coreDir: string; @@ -706,6 +801,8 @@ declare module 'klasa' { permission: boolean; }; + type ProxyCommand = CommandMessage & Message; + type CommandOptions = { enabled: boolean; name: string; @@ -763,6 +860,26 @@ declare module 'klasa' { sql: boolean; }; + type AddOptions = { + type: string; + default: any; + min: number; + max: number; + array: boolean; + sql: string; + } + + type SchemaPiece = { + type: string; + default: any; + min: number; + max: number; + array: boolean; + sql: string; + } + + type SettingGatewayGuildResolvable = Guild|Channel|Message|Role|Snowflake; + type ColorsClose = { normal: 0; bold: 22; @@ -856,57 +973,11 @@ declare module 'klasa' { style: StyleTypes; } - type TextColorTypes = { - black: string; - red: string; - green: string; - yellow: string; - blue: string; - magenta: string; - cyan: string; - gray: string; - grey: string; - lightgray: string; - lightgrey: string; - lightred: string; - lightgreen: string; - lightyellow: string; - lightblue: string; - lightmagenta: string; - lightcyan: string; - white: string; - } | number[] | string[]; - - type BackgroundColorTypes = { - black: string; - red: string; - green: string; - blue: string; - magenta: string; - cyan: string; - gray: string; - grey: string; - lightgray: string; - lightgrey: string; - lightred: string; - lightgreen: string; - lightyellow: string; - lightblue: string; - lightmagenta: string; - lightcyan: string; - white: string; - } | number[] | string[]; - - type StyleTypes = { - normal: string; - bold: string; - dim: string; - italic: string; - underline: string; - inverse: string; - hidden: string; - strikethrough: string; - } + type TextColorTypes = 'black'|'red'|'green'|'yellow'|'blue'|'magenta'|'cyan'|'gray'|'grey'|'lightgray'|'lightgrey'|'lightred'|'lightgreen'|'lightyellow'|'lightblue'|'lightmagenta'|'lightcyan'|'white'|number[]|string[]; + + type BackgroundColorTypes = 'black'|'red'|'green'|'blue'|'magenta'|'cyan'|'gray'|'grey'|'lightgray'|'lightgrey'|'lightred'|'lightgreen'|'lightyellow'|'lightblue'|'lightmagenta'|'lightcyan'|'white'|number[]|string[]; + + type StyleTypes = 'normal'|'bold'|'dim'|'italic'|'underline'|'inverse'|'hidden'|'strikethrough'; // Simulates what performance-now's now() does. type Now = () => number; From 15787fd69e3835f2ef89562ed1f8b48ffcd92019 Mon Sep 17 00:00:00 2001 From: kyraNET Date: Wed, 20 Sep 2017 02:34:34 +0200 Subject: [PATCH 06/12] Ao's requested change --- src/lib/structures/Finalizer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/structures/Finalizer.js b/src/lib/structures/Finalizer.js index b23a99ebf8..8ed3d2b510 100644 --- a/src/lib/structures/Finalizer.js +++ b/src/lib/structures/Finalizer.js @@ -18,7 +18,7 @@ class Finalizer { /** * @param {KlasaClient} client The Klasa Client * @param {string} dir The path to the core or user finalizer pieces folder - * @param {string[]} file The path from the pieces folder to the finalizer file + * @param {string} file The path from the pieces folder to the finalizer file * @param {FinalizerOptions} [options = {}] Optional Finalizer settings */ constructor(client, dir, file, options = {}) { From 7e5b4c5dfaa007505f936a9e6e11034b8f713a55 Mon Sep 17 00:00:00 2001 From: kyraNET Date: Wed, 20 Sep 2017 11:06:56 +0200 Subject: [PATCH 07/12] Added typings for extended classes --- typings/index.d.ts | 81 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 75 insertions(+), 6 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 6c4a3303bb..c250450ebf 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -8,19 +8,21 @@ declare module 'klasa' { MessageEmbed, MessageCollector, WebhookClient, - User, - Message, + User as DiscordUser, + Message as DiscordMessage, GuildMember, - Guild, + Guild as DiscordGuild, Role, Channel, - TextChannel, - VoiceChannel + TextChannel as DiscordTextChannel, + VoiceChannel, + DMChannel as DiscordDMChannel, + GroupDMChannel as DiscordGroupDMChannel } from 'discord.js'; export const version: string; - export class KlasaClient extends Client { + class KlasaClient extends Client { constructor(options?: KlasaClientConfig); config: KlasaClientConfig; coreBaseDir: string; @@ -68,6 +70,8 @@ declare module 'klasa' { public defaultPermissionLevels: PermissionLevels; } + export { KlasaClient as Client } + export class util { public static codeBlock(lang: string, expression: string): string; public static clean(text: string): string; @@ -979,6 +983,71 @@ declare module 'klasa' { type StyleTypes = 'normal'|'bold'|'dim'|'italic'|'underline'|'inverse'|'hidden'|'strikethrough'; + // Extended classes + export type Message = { + guild: Guild; + guildSettings: object; + hasAtLeastPermissionLevel: Promise; + language: Language; + reactable: Boolean; + send: Promise; + sendCode: Promise; + sendEmbed: Promise; + sendMessage: Promise; + sendFile: Promise; + sendFiles: Promise; + usableCommands: Promise> + } & DiscordMessage; + + export type Guild = { + language: Language; + settings: object; + } & DiscordGuild; + + export type User = { + sendCode: Promise; + sendEmbed: Promise; + sendMessage: Promise; + sendFile: Promise; + sendFiles: Promise; + } & DiscordUser; + + export type TextChannel = { + attachable: boolean; + embedable: boolean; + postable: boolean; + language: Language; + sendCode: Promise; + sendEmbed: Promise; + sendMessage: Promise; + sendFile: Promise; + sendFiles: Promise; + } & DiscordTextChannel; + + export type DMChannel = { + attachable: boolean; + embedable: boolean; + postable: boolean; + language: Language; + sendCode: Promise; + sendEmbed: Promise; + sendMessage: Promise; + sendFile: Promise; + sendFiles: Promise; + } & DiscordDMChannel; + + export type GroupDMChannel = { + attachable: boolean; + embedable: boolean; + postable: boolean; + language: Language; + sendCode: Promise; + sendEmbed: Promise; + sendMessage: Promise; + sendFile: Promise; + sendFiles: Promise; + } & DiscordGroupDMChannel; + // Simulates what performance-now's now() does. type Now = () => number; } From 6c7ec0dae45f30b7e45f00c939ed7adbc7443d01 Mon Sep 17 00:00:00 2001 From: kyraNET Date: Wed, 20 Sep 2017 11:09:48 +0200 Subject: [PATCH 08/12] Fix Now, it should have been number. --- src/lib/structures/Finalizer.js | 2 +- typings/index.d.ts | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/lib/structures/Finalizer.js b/src/lib/structures/Finalizer.js index 8ed3d2b510..5520bee127 100644 --- a/src/lib/structures/Finalizer.js +++ b/src/lib/structures/Finalizer.js @@ -62,7 +62,7 @@ class Finalizer { * The run method to be overwritten in actual finalizers * @param {CommandMessage} msg The command message mapped on top of the message used to trigger this finalizer * @param {external:Message} mes The bot's response message, if one is returned - * @param {external:Now} start The performance now start time including all command overhead + * @param {number} start The performance now start time including all command overhead * @abstract * @returns {void} */ diff --git a/typings/index.d.ts b/typings/index.d.ts index c250450ebf..45099eb1b6 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -500,7 +500,7 @@ declare module 'klasa' { public dir: string; public file: string; - public abstract run(msg: CommandMessage, mes: Message, start: Now): void; + public abstract run(msg: CommandMessage, mes: Message, start: number): void; public abstract init(): any; public abstract enable(): Piece; @@ -672,7 +672,7 @@ declare module 'klasa' { public name: 'finalizers'; public delete(name: Finalizer|string): boolean; - public run(msg: CommandMessage, mes: Message, start: Now): void; + public run(msg: CommandMessage, mes: Message, start: number): void; public set(key: string, value: Finalizer): this; public set(finalizer: Finalizer): Finalizer; @@ -1048,6 +1048,4 @@ declare module 'klasa' { sendFiles: Promise; } & DiscordGroupDMChannel; - // Simulates what performance-now's now() does. - type Now = () => number; } From 3f03fe98fc38e200a9596f332a809ac45ff9d337 Mon Sep 17 00:00:00 2001 From: kyraNET Date: Wed, 20 Sep 2017 11:14:54 +0200 Subject: [PATCH 09/12] I don't think they should be exported... they're not in Klasa. --- typings/index.d.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 45099eb1b6..f29c35b031 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -984,7 +984,7 @@ declare module 'klasa' { type StyleTypes = 'normal'|'bold'|'dim'|'italic'|'underline'|'inverse'|'hidden'|'strikethrough'; // Extended classes - export type Message = { + type Message = { guild: Guild; guildSettings: object; hasAtLeastPermissionLevel: Promise; @@ -999,12 +999,12 @@ declare module 'klasa' { usableCommands: Promise> } & DiscordMessage; - export type Guild = { + type Guild = { language: Language; settings: object; } & DiscordGuild; - export type User = { + type User = { sendCode: Promise; sendEmbed: Promise; sendMessage: Promise; @@ -1012,7 +1012,7 @@ declare module 'klasa' { sendFiles: Promise; } & DiscordUser; - export type TextChannel = { + type TextChannel = { attachable: boolean; embedable: boolean; postable: boolean; @@ -1024,7 +1024,7 @@ declare module 'klasa' { sendFiles: Promise; } & DiscordTextChannel; - export type DMChannel = { + type DMChannel = { attachable: boolean; embedable: boolean; postable: boolean; @@ -1036,7 +1036,7 @@ declare module 'klasa' { sendFiles: Promise; } & DiscordDMChannel; - export type GroupDMChannel = { + type GroupDMChannel = { attachable: boolean; embedable: boolean; postable: boolean; From 3bcca7e882312c06f78fa9bda4f3890574023bb2 Mon Sep 17 00:00:00 2001 From: kyraNET Date: Wed, 20 Sep 2017 17:12:42 +0200 Subject: [PATCH 10/12] Added events, Settings type. --- typings/index.d.ts | 2186 +++++++++++++++++++++++--------------------- 1 file changed, 1139 insertions(+), 1047 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index f29c35b031..05205dc134 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1,1051 +1,1143 @@ declare module 'klasa' { - import { - Client, - ClientOptions, - Collection, - Snowflake, - MessageEmbed, - MessageCollector, - WebhookClient, - User as DiscordUser, - Message as DiscordMessage, - GuildMember, - Guild as DiscordGuild, - Role, - Channel, - TextChannel as DiscordTextChannel, - VoiceChannel, - DMChannel as DiscordDMChannel, - GroupDMChannel as DiscordGroupDMChannel - } from 'discord.js'; - - export const version: string; - - class KlasaClient extends Client { - constructor(options?: KlasaClientConfig); - config: KlasaClientConfig; - coreBaseDir: string; - clientBaseDir: string; - console: Console; - argResolver: ArgResolver; - commands: CommandStore; - inhibitors: InhibitorStore; - finalizers: FinalizerStore; - monitors: MonitorStore; - languages: LanguageStore; - providers: ProviderStore; - events: EventStore; - extendables: ExtendableStore; - pieceStores: Collection; - commandMessages: Collection; - permissionLevels: PermissionLevels; - commandMessageLifetime: number; - commandMessageSweep: number; - ready: false; - methods: { - Collection: typeof Collection; - Embed: typeof MessageEmbed; - MessageCollector: typeof MessageCollector; - Webhook: typeof WebhookClient; - CommandMessage: typeof CommandMessage; - util: object; - }; - settings: object; - application: object; - - public static readonly invite: string; - public static readonly owner: User; - public validatePermissionLevels(): PermissionLevels; - public registerStore(store: Store): KlasaClient; - public unregisterStore(store: Store): KlasaClient; - - public registerPiece(pieceName: string, store: Store): KlasaClient; - public unregisterPiece(pieceName: string): KlasaClient; - - public login(token: string): Promise; - private _ready(): void; - - public sweepCommandMessages(lifetime: number): number; - public defaultPermissionLevels: PermissionLevels; - } - - export { KlasaClient as Client } - - export class util { - public static codeBlock(lang: string, expression: string): string; - public static clean(text: string): string; - private static initClean(client: KlasaClient): void; - public static toTitleCase(str: string): string; - public static newError(error: Error, code: number): Error; - public static regExpEsc(str: string): string; - public static applyToClass(base: object, structure: object, skips: string[]): void; - } - - export class Resolver { - public constructor(client: KlasaClient); - public client: KlasaClient; - - public msg(message: Message|Snowflake, channel: Channel): Promise; - public user(user: User|GuildMember|Message|Snowflake): Promise; - public member(member: User|GuildMember|Snowflake, guild: Guild): Promise; - public channel(channel: Channel|Snowflake): Promise; - public guild(guild: Guild|Snowflake): Promise; - public role(role: Role|Snowflake, guild: Guild): Promise; - public boolean(bool: boolean|string): Promise; - public string(string: string): Promise; - public integer(integer: string|number): Promise; - public float(number: string|number): Promise; - public url(hyperlink: string): Promise; - - public static readonly regex: { - userOrMember: RegExp, - channel: RegExp, - role: RegExp, - snowflake: RegExp, - } - } - - export class ArgResolver extends Resolver { - public piece(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public store(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public cmd(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public command(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public event(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public extendable(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public finalizer(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public inhibitor(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public monitor(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public language(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public provider(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public msg(message: string|Message, channel: Channel): Promise; - public msg(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public message(message: string|Message, channel: Channel): Promise; - public message(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public user(user: User|GuildMember|Message|Snowflake): Promise; - public user(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public mention(user: User|GuildMember|Message|Snowflake): Promise; - public mention(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public member(member: User|GuildMember|Snowflake, guild: Guild): Promise; - public member(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public channel(channel: Channel|Snowflake): Promise; - public channel(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public guild(guild: Guild|Snowflake): Promise; - public guild(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public role(role: Role|Snowflake, guild: Guild): Promise; - public role(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public literal(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public bool(bool: boolean|string): Promise; - public bool(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public boolean(bool: boolean|string): Promise; - public boolean(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public str(string: string): Promise; - public str(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public string(string: string): Promise; - public string(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public int(integer: string|number): Promise; - public int(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public integer(integer: string|number): Promise; - public integer(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public num(number: string|number): Promise; - public num(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public number(number: string|number): Promise; - public number(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public float(number: string|number): Promise; - public float(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public reg(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public regex(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public regexp(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public url(hyperlink: string): Promise; - public url(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - - public static minOrMax(value: number, min: number, max: number, currentUsage: object, possible: number, repeat: boolean, msg: Message, suffix: string): boolean; - } - - export class SettingResolver extends Resolver { - public command(data: any, guild: Guild, name: string): Promise; - public language(data: any, guild: Guild, name: string): Promise; - - public user(user: User|GuildMember|Message|Snowflake): Promise; - public user(data: any, guild: Guild, name: string): Promise; - - public channel(channel: Channel|Snowflake): Promise; - public channel(data: any, guild: Guild, name: string): Promise; - - public textchannel(data: any, guild: Guild, name: string): Promise; - public voicechannel(data: any, guild: Guild, name: string): Promise; - - public guild(guild: Guild|Snowflake): Promise; - public guild(data: any, guild: Guild, name: string): Promise; - - public role(role: Role|Snowflake, guild: Guild): Promise; - public role(data: any, guild: Guild, name: string): Promise; - - public boolean(bool: boolean|string): Promise; - public boolean(data: any, guild: Guild, name: string): Promise; - - public string(string: string): Promise; - public string(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; - - public integer(integer: string|number): Promise; - public integer(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; - - public float(number: string|number): Promise; - public float(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; - - public url(hyperlink: string): Promise; - public url(data: any, guild: Guild, name: string): Promise; - - public static maxOrMin(guild: Guild, value: number, min: number, max: number, name: string, suffix: string): boolean; - } - - export class PermissionLevels extends Collection { - public constructor(levels: number); - public requiredLevels: number; - - public addLevel(level: number, brk: boolean, check: Function); - public set(level: number, obj: PermissionLevel): this; - public isValid(): boolean; - public debug(): string; - - public run(msg: Message, min: number): permissionLevelResponse; - } - - // Usage - export class ParsedUsage { - public constructor(client: KlasaClient, command: Command); - public readonly client: KlasaClient; - public names: string[]; - public commands: string; - public deliminatedUsage: string; - public usageString: string; - public parsedUsage: Tag[]; - public nearlyFullUsage: string; - - public fullUsage(msg: Message): string; - public static parseUsage(usageString: string): Tag[]; - public static tagOpen(usage: object, char: string): object; - public static tagClose(usage: object, char: string): object; - public static tagSpace(usage: object, char: string): object; - } - - export class Possible { - public constructor(regexResults: string[]); - public name: string; - public type: string; - public min: number; - public max: number; - public regex: RegExp; - - public static resolveLimit(limit: string, type: string): number; - } - - export class Tag { - public constructor(members: string, count: number, required: boolean); - public type: string; - public possibles: Possible[]; - - public static parseMembers(members: string, count: number): Possible[]; - public static parseTrueMembers(members: string): string[]; - } - - // Settings - export class CacheManager { - public constructor(client: KlasaClient); - public readonly cacheEngine: string; - public data: Collection|Provider; - - public get(key: string): object; - public getAll(): object[]; - public set(key: string, value: object): any; - public delete(key: string): any; - } - - export class SchemaManager extends CacheManager { - public constructor(client: KlasaClient); - public schema: object; - public defaults: object; - - public initSchema(): Promise; - public validateSchema(schema: object): void; - public add(key: string, options: AddOptions, force: boolean): Promise; - public remove(key: string, force: boolean): Promise; - private force(action: string, key: string): Promise; - } - - export class SettingGateway extends SchemaManager { - constructor(store: SettingCache, type: T, validateFunction: Function, schema: object); - public readonly store: SettingCache; - public type: T; - public engine: string; - public sql: SQL; - public validate: Function; - public defaultDataSchema: object; - - public initSchema(): Promise; - public create(input: object|string): Promise; - public destroy(input: string): Promise; - public get(input: string): object; - public getResolved(input: object|string, guild: SettingGatewayGuildResolvable): Promise; - public sync(input: object|string): Promise; - public reset(input: object|string, key: string): Promise; - public update(input: object|string, object: object, guild: SettingGatewayGuildResolvable): object; - public ensureCreate(target: object|string): true; - public updateArray(input: object|string, action: 'add'|'remove', key: string, data: any): Promise; - private _resolveGuild(guild: Guild|TextChannel|VoiceChannel|Snowflake): Guild; - - public readonly client: KlasaClient; - public readonly resolver: Resolver; - public readonly provider: Provider; - } - - export class SettingCache { - constructor(client: KlasaClient); - public client: KlasaClient; - public resolver: SettingResolver; - public guilds: SettingGateway<'guilds'>; - - public add(name: T, validateFunction: Function, schema: object): Promise>; - public validate(resolver: SettingResolver, guild: object|string); - - public readonly defaultDataSchema: { prefix: SchemaPiece, language: SchemaPiece, disabledCommands: SchemaPiece }; - } - - export class SQL { - constructor(client: KlasaClient, gateway: SettingGateway); - public readonly client: KlasaClient; - public readonly gateway: SettingGateway; - - public buildSingleSQLSchema(value: SchemaPiece): string; - public buildSQLSchema(schema: object): string[]; - - public initDeserialize(): void; - public deserializer(data: SchemaPiece): void; - public updateColumns(schema: object, defaults: object, key: string): Promise; - - public readonly constants: object; - public readonly sanitizer: Function; - public readonly schema: object; - public readonly defaults: object; - public readonly provider: Provider; - } - - // Util - export class Colors { - public constructor(); - public CLOSE: ColorsClose; - public STYLES: ColorsStyles; - public TEXTS: ColorsTexts; - public BACKGROUNDS: ColorsBackgrounds; - - public static hexToRGB(hex: string): number[]; - public static hslToRGB(hsl: number[]): number[]; - public static hueToRGB(p: number, q: number, t: number): number; - public static formatArray(array: string[]): string|number[]; - - public format(string: string, type: { style: string|string[], background: string|number|string[], text: string|number|string[] }): string; - } - - class KlasaConsole extends Console { - public constructor(options: KlasaConsoleConfig); - public readonly stdout: NodeJS.WritableStream; - public readonly stderr: NodeJS.WritableStream; - public timestaamps: boolean|string; - public useColors: boolean; - public colors: boolean|KlasaConsoleColors; - - public write(data: any, type: string): void; - public log(...data: any[]): void; - public warn(...data: any[]): void; - public error(...data: any[]): void; - public debug(...data: any[]): void; - public verbose(...data: any[]): void; - public wtf(...data: any[]): void; - - public timestamp(timestamp: Date, time: string): string; - public messages(string: string, message: string): string; - - public static flatten(data: any, useColors: boolean): string; - } - - export { KlasaConsole as Console } - - // Structures - export class CommandMessage { - public constructor(msg: Message, cmd: Command, prefix: string, prefixLength: number); - public readonly client: KlasaClient; - public msg: Message; - public cmd: Command; - public prefix: string; - public prefixLength: number; - public args: string[]; - public params: any[]; - public reprompted: false; - private _currentUsage: object; - private _repeat: boolean; - - private validateArgs(): Promise; - private multiPossibles(possible: number, validated: boolean): Promise; - - public static getArgs(cmdMsg: CommandMessage): string[]; - public static getQuotedStringArgs(cmdMsg: CommandMessage): string[]; - } - - export class Piece { - public reload(): Promise; - public unload(): void; - public enable(): Piece; - public disable(): Piece; - - public static applyToClass(structure: object, skips: string[]): void; - } - - export abstract class Command implements Piece { - public constructor(client: KlasaClient, dir: string, file: string[], options: CommandOptions); - public client: KlasaClient; - public type: 'command'; - - public enabled: boolean; - public name: string; - public aliases: string[]; - public runIn: string[]; - public botPerms: string[]; - public requiredSettings: string[]; - public cooldown: number; - public permLevel: number; - public description: string; - public usageDelim: string; - public extendedHelp: string; - public quotedStringSupport: boolean; - - public fullCategory: string[]; - public category: string; - public subCategory: string; - public usage: ParsedUsage; - private cooldowns: Map; - - public abstract run(msg: ProxyCommand, params: any[]): Promise; - public abstract init(): any; - - public abstract enable(): Piece; - public abstract disable(): Piece; - public abstract reload(): Promise; - public abstract unload(): any; - } - - export abstract class Event implements Piece { - public constructor(client: KlasaClient, dir: string, file: string[], options: EventOptions); - public client: KlasaClient; - public type: 'event'; - - public enabled: boolean; - public name: string; - public dir: string; - public file: string; - - private _run(param: any): void; - - public abstract run(...params: any[]): void; - public abstract init(): any; - - public abstract enable(): Piece; - public abstract disable(): Piece; - public abstract reload(): Promise; - public abstract unload(): any; - } - - export abstract class Extendable implements Piece { - public constructor(client: KlasaClient, dir: string, file: string[], options: ExtendableOptions); - public client: KlasaClient; - public type: 'extendable'; - - public enabled: boolean; - public name: string; - public dir: string; - public file: string; - - public appliesTo: string[]; - public target: boolean; - - public abstract extend(...params: any[]): any; - public abstract init(): any; - - public abstract enable(): Piece; - public abstract disable(): Piece; - public abstract reload(): Promise; - public abstract unload(): any; - } - - export abstract class Finalizer implements Piece { - public constructor(client: KlasaClient, dir: string, file: string[], options: FinalizerOptions); - public client: KlasaClient; - public type: 'finalizer'; - - public enabled: boolean; - public name: string; - public dir: string; - public file: string; - - public abstract run(msg: CommandMessage, mes: Message, start: number): void; - public abstract init(): any; - - public abstract enable(): Piece; - public abstract disable(): Piece; - public abstract reload(): Promise; - public abstract unload(): any; - } - - export abstract class Inhibitor implements Piece { - public constructor(client: KlasaClient, dir: string, file: string[], options: InhibitorOptions); - public client: KlasaClient; - public type: 'inhibitor'; - - public enabled: boolean; - public name: string; - public dir: string; - public file: string; - - public abstract run(msg: Message, cmd: Command): Promise; - public abstract init(): any; - - public abstract enable(): Piece; - public abstract disable(): Piece; - public abstract reload(): Promise; - public abstract unload(): any; - } - - export abstract class Language implements Piece { - public constructor(client: KlasaClient, dir: string, file: string[], options: LanguageOptions); - public client: KlasaClient; - public type: 'language'; - - public enabled: boolean; - public name: string; - public dir: string; - public file: string; - - public get(term: string, ...args: any[]): string|Function; - public abstract init(): any; - - public abstract enable(): Piece; - public abstract disable(): Piece; - public abstract reload(): Promise; - public abstract unload(): any; - } - - export abstract class Monitor implements Piece { - public constructor(client: KlasaClient, dir: string, file: string[], options: MonitorOptions); - public client: KlasaClient; - public type: 'monitor'; - - public enabled: boolean; - public name: string; - public dir: string; - public file: string; - - public ignoreBots: boolean; - public ignoreSelf: boolean; - - public abstract run(msg: Message): void; - public abstract init(): any; - - public abstract enable(): Piece; - public abstract disable(): Piece; - public abstract reload(): Promise; - public abstract unload(): any; - } - - export abstract class Provider implements Piece { - public constructor(client: KlasaClient, dir: string, file: string[], options: ProviderOptions); - public client: KlasaClient; - public type: 'monitor'; - - public enabled: boolean; - public name: string; - public dir: string; - public file: string; - - public description: string; - public sql: boolean; - - public abstract run(msg: Message): void; - public abstract init(): any; - public abstract shutdown(): Promise; - - public abstract enable(): Piece; - public abstract disable(): Piece; - public abstract reload(): Promise; - public abstract unload(): any; - } - - export class Store { - init(): Promise; - load(dir: string, file: string|string[]): Piece; - loadAll(): Promise; - resolve(name: Piece|string): Piece; - - public static applyToClass(structure: object, skips: string[]): void; - } - - export class CommandStore extends Collection implements Store { - public constructor(client: KlasaClient); - public client: KlasaClient; - public aliases: Collection; - public coreDir: string; - public userDir: string; - public holds: Command; - public name: 'commands'; - - public get(name: string): Command; - public has(name: string): boolean; - public set(key: string, value: Command): this; - public set(command: Command): Command; - public delete(name: Command|string): boolean; - public clear(): void; - public load(dir: string, file: string[]): Command; - public loadAll(): Promise; - - public init(): any; - public resolve(): any; - - public static walk(store: CommandStore, dir: string, subs: string[]): Promise; - } - - export class EventStore extends Collection implements Store { - public constructor(client: KlasaClient); - public client: KlasaClient; - public coreDir: string; - public userDir: string; - public holds: Event; - public name: 'events'; - - public clear(): void; - public delete(name: Event|string): boolean; - public set(key: string, value: Event): this; - public set(event: Event): Event; - - public init(): any; - public load(): any; - public loadAll(): Promise; - public resolve(): any; - } - - export class ExtendableStore extends Collection implements Store { - public constructor(client: KlasaClient); - public client: KlasaClient; - public coreDir: string; - public userDir: string; - public holds: Extendable; - public name: 'extendables'; - - public delete(name: Extendable|string): boolean; - public clear(): void; - public set(key: string, value: Extendable): this; - public set(extendable: Extendable): Extendable; - - public init(): any; - public load(): any; - public loadAll(): Promise; - public resolve(): any; - } - - export class FinalizerStore extends Collection implements Store { - public constructor(client: KlasaClient); - public client: KlasaClient; - public coreDir: string; - public userDir: string; - public holds: Finalizer; - public name: 'finalizers'; - - public delete(name: Finalizer|string): boolean; - public run(msg: CommandMessage, mes: Message, start: number): void; - public set(key: string, value: Finalizer): this; - public set(finalizer: Finalizer): Finalizer; - - public init(): any; - public load(): any; - public loadAll(): Promise; - public resolve(): any; - } - - export class InhibitorStore extends Collection implements Store { - public constructor(client: KlasaClient); - public client: KlasaClient; - public coreDir: string; - public userDir: string; - public holds: Inhibitor; - public name: 'inhibitors'; - - public delete(name: Inhibitor|string): boolean; - public run(msg: Message, cmd: Command, selective: boolean): void; - public set(key: string, value: Inhibitor): this; - public set(inhibitor: Inhibitor): Inhibitor; - - public init(): any; - public load(): any; - public loadAll(): Promise; - public resolve(): any; - } - - export class LanguageStore extends Collection implements Store { - public constructor(client: KlasaClient); - public client: KlasaClient; - public coreDir: string; - public userDir: string; - public holds: Language; - public name: 'languages'; - - public readonly default: Language; - public delete(name: Language|string): boolean; - public set(key: string, value: Language): this; - public set(language: Language): Language; - - public init(): any; - public load(): any; - public loadAll(): Promise; - public resolve(): any; - } - - export class MonitorStore extends Collection implements Store { - public constructor(client: KlasaClient); - public client: KlasaClient; - public coreDir: string; - public userDir: string; - public holds: Monitor; - public name: 'monitors'; - - public delete(name: Monitor|string): boolean; - public run(msg: Message): void; - public set(key: string, value: Monitor): this; - public set(monitor: Monitor): Monitor; - - public init(): any; - public load(): any; - public loadAll(): Promise; - public resolve(): any; - } - - export class ProviderStore extends Collection implements Store { - public constructor(client: KlasaClient); - public client: KlasaClient; - public coreDir: string; - public userDir: string; - public holds: Provider; - public name: 'providers'; - - public delete(name: Provider|string): boolean; - public set(key: string, value: Provider): this; - public set(provider: Provider): Provider; - - public init(): any; - public load(): any; - public loadAll(): Promise; - public resolve(): any; - } - - type KlasaClientConfig = { - prefix: string; - permissionLevels: PermissionLevels; - clientBaseDir: string; - commandMessageLifetime: number; - commandMessageSweep: number; - provider: object; - console: KlasaConsoleConfig; - consoleEvents: KlasaConsoleEvents; - ignoreBots: boolean; - ignoreSelf: boolean; - prefixMention: RegExp; - cmdPrompt: boolean; - cmdEditing: boolean; - cmdLogging: boolean; - typing: boolean; - quotedStringSupport: boolean; - readyMessage: string|Function; - string: string; - } & ClientOptions; - - type KlasaConsoleConfig = { - stdout: NodeJS.WritableStream; - stderr: NodeJS.WritableStream; - useColor: boolean; - colors: Colors; - timestamps: boolean|string; - }; - - type KlasaConsoleEvents = { - log: boolean; - warn: boolean; - error: boolean; - debug: boolean; - verbose: boolean; - wtf: boolean; - }; - - type PermissionLevel = { - break: boolean; - check: Function; - }; - - type permissionLevelResponse = { - broke: boolean; - permission: boolean; - }; - - type ProxyCommand = CommandMessage & Message; - - type CommandOptions = { - enabled: boolean; - name: string; - aliases: string[]; - runIn: string[]; - botPerms: string[]; - requiredSettings: string[]; - cooldown: number; - permLevel: number; - description: string; - usage: string; - usageDelim: string; - extendedHelp: string; - quotedStringSupport: boolean; - }; - - type EventOptions = { - enabled: boolean; - name: string; - }; - - type ExtendableOptions = { - enabled: boolean; - name: string; - klasa: boolean; - }; - - type FinalizerOptions = { - enabled: boolean; - name: string; - }; - - type InhibitorOptions = { - enabled: boolean; - name: string; - spamProtection: boolean; - }; - - type LanguageOptions = { - enabled: boolean; - name: string; - }; - - type MonitorOptions = { - enabled: boolean; - name: string; - ignoreBots: boolean; - ignoreSelf: boolean; - }; - - type ProviderOptions = { - enabled: boolean; - name: string; - description: string; - sql: boolean; - }; - - type AddOptions = { - type: string; - default: any; - min: number; - max: number; - array: boolean; - sql: string; - } - - type SchemaPiece = { - type: string; - default: any; - min: number; - max: number; - array: boolean; - sql: string; - } - - type SettingGatewayGuildResolvable = Guild|Channel|Message|Role|Snowflake; - - type ColorsClose = { - normal: 0; - bold: 22; - dim: 22; - italic: 23; - underline: 24; - inverse: 27; - hidden: 28; - strikethrough: 29; - text: 39; - background: 49; - }; - - type ColorsStyles = { - normal: 0; - bold: 1; - dim: 2; - italic: 3; - underline: 4; - inverse: 7; - hidden: 8; - strikethrough: 9; - }; - - type ColorsTexts = { - black: 30; - red: 31; - green: 32; - yellow: 33; - blue: 34; - magenta: 35; - cyan: 36; - lightgray: 37; - lightgrey: 37; - gray: 90; - grey: 90; - lightred: 91; - lightgreen: 92; - lightyellow: 93; - lightblue: 94; - lightmagenta: 95; - lightcyan: 96; - white: 97; - }; - - type ColorsBackgrounds = { - black: 40; - red: 41; - green: 42; - yellow: 43; - blue: 44; - magenta: 45; - cyan: 46; - gray: 47; - grey: 47; - lightgray: 100; - lightgrey: 100; - lightred: 101; - lightgreen: 102; - lightyellow: 103; - lightblue: 104; - lightmagenta: 105; - lightcyan: 106; - white: 107; - }; - - type KlasaConsoleColors = { - debug: KlasaConsoleColorObjects; - error: KlasaConsoleColorObjects; - log: KlasaConsoleColorObjects; - verbose: KlasaConsoleColorObjects; - warn: KlasaConsoleColorObjects; - wtf: KlasaConsoleColorObjects; - }; - - type KlasaConsoleColorObjects = { - log: string; - message: KlasaConsoleMessageObject; - time: KlasaConsoleTimeObject; - } - - type KlasaConsoleMessageObject = { - background: BackgroundColorTypes; - text: TextColorTypes; - style: StyleTypes; - } - - type KlasaConsoleTimeObject = { - background: BackgroundColorTypes; - text: TextColorTypes; - style: StyleTypes; - } - - type TextColorTypes = 'black'|'red'|'green'|'yellow'|'blue'|'magenta'|'cyan'|'gray'|'grey'|'lightgray'|'lightgrey'|'lightred'|'lightgreen'|'lightyellow'|'lightblue'|'lightmagenta'|'lightcyan'|'white'|number[]|string[]; - - type BackgroundColorTypes = 'black'|'red'|'green'|'blue'|'magenta'|'cyan'|'gray'|'grey'|'lightgray'|'lightgrey'|'lightred'|'lightgreen'|'lightyellow'|'lightblue'|'lightmagenta'|'lightcyan'|'white'|number[]|string[]; - - type StyleTypes = 'normal'|'bold'|'dim'|'italic'|'underline'|'inverse'|'hidden'|'strikethrough'; - - // Extended classes - type Message = { - guild: Guild; - guildSettings: object; - hasAtLeastPermissionLevel: Promise; - language: Language; - reactable: Boolean; - send: Promise; - sendCode: Promise; - sendEmbed: Promise; - sendMessage: Promise; - sendFile: Promise; - sendFiles: Promise; - usableCommands: Promise> - } & DiscordMessage; - - type Guild = { - language: Language; - settings: object; - } & DiscordGuild; - - type User = { - sendCode: Promise; - sendEmbed: Promise; - sendMessage: Promise; - sendFile: Promise; - sendFiles: Promise; - } & DiscordUser; - - type TextChannel = { - attachable: boolean; - embedable: boolean; - postable: boolean; - language: Language; - sendCode: Promise; - sendEmbed: Promise; - sendMessage: Promise; - sendFile: Promise; - sendFiles: Promise; - } & DiscordTextChannel; - - type DMChannel = { - attachable: boolean; - embedable: boolean; - postable: boolean; - language: Language; - sendCode: Promise; - sendEmbed: Promise; - sendMessage: Promise; - sendFile: Promise; - sendFiles: Promise; - } & DiscordDMChannel; - - type GroupDMChannel = { - attachable: boolean; - embedable: boolean; - postable: boolean; - language: Language; - sendCode: Promise; - sendEmbed: Promise; - sendMessage: Promise; - sendFile: Promise; - sendFiles: Promise; - } & DiscordGroupDMChannel; + import { + Client, + ClientOptions, + Collection, + Snowflake, + MessageEmbed, + MessageCollector, + WebhookClient, + ClientUserGuildSettings, + ClientUserSettings, + Emoji, + User as DiscordUser, + Message as DiscordMessage, + MessageReaction, + GuildMember, + Guild as DiscordGuild, + UserResolvable, + Role, + Channel, + TextChannel as DiscordTextChannel, + VoiceChannel, + DMChannel as DiscordDMChannel, + GroupDMChannel as DiscordGroupDMChannel + } from 'discord.js'; + + export const version: string; + + class KlasaClient extends Client { + constructor(options?: KlasaClientConfig); + config: KlasaClientConfig; + coreBaseDir: string; + clientBaseDir: string; + console: Console; + argResolver: ArgResolver; + commands: CommandStore; + inhibitors: InhibitorStore; + finalizers: FinalizerStore; + monitors: MonitorStore; + languages: LanguageStore; + providers: ProviderStore; + events: EventStore; + extendables: ExtendableStore; + pieceStores: Collection; + commandMessages: Collection; + permissionLevels: PermissionLevels; + commandMessageLifetime: number; + commandMessageSweep: number; + ready: false; + methods: { + Collection: typeof Collection; + Embed: typeof MessageEmbed; + MessageCollector: typeof MessageCollector; + Webhook: typeof WebhookClient; + CommandMessage: typeof CommandMessage; + util: object; + }; + settings: StringMappedType>; + application: object; + + public static readonly invite: string; + public static readonly owner: User; + public validatePermissionLevels(): PermissionLevels; + public registerStore(store: Store): KlasaClient; + public unregisterStore(store: Store): KlasaClient; + + public registerPiece(pieceName: string, store: Store): KlasaClient; + public unregisterPiece(pieceName: string): KlasaClient; + + public login(token: string): Promise; + private _ready(): void; + + public sweepCommandMessages(lifetime: number): number; + public defaultPermissionLevels: PermissionLevels; + + // Discord.js events + public on(event: string, listener: Function): this; + public on(event: 'channelCreate' | 'channelDelete', listener: (channel: Channel) => void): this; + public on(event: 'channelPinsUpdate', listener: (channel: Channel, time: Date) => void): this; + public on(event: 'channelUpdate', listener: (oldChannel: Channel, newChannel: Channel) => void): this; + public on(event: 'clientUserGuildSettingsUpdate', listener: (clientUserGuildSettings: ClientUserGuildSettings) => void): this; + public on(event: 'clientUserSettingsUpdate', listener: (clientUserSettings: ClientUserSettings) => void): this; + public on(event: 'clientUserGuildSettingsUpdate', listener: (clientUserGuildSettings: ClientUserGuildSettings) => void): this; + public on(event: 'debug' | 'warn', listener: (info: string) => void): this; + public on(event: 'disconnect', listener: (event: any) => void): this; + public on(event: 'emojiCreate | emojiDelete', listener: (emoji: Emoji) => void): this; + public on(event: 'emojiUpdate', listener: (oldEmoji: Emoji, newEmoji: Emoji) => void): this; + public on(event: 'error', listener: (error: Error) => void): this; + public on(event: 'guildBanAdd' | 'guildBanRemove', listener: (guild: Guild, user: User) => void): this; + public on(event: 'guildCreate' | 'guildDelete' | 'guildUnavailable', listener: (guild: Guild) => void): this; + public on(event: 'guildMemberAdd' | 'guildMemberAvailable' | 'guildMemberRemove', listener: (member: GuildMember) => void): this; + public on(event: 'guildMembersChunk', listener: (members: GuildMember[], guild: Guild) => void): this; + public on(event: 'guildMemberSpeaking', listener: (member: GuildMember, speaking: boolean) => void): this; + public on(event: 'guildMemberUpdate' | 'presenceUpdate' | 'voiceStateUpdate', listener: (oldMember: GuildMember, newMember: GuildMember) => void): this; + public on(event: 'guildUpdate', listener: (oldGuild: Guild, newGuild: Guild) => void): this; + public on(event: 'message' | 'messageDelete' | 'messageReactionRemoveAll', listener: (message: Message) => void): this; + public on(event: 'messageDeleteBulk', listener: (messages: Collection) => void): this; + public on(event: 'messageReactionAdd' | 'messageReactionRemove', listener: (messageReaction: MessageReaction, user: User) => void): this; + public on(event: 'messageUpdate', listener: (oldMessage: Message, newMessage: Message) => void): this; + public on(event: 'ready' | 'reconnecting' | 'resume', listener: () => void): this; + public on(event: 'roleCreate' | 'roleDelete', listener: (role: Role) => void): this; + public on(event: 'roleUpdate', listener: (oldRole: Role, newRole: Role) => void): this; + public on(event: 'typingStart' | 'typingStop', listener: (channel: Channel, user: User) => void): this; + public on(event: 'userNoteUpdate', listener: (user: UserResolvable, oldNote: string, newNote: string) => void): this; + public on(event: 'userUpdate', listener: (oldUser: User, newUser: User) => void): this; + + // Klasa Command Events + public on(event: 'commandError', listener: (msg: Message, command: Command, params: any[], error: Error) => void): this; + public on(event: 'commandInhibited', listener: (msg: Message, command: Command, response: string|Error) => void): this; + + // Klasa Console Custom Events + public on(event: 'log', listener: (data: any, type: string) => void): this; + public on(event: 'wtf', listener: (failure: Error) => void): this; + public on(event: 'verbose', listener: (data: any) => void): this; + + // Discord.js events + public once(event: string, listener: Function): this; + public once(event: 'channelCreate' | 'channelDelete', listener: (channel: Channel) => void): this; + public once(event: 'channelPinsUpdate', listener: (channel: Channel, time: Date) => void): this; + public once(event: 'channelUpdate', listener: (oldChannel: Channel, newChannel: Channel) => void): this; + public once(event: 'clientUserGuildSettingsUpdate', listener: (clientUserGuildSettings: ClientUserGuildSettings) => void): this; + public once(event: 'clientUserSettingsUpdate', listener: (clientUserSettings: ClientUserSettings) => void): this; + public once(event: 'clientUserGuildSettingsUpdate', listener: (clientUserGuildSettings: ClientUserGuildSettings) => void): this; + public once(event: 'debug' | 'warn', listener: (info: string) => void): this; + public once(event: 'disconnect', listener: (event: any) => void): this; + public once(event: 'emojiCreate | emojiDelete', listener: (emoji: Emoji) => void): this; + public once(event: 'emojiUpdate', listener: (oldEmoji: Emoji, newEmoji: Emoji) => void): this; + public once(event: 'error', listener: (error: Error) => void): this; + public once(event: 'guildBanAdd' | 'guildBanRemove', listener: (guild: Guild, user: User) => void): this; + public once(event: 'guildCreate' | 'guildDelete' | 'guildUnavailable', listener: (guild: Guild) => void): this; + public once(event: 'guildMemberAdd' | 'guildMemberAvailable' | 'guildMemberRemove', listener: (member: GuildMember) => void): this; + public once(event: 'guildMembersChunk', listener: (members: GuildMember[], guild: Guild) => void): this; + public once(event: 'guildMemberSpeaking', listener: (member: GuildMember, speaking: boolean) => void): this; + public once(event: 'guildMemberUpdate' | 'presenceUpdate' | 'voiceStateUpdate', listener: (oldMember: GuildMember, newMember: GuildMember) => void): this; + public once(event: 'guildUpdate', listener: (oldGuild: Guild, newGuild: Guild) => void): this; + public once(event: 'message' | 'messageDelete' | 'messageReactionRemoveAll', listener: (message: Message) => void): this; + public once(event: 'messageDeleteBulk', listener: (messages: Collection) => void): this; + public once(event: 'messageReactionAdd' | 'messageReactionRemove', listener: (messageReaction: MessageReaction, user: User) => void): this; + public once(event: 'messageUpdate', listener: (oldMessage: Message, newMessage: Message) => void): this; + public once(event: 'ready' | 'reconnecting' | 'resume', listener: () => void): this; + public once(event: 'roleCreate' | 'roleDelete', listener: (role: Role) => void): this; + public once(event: 'roleUpdate', listener: (oldRole: Role, newRole: Role) => void): this; + public once(event: 'typingStart' | 'typingStop', listener: (channel: Channel, user: User) => void): this; + public once(event: 'userNoteUpdate', listener: (user: UserResolvable, oldNote: string, newNote: string) => void): this; + public once(event: 'userUpdate', listener: (oldUser: User, newUser: User) => void): this; + + // Klasa Command Events + public once(event: 'commandError', listener: (msg: Message, command: Command, params: any[], error: Error) => void): this; + public once(event: 'commandInhibited', listener: (msg: Message, command: Command, response: string|Error) => void): this; + + // Klasa Console Custom Events + public once(event: 'log', listener: (data: any, type: string) => void): this; + public once(event: 'wtf', listener: (failure: Error) => void): this; + public once(event: 'verbose', listener: (data: any) => void): this; + + } + + export { KlasaClient as Client } + + export class util { + public static codeBlock(lang: string, expression: string): string; + public static clean(text: string): string; + private static initClean(client: KlasaClient): void; + public static toTitleCase(str: string): string; + public static newError(error: Error, code: number): Error; + public static regExpEsc(str: string): string; + public static applyToClass(base: object, structure: object, skips: string[]): void; + } + + export class Resolver { + public constructor(client: KlasaClient); + public client: KlasaClient; + + public msg(message: Message|Snowflake, channel: Channel): Promise; + public user(user: User|GuildMember|Message|Snowflake): Promise; + public member(member: User|GuildMember|Snowflake, guild: Guild): Promise; + public channel(channel: Channel|Snowflake): Promise; + public guild(guild: Guild|Snowflake): Promise; + public role(role: Role|Snowflake, guild: Guild): Promise; + public boolean(bool: boolean|string): Promise; + public string(string: string): Promise; + public integer(integer: string|number): Promise; + public float(number: string|number): Promise; + public url(hyperlink: string): Promise; + + public static readonly regex: { + userOrMember: RegExp, + channel: RegExp, + role: RegExp, + snowflake: RegExp, + } + } + + export class ArgResolver extends Resolver { + public piece(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public store(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public cmd(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public command(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public event(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public extendable(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public finalizer(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public inhibitor(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public monitor(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public language(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public provider(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public msg(message: string|Message, channel: Channel): Promise; + public msg(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public message(message: string|Message, channel: Channel): Promise; + public message(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public user(user: User|GuildMember|Message|Snowflake): Promise; + public user(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public mention(user: User|GuildMember|Message|Snowflake): Promise; + public mention(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public member(member: User|GuildMember|Snowflake, guild: Guild): Promise; + public member(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public channel(channel: Channel|Snowflake): Promise; + public channel(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public guild(guild: Guild|Snowflake): Promise; + public guild(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public role(role: Role|Snowflake, guild: Guild): Promise; + public role(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public literal(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public bool(bool: boolean|string): Promise; + public bool(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public boolean(bool: boolean|string): Promise; + public boolean(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public str(string: string): Promise; + public str(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public string(string: string): Promise; + public string(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public int(integer: string|number): Promise; + public int(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public integer(integer: string|number): Promise; + public integer(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public num(number: string|number): Promise; + public num(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public number(number: string|number): Promise; + public number(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public float(number: string|number): Promise; + public float(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public reg(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public regex(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + public regexp(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public url(hyperlink: string): Promise; + public url(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; + + public static minOrMax(value: number, min: number, max: number, currentUsage: object, possible: number, repeat: boolean, msg: Message, suffix: string): boolean; + } + + export class SettingResolver extends Resolver { + public command(data: any, guild: Guild, name: string): Promise; + public language(data: any, guild: Guild, name: string): Promise; + + public user(user: User|GuildMember|Message|Snowflake): Promise; + public user(data: any, guild: Guild, name: string): Promise; + + public channel(channel: Channel|Snowflake): Promise; + public channel(data: any, guild: Guild, name: string): Promise; + + public textchannel(data: any, guild: Guild, name: string): Promise; + public voicechannel(data: any, guild: Guild, name: string): Promise; + + public guild(guild: Guild|Snowflake): Promise; + public guild(data: any, guild: Guild, name: string): Promise; + + public role(role: Role|Snowflake, guild: Guild): Promise; + public role(data: any, guild: Guild, name: string): Promise; + + public boolean(bool: boolean|string): Promise; + public boolean(data: any, guild: Guild, name: string): Promise; + + public string(string: string): Promise; + public string(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; + + public integer(integer: string|number): Promise; + public integer(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; + + public float(number: string|number): Promise; + public float(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; + + public url(hyperlink: string): Promise; + public url(data: any, guild: Guild, name: string): Promise; + + public static maxOrMin(guild: Guild, value: number, min: number, max: number, name: string, suffix: string): boolean; + } + + export class PermissionLevels extends Collection { + public constructor(levels: number); + public requiredLevels: number; + + public addLevel(level: number, brk: boolean, check: Function); + public set(level: number, obj: PermissionLevel): this; + public isValid(): boolean; + public debug(): string; + + public run(msg: Message, min: number): permissionLevelResponse; + } + + // Usage + export class ParsedUsage { + public constructor(client: KlasaClient, command: Command); + public readonly client: KlasaClient; + public names: string[]; + public commands: string; + public deliminatedUsage: string; + public usageString: string; + public parsedUsage: Tag[]; + public nearlyFullUsage: string; + + public fullUsage(msg: Message): string; + public static parseUsage(usageString: string): Tag[]; + public static tagOpen(usage: object, char: string): object; + public static tagClose(usage: object, char: string): object; + public static tagSpace(usage: object, char: string): object; + } + + export class Possible { + public constructor(regexResults: string[]); + public name: string; + public type: string; + public min: number; + public max: number; + public regex: RegExp; + + public static resolveLimit(limit: string, type: string): number; + } + + export class Tag { + public constructor(members: string, count: number, required: boolean); + public type: string; + public possibles: Possible[]; + + public static parseMembers(members: string, count: number): Possible[]; + public static parseTrueMembers(members: string): string[]; + } + + // Settings + export class CacheManager { + public constructor(client: KlasaClient); + public readonly cacheEngine: string; + public data: Collection|Provider; + + public get(key: string): object; + public getAll(): object[]; + public set(key: string, value: object): any; + public delete(key: string): any; + } + + export class SchemaManager extends CacheManager { + public constructor(client: KlasaClient); + public schema: object; + public defaults: object; + + public initSchema(): Promise; + public validateSchema(schema: object): void; + public add(key: string, options: AddOptions, force: boolean): Promise; + public remove(key: string, force: boolean): Promise; + private force(action: string, key: string): Promise; + } + + export class SettingGateway extends SchemaManager { + constructor(store: SettingCache, type: T, validateFunction: Function, schema: object); + public readonly store: SettingCache; + public type: T; + public engine: string; + public sql: SQL; + public validate: Function; + public defaultDataSchema: object; + + public initSchema(): Promise; + public create(input: object|string): Promise; + public destroy(input: string): Promise; + public get(input: string): object; + public getResolved(input: object|string, guild: SettingGatewayGuildResolvable): Promise; + public sync(input: object|string): Promise; + public reset(input: object|string, key: string): Promise; + public update(input: object|string, object: object, guild: SettingGatewayGuildResolvable): object; + public ensureCreate(target: object|string): true; + public updateArray(input: object|string, action: 'add'|'remove', key: string, data: any): Promise; + private _resolveGuild(guild: Guild|TextChannel|VoiceChannel|Snowflake): Guild; + + public readonly client: KlasaClient; + public readonly resolver: Resolver; + public readonly provider: Provider; + } + + export class SettingCache { + constructor(client: KlasaClient); + public client: KlasaClient; + public resolver: SettingResolver; + public guilds: SettingGateway<'guilds'>; + + public add(name: T, validateFunction: Function, schema: object): Promise>; + public validate(resolver: SettingResolver, guild: object|string); + + public readonly defaultDataSchema: { prefix: SchemaPiece, language: SchemaPiece, disabledCommands: SchemaPiece }; + } + + export class SQL { + constructor(client: KlasaClient, gateway: SettingGateway); + public readonly client: KlasaClient; + public readonly gateway: SettingGateway; + + public buildSingleSQLSchema(value: SchemaPiece): string; + public buildSQLSchema(schema: object): string[]; + + public initDeserialize(): void; + public deserializer(data: SchemaPiece): void; + public updateColumns(schema: object, defaults: object, key: string): Promise; + + public readonly constants: object; + public readonly sanitizer: Function; + public readonly schema: object; + public readonly defaults: object; + public readonly provider: Provider; + } + + // Util + export class Colors { + public constructor(); + public CLOSE: ColorsClose; + public STYLES: ColorsStyles; + public TEXTS: ColorsTexts; + public BACKGROUNDS: ColorsBackgrounds; + + public static hexToRGB(hex: string): number[]; + public static hslToRGB(hsl: number[]): number[]; + public static hueToRGB(p: number, q: number, t: number): number; + public static formatArray(array: string[]): string|number[]; + + public format(string: string, type: { style: string|string[], background: string|number|string[], text: string|number|string[] }): string; + } + + class KlasaConsole extends Console { + public constructor(options: KlasaConsoleConfig); + public readonly stdout: NodeJS.WritableStream; + public readonly stderr: NodeJS.WritableStream; + public timestaamps: boolean|string; + public useColors: boolean; + public colors: boolean|KlasaConsoleColors; + + public write(data: any, type: string): void; + public log(...data: any[]): void; + public warn(...data: any[]): void; + public error(...data: any[]): void; + public debug(...data: any[]): void; + public verbose(...data: any[]): void; + public wtf(...data: any[]): void; + + public timestamp(timestamp: Date, time: string): string; + public messages(string: string, message: string): string; + + public static flatten(data: any, useColors: boolean): string; + } + + export { KlasaConsole as Console } + + // Structures + export class CommandMessage { + public constructor(msg: Message, cmd: Command, prefix: string, prefixLength: number); + public readonly client: KlasaClient; + public msg: Message; + public cmd: Command; + public prefix: string; + public prefixLength: number; + public args: string[]; + public params: any[]; + public reprompted: false; + private _currentUsage: object; + private _repeat: boolean; + + private validateArgs(): Promise; + private multiPossibles(possible: number, validated: boolean): Promise; + + public static getArgs(cmdMsg: CommandMessage): string[]; + public static getQuotedStringArgs(cmdMsg: CommandMessage): string[]; + } + + export class Piece { + public reload(): Promise; + public unload(): void; + public enable(): Piece; + public disable(): Piece; + + public static applyToClass(structure: object, skips: string[]): void; + } + + export abstract class Command implements Piece { + public constructor(client: KlasaClient, dir: string, file: string[], options: CommandOptions); + public client: KlasaClient; + public type: 'command'; + + public enabled: boolean; + public name: string; + public aliases: string[]; + public runIn: string[]; + public botPerms: string[]; + public requiredSettings: string[]; + public cooldown: number; + public permLevel: number; + public description: string; + public usageDelim: string; + public extendedHelp: string; + public quotedStringSupport: boolean; + + public fullCategory: string[]; + public category: string; + public subCategory: string; + public usage: ParsedUsage; + private cooldowns: Map; + + public abstract run(msg: ProxyCommand, params: any[]): Promise; + public abstract init(): any; + + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; + public abstract unload(): any; + } + + export abstract class Event implements Piece { + public constructor(client: KlasaClient, dir: string, file: string[], options: EventOptions); + public client: KlasaClient; + public type: 'event'; + + public enabled: boolean; + public name: string; + public dir: string; + public file: string; + + private _run(param: any): void; + + public abstract run(...params: any[]): void; + public abstract init(): any; + + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; + public abstract unload(): any; + } + + export abstract class Extendable implements Piece { + public constructor(client: KlasaClient, dir: string, file: string[], options: ExtendableOptions); + public client: KlasaClient; + public type: 'extendable'; + + public enabled: boolean; + public name: string; + public dir: string; + public file: string; + + public appliesTo: string[]; + public target: boolean; + + public abstract extend(...params: any[]): any; + public abstract init(): any; + + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; + public abstract unload(): any; + } + + export abstract class Finalizer implements Piece { + public constructor(client: KlasaClient, dir: string, file: string[], options: FinalizerOptions); + public client: KlasaClient; + public type: 'finalizer'; + + public enabled: boolean; + public name: string; + public dir: string; + public file: string; + + public abstract run(msg: CommandMessage, mes: Message, start: number): void; + public abstract init(): any; + + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; + public abstract unload(): any; + } + + export abstract class Inhibitor implements Piece { + public constructor(client: KlasaClient, dir: string, file: string[], options: InhibitorOptions); + public client: KlasaClient; + public type: 'inhibitor'; + + public enabled: boolean; + public name: string; + public dir: string; + public file: string; + + public abstract run(msg: Message, cmd: Command): Promise; + public abstract init(): any; + + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; + public abstract unload(): any; + } + + export abstract class Language implements Piece { + public constructor(client: KlasaClient, dir: string, file: string[], options: LanguageOptions); + public client: KlasaClient; + public type: 'language'; + + public enabled: boolean; + public name: string; + public dir: string; + public file: string; + + public get(term: string, ...args: any[]): string|Function; + public abstract init(): any; + + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; + public abstract unload(): any; + } + + export abstract class Monitor implements Piece { + public constructor(client: KlasaClient, dir: string, file: string[], options: MonitorOptions); + public client: KlasaClient; + public type: 'monitor'; + + public enabled: boolean; + public name: string; + public dir: string; + public file: string; + + public ignoreBots: boolean; + public ignoreSelf: boolean; + + public abstract run(msg: Message): void; + public abstract init(): any; + + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; + public abstract unload(): any; + } + + export abstract class Provider implements Piece { + public constructor(client: KlasaClient, dir: string, file: string[], options: ProviderOptions); + public client: KlasaClient; + public type: 'monitor'; + + public enabled: boolean; + public name: string; + public dir: string; + public file: string; + + public description: string; + public sql: boolean; + + public abstract run(msg: Message): void; + public abstract init(): any; + public abstract shutdown(): Promise; + + public abstract enable(): Piece; + public abstract disable(): Piece; + public abstract reload(): Promise; + public abstract unload(): any; + } + + export class Store { + init(): Promise; + load(dir: string, file: string|string[]): Piece; + loadAll(): Promise; + resolve(name: Piece|string): Piece; + + public static applyToClass(structure: object, skips: string[]): void; + } + + export class CommandStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public aliases: Collection; + public coreDir: string; + public userDir: string; + public holds: Command; + public name: 'commands'; + + public get(name: string): Command; + public has(name: string): boolean; + public set(key: string, value: Command): this; + public set(command: Command): Command; + public delete(name: Command|string): boolean; + public clear(): void; + public load(dir: string, file: string[]): Command; + public loadAll(): Promise; + + public init(): any; + public resolve(): any; + + public static walk(store: CommandStore, dir: string, subs: string[]): Promise; + } + + export class EventStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public coreDir: string; + public userDir: string; + public holds: Event; + public name: 'events'; + + public clear(): void; + public delete(name: Event|string): boolean; + public set(key: string, value: Event): this; + public set(event: Event): Event; + + public init(): any; + public load(): any; + public loadAll(): Promise; + public resolve(): any; + } + + export class ExtendableStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public coreDir: string; + public userDir: string; + public holds: Extendable; + public name: 'extendables'; + + public delete(name: Extendable|string): boolean; + public clear(): void; + public set(key: string, value: Extendable): this; + public set(extendable: Extendable): Extendable; + + public init(): any; + public load(): any; + public loadAll(): Promise; + public resolve(): any; + } + + export class FinalizerStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public coreDir: string; + public userDir: string; + public holds: Finalizer; + public name: 'finalizers'; + + public delete(name: Finalizer|string): boolean; + public run(msg: CommandMessage, mes: Message, start: number): void; + public set(key: string, value: Finalizer): this; + public set(finalizer: Finalizer): Finalizer; + + public init(): any; + public load(): any; + public loadAll(): Promise; + public resolve(): any; + } + + export class InhibitorStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public coreDir: string; + public userDir: string; + public holds: Inhibitor; + public name: 'inhibitors'; + + public delete(name: Inhibitor|string): boolean; + public run(msg: Message, cmd: Command, selective: boolean): void; + public set(key: string, value: Inhibitor): this; + public set(inhibitor: Inhibitor): Inhibitor; + + public init(): any; + public load(): any; + public loadAll(): Promise; + public resolve(): any; + } + + export class LanguageStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public coreDir: string; + public userDir: string; + public holds: Language; + public name: 'languages'; + + public readonly default: Language; + public delete(name: Language|string): boolean; + public set(key: string, value: Language): this; + public set(language: Language): Language; + + public init(): any; + public load(): any; + public loadAll(): Promise; + public resolve(): any; + } + + export class MonitorStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public coreDir: string; + public userDir: string; + public holds: Monitor; + public name: 'monitors'; + + public delete(name: Monitor|string): boolean; + public run(msg: Message): void; + public set(key: string, value: Monitor): this; + public set(monitor: Monitor): Monitor; + + public init(): any; + public load(): any; + public loadAll(): Promise; + public resolve(): any; + } + + export class ProviderStore extends Collection implements Store { + public constructor(client: KlasaClient); + public client: KlasaClient; + public coreDir: string; + public userDir: string; + public holds: Provider; + public name: 'providers'; + + public delete(name: Provider|string): boolean; + public set(key: string, value: Provider): this; + public set(provider: Provider): Provider; + + public init(): any; + public load(): any; + public loadAll(): Promise; + public resolve(): any; + } + + type KlasaClientConfig = { + prefix: string; + permissionLevels: PermissionLevels; + clientBaseDir: string; + commandMessageLifetime: number; + commandMessageSweep: number; + provider: object; + console: KlasaConsoleConfig; + consoleEvents: KlasaConsoleEvents; + ignoreBots: boolean; + ignoreSelf: boolean; + prefixMention: RegExp; + cmdPrompt: boolean; + cmdEditing: boolean; + cmdLogging: boolean; + typing: boolean; + quotedStringSupport: boolean; + readyMessage: string|Function; + string: string; + } & ClientOptions; + + type KlasaConsoleConfig = { + stdout: NodeJS.WritableStream; + stderr: NodeJS.WritableStream; + useColor: boolean; + colors: Colors; + timestamps: boolean|string; + }; + + type KlasaConsoleEvents = { + log: boolean; + warn: boolean; + error: boolean; + debug: boolean; + verbose: boolean; + wtf: boolean; + }; + + type PermissionLevel = { + break: boolean; + check: Function; + }; + + type permissionLevelResponse = { + broke: boolean; + permission: boolean; + }; + + type ProxyCommand = CommandMessage & Message; + + type CommandOptions = { + enabled: boolean; + name: string; + aliases: string[]; + runIn: string[]; + botPerms: string[]; + requiredSettings: string[]; + cooldown: number; + permLevel: number; + description: string; + usage: string; + usageDelim: string; + extendedHelp: string; + quotedStringSupport: boolean; + }; + + type EventOptions = { + enabled: boolean; + name: string; + }; + + type ExtendableOptions = { + enabled: boolean; + name: string; + klasa: boolean; + }; + + type FinalizerOptions = { + enabled: boolean; + name: string; + }; + + type InhibitorOptions = { + enabled: boolean; + name: string; + spamProtection: boolean; + }; + + type LanguageOptions = { + enabled: boolean; + name: string; + }; + + type MonitorOptions = { + enabled: boolean; + name: string; + ignoreBots: boolean; + ignoreSelf: boolean; + }; + + type ProviderOptions = { + enabled: boolean; + name: string; + description: string; + sql: boolean; + }; + + type AddOptions = { + type: string; + default: any; + min: number; + max: number; + array: boolean; + sql: string; + } + + type SchemaPiece = { + type: string; + default: any; + min: number; + max: number; + array: boolean; + sql: string; + } + + type SettingGatewayGuildResolvable = Guild|Channel|Message|Role|Snowflake; + + type ColorsClose = { + normal: 0; + bold: 22; + dim: 22; + italic: 23; + underline: 24; + inverse: 27; + hidden: 28; + strikethrough: 29; + text: 39; + background: 49; + }; + + type ColorsStyles = { + normal: 0; + bold: 1; + dim: 2; + italic: 3; + underline: 4; + inverse: 7; + hidden: 8; + strikethrough: 9; + }; + + type ColorsTexts = { + black: 30; + red: 31; + green: 32; + yellow: 33; + blue: 34; + magenta: 35; + cyan: 36; + lightgray: 37; + lightgrey: 37; + gray: 90; + grey: 90; + lightred: 91; + lightgreen: 92; + lightyellow: 93; + lightblue: 94; + lightmagenta: 95; + lightcyan: 96; + white: 97; + }; + + type ColorsBackgrounds = { + black: 40; + red: 41; + green: 42; + yellow: 43; + blue: 44; + magenta: 45; + cyan: 46; + gray: 47; + grey: 47; + lightgray: 100; + lightgrey: 100; + lightred: 101; + lightgreen: 102; + lightyellow: 103; + lightblue: 104; + lightmagenta: 105; + lightcyan: 106; + white: 107; + }; + + type KlasaConsoleColors = { + debug: KlasaConsoleColorObjects; + error: KlasaConsoleColorObjects; + log: KlasaConsoleColorObjects; + verbose: KlasaConsoleColorObjects; + warn: KlasaConsoleColorObjects; + wtf: KlasaConsoleColorObjects; + }; + + type KlasaConsoleColorObjects = { + log: string; + message: KlasaConsoleMessageObject; + time: KlasaConsoleTimeObject; + } + + type KlasaConsoleMessageObject = { + background: BackgroundColorTypes; + text: TextColorTypes; + style: StyleTypes; + } + + type KlasaConsoleTimeObject = { + background: BackgroundColorTypes; + text: TextColorTypes; + style: StyleTypes; + } + + type TextColorTypes = 'black'|'red'|'green'|'yellow'|'blue'|'magenta'|'cyan'|'gray'|'grey'|'lightgray'|'lightgrey'|'lightred'|'lightgreen'|'lightyellow'|'lightblue'|'lightmagenta'|'lightcyan'|'white'|number[]|string[]; + + type BackgroundColorTypes = 'black'|'red'|'green'|'blue'|'magenta'|'cyan'|'gray'|'grey'|'lightgray'|'lightgrey'|'lightred'|'lightgreen'|'lightyellow'|'lightblue'|'lightmagenta'|'lightcyan'|'white'|number[]|string[]; + + type StyleTypes = 'normal'|'bold'|'dim'|'italic'|'underline'|'inverse'|'hidden'|'strikethrough'; + + type StringMappedType = { [key: string]: T }; + + type GuildSettings = StringMappedType; + type SchemaObject = StringMappedType; + type SchemaDefaults = StringMappedType; + + // Extended classes + type Message = { + guild: Guild; + guildSettings: GuildSettings; + hasAtLeastPermissionLevel: Promise; + language: Language; + reactable: Boolean; + send: Promise; + sendCode: Promise; + sendEmbed: Promise; + sendMessage: Promise; + sendFile: Promise; + sendFiles: Promise; + usableCommands: Promise> + } & DiscordMessage; + + type Guild = { + language: Language; + settings: GuildSettings; + } & DiscordGuild; + + type User = { + sendCode: Promise; + sendEmbed: Promise; + sendMessage: Promise; + sendFile: Promise; + sendFiles: Promise; + } & DiscordUser; + + type TextChannel = { + attachable: boolean; + embedable: boolean; + postable: boolean; + language: Language; + sendCode: Promise; + sendEmbed: Promise; + sendMessage: Promise; + sendFile: Promise; + sendFiles: Promise; + } & DiscordTextChannel; + + type DMChannel = { + attachable: boolean; + embedable: boolean; + postable: boolean; + language: Language; + sendCode: Promise; + sendEmbed: Promise; + sendMessage: Promise; + sendFile: Promise; + sendFiles: Promise; + } & DiscordDMChannel; + + type GroupDMChannel = { + attachable: boolean; + embedable: boolean; + postable: boolean; + language: Language; + sendCode: Promise; + sendEmbed: Promise; + sendMessage: Promise; + sendFile: Promise; + sendFiles: Promise; + } & DiscordGroupDMChannel; } From 82a112f784d41bbdc94369895016d6446f667b08 Mon Sep 17 00:00:00 2001 From: kyraNET Date: Wed, 20 Sep 2017 17:23:29 +0200 Subject: [PATCH 11/12] The SemiColons. Part 1. (Wake up Travis-CI) --- typings/index.d.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 05205dc134..ffdd60087a 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -156,7 +156,7 @@ declare module 'klasa' { } - export { KlasaClient as Client } + export { KlasaClient as Client }; export class util { public static codeBlock(lang: string, expression: string): string; @@ -189,7 +189,7 @@ declare module 'klasa' { channel: RegExp, role: RegExp, snowflake: RegExp, - } + }; } export class ArgResolver extends Resolver { @@ -468,7 +468,7 @@ declare module 'klasa' { public static flatten(data: any, useColors: boolean): string; } - export { KlasaConsole as Console } + export { KlasaConsole as Console }; // Structures export class CommandMessage { @@ -957,7 +957,7 @@ declare module 'klasa' { max: number; array: boolean; sql: string; - } + }; type SchemaPiece = { type: string; @@ -966,7 +966,7 @@ declare module 'klasa' { max: number; array: boolean; sql: string; - } + }; type SettingGatewayGuildResolvable = Guild|Channel|Message|Role|Snowflake; @@ -1049,19 +1049,19 @@ declare module 'klasa' { log: string; message: KlasaConsoleMessageObject; time: KlasaConsoleTimeObject; - } + }; type KlasaConsoleMessageObject = { background: BackgroundColorTypes; text: TextColorTypes; style: StyleTypes; - } + }; type KlasaConsoleTimeObject = { background: BackgroundColorTypes; text: TextColorTypes; style: StyleTypes; - } + }; type TextColorTypes = 'black'|'red'|'green'|'yellow'|'blue'|'magenta'|'cyan'|'gray'|'grey'|'lightgray'|'lightgrey'|'lightred'|'lightgreen'|'lightyellow'|'lightblue'|'lightmagenta'|'lightcyan'|'white'|number[]|string[]; @@ -1088,7 +1088,7 @@ declare module 'klasa' { sendMessage: Promise; sendFile: Promise; sendFiles: Promise; - usableCommands: Promise> + usableCommands: Promise>; } & DiscordMessage; type Guild = { From 8c9b1a3143f012b6a25fe754372cf9a0cad3849d Mon Sep 17 00:00:00 2001 From: kyraNET Date: Wed, 20 Sep 2017 17:59:45 +0200 Subject: [PATCH 12/12] TSLint (Do not confuse with ESLint), added scripts in package.json --- package.json | 8 ++- tslint.json | 3 +- typings/index.d.ts | 142 ++++++++++++++++++++++----------------------- 3 files changed, 77 insertions(+), 76 deletions(-) diff --git a/package.json b/package.json index 3aed3bbf43..0861a3bbb5 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ "url": "https://github.com/dirigeants/klasa.git" }, "scripts": { - "lint": "npm run test -- --fix", - "test": "npx eslint src", + "lint": "npx eslint src --fix && npx tslint --fix 'typings/*.ts'", + "test": "npx eslint src && npx tslint 'typings/*.ts'", "docs": "npx jsdoc -c ./.docstrap.json -R README.md" }, "dependencies": { @@ -29,7 +29,9 @@ "devDependencies": { "eslint": "^4.6.1", "ink-docstrap": "github:bdistin/docstrap#klasa", - "jsdoc": "github:jsdoc3/jsdoc" + "jsdoc": "github:jsdoc3/jsdoc", + "tslint": "^5.7.0", + "typescript": "^2.5.2" }, "engines": { "node": ">=8.1.0" diff --git a/tslint.json b/tslint.json index 8fdeff66f5..23300ae998 100644 --- a/tslint.json +++ b/tslint.json @@ -3,7 +3,6 @@ "no-inferrable-types": [false], "no-unused-expression": true, "no-duplicate-variable": true, - "no-unused-variable": [true, {"ignore-pattern": "^_"}], "no-shadowed-variable": true, "comment-format": [ true, "check-space" @@ -30,7 +29,7 @@ "use-isnan": true, "no-trailing-whitespace": true, "quotemark": [true, "single", "avoid-escape"], - "no-use-before-declare": true, + "no-use-before-declare": false, "whitespace": [true, "check-branch", "check-decl", diff --git a/typings/index.d.ts b/typings/index.d.ts index ffdd60087a..e38ecfced1 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -28,27 +28,27 @@ declare module 'klasa' { export const version: string; class KlasaClient extends Client { - constructor(options?: KlasaClientConfig); - config: KlasaClientConfig; - coreBaseDir: string; - clientBaseDir: string; - console: Console; - argResolver: ArgResolver; - commands: CommandStore; - inhibitors: InhibitorStore; - finalizers: FinalizerStore; - monitors: MonitorStore; - languages: LanguageStore; - providers: ProviderStore; - events: EventStore; - extendables: ExtendableStore; - pieceStores: Collection; - commandMessages: Collection; - permissionLevels: PermissionLevels; - commandMessageLifetime: number; - commandMessageSweep: number; - ready: false; - methods: { + public constructor(options?: KlasaClientConfig); + public config: KlasaClientConfig; + public coreBaseDir: string; + public clientBaseDir: string; + public console: Console; + public argResolver: ArgResolver; + public commands: CommandStore; + public inhibitors: InhibitorStore; + public finalizers: FinalizerStore; + public monitors: MonitorStore; + public languages: LanguageStore; + public providers: ProviderStore; + public events: EventStore; + public extendables: ExtendableStore; + public pieceStores: Collection; + public commandMessages: Collection; + public permissionLevels: PermissionLevels; + public commandMessageLifetime: number; + public commandMessageSweep: number; + public ready: false; + public methods: { Collection: typeof Collection; Embed: typeof MessageEmbed; MessageCollector: typeof MessageCollector; @@ -56,8 +56,8 @@ declare module 'klasa' { CommandMessage: typeof CommandMessage; util: object; }; - settings: StringMappedType>; - application: object; + public settings: StringMappedType>; + public application: object; public static readonly invite: string; public static readonly owner: User; @@ -158,7 +158,7 @@ declare module 'klasa' { export { KlasaClient as Client }; - export class util { + export class Util { public static codeBlock(lang: string, expression: string): string; public static clean(text: string): string; private static initClean(client: KlasaClient): void; @@ -172,17 +172,17 @@ declare module 'klasa' { public constructor(client: KlasaClient); public client: KlasaClient; - public msg(message: Message|Snowflake, channel: Channel): Promise; - public user(user: User|GuildMember|Message|Snowflake): Promise; - public member(member: User|GuildMember|Snowflake, guild: Guild): Promise; - public channel(channel: Channel|Snowflake): Promise; - public guild(guild: Guild|Snowflake): Promise; - public role(role: Role|Snowflake, guild: Guild): Promise; - public boolean(bool: boolean|string): Promise; - public string(string: string): Promise; - public integer(integer: string|number): Promise; - public float(number: string|number): Promise; - public url(hyperlink: string): Promise; + public msg(input: Message|Snowflake, channel: Channel): Promise; + public user(input: User|GuildMember|Message|Snowflake): Promise; + public member(input: User|GuildMember|Snowflake, guild: Guild): Promise; + public channel(input: Channel|Snowflake): Promise; + public guild(input: Guild|Snowflake): Promise; + public role(input: Role|Snowflake, guild: Guild): Promise; + public boolean(input: boolean|string): Promise; + public string(input: string): Promise; + public integer(input: string|number): Promise; + public float(input: string|number): Promise; + public url(input: string): Promise; public static readonly regex: { userOrMember: RegExp, @@ -206,57 +206,57 @@ declare module 'klasa' { public language(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public provider(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public msg(message: string|Message, channel: Channel): Promise; + public msg(input: string|Message, channel: Channel): Promise; public msg(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public message(message: string|Message, channel: Channel): Promise; + public message(input: string|Message, channel: Channel): Promise; public message(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public user(user: User|GuildMember|Message|Snowflake): Promise; + public user(input: User|GuildMember|Message|Snowflake): Promise; public user(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public mention(user: User|GuildMember|Message|Snowflake): Promise; + public mention(input: User|GuildMember|Message|Snowflake): Promise; public mention(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public member(member: User|GuildMember|Snowflake, guild: Guild): Promise; + public member(input: User|GuildMember|Snowflake, guild: Guild): Promise; public member(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public channel(channel: Channel|Snowflake): Promise; + public channel(input: Channel|Snowflake): Promise; public channel(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public guild(guild: Guild|Snowflake): Promise; + public guild(input: Guild|Snowflake): Promise; public guild(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public role(role: Role|Snowflake, guild: Guild): Promise; + public role(input: Role|Snowflake, guild: Guild): Promise; public role(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public literal(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public bool(bool: boolean|string): Promise; + public bool(input: boolean|string): Promise; public bool(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public boolean(bool: boolean|string): Promise; + public boolean(input: boolean|string): Promise; public boolean(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public str(string: string): Promise; + public str(input: string): Promise; public str(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public string(string: string): Promise; + public string(input: string): Promise; public string(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public int(integer: string|number): Promise; + public int(input: string|number): Promise; public int(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public integer(integer: string|number): Promise; + public integer(input: string|number): Promise; public integer(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public num(number: string|number): Promise; + public num(input: string|number): Promise; public num(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public number(number: string|number): Promise; + public number(input: string|number): Promise; public number(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public float(number: string|number): Promise; + public float(input: string|number): Promise; public float(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public reg(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public regex(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public regexp(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; - public url(hyperlink: string): Promise; + public url(input: string): Promise; public url(arg: string, currentUsage: object, possible: number, repeat: boolean, msg: Message): Promise; public static minOrMax(value: number, min: number, max: number, currentUsage: object, possible: number, repeat: boolean, msg: Message, suffix: string): boolean; @@ -266,34 +266,34 @@ declare module 'klasa' { public command(data: any, guild: Guild, name: string): Promise; public language(data: any, guild: Guild, name: string): Promise; - public user(user: User|GuildMember|Message|Snowflake): Promise; + public user(input: User|GuildMember|Message|Snowflake): Promise; public user(data: any, guild: Guild, name: string): Promise; - public channel(channel: Channel|Snowflake): Promise; + public channel(input: Channel|Snowflake): Promise; public channel(data: any, guild: Guild, name: string): Promise; public textchannel(data: any, guild: Guild, name: string): Promise; public voicechannel(data: any, guild: Guild, name: string): Promise; - public guild(guild: Guild|Snowflake): Promise; + public guild(input: Guild|Snowflake): Promise; public guild(data: any, guild: Guild, name: string): Promise; - public role(role: Role|Snowflake, guild: Guild): Promise; + public role(input: Role|Snowflake, guild: Guild): Promise; public role(data: any, guild: Guild, name: string): Promise; - public boolean(bool: boolean|string): Promise; + public boolean(input: boolean|string): Promise; public boolean(data: any, guild: Guild, name: string): Promise; - public string(string: string): Promise; + public string(input: string): Promise; public string(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; - public integer(integer: string|number): Promise; + public integer(input: string|number): Promise; public integer(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; - public float(number: string|number): Promise; + public float(input: string|number): Promise; public float(data: any, guild: Guild, name: string, minMax: { min: number, max: number }): Promise; - public url(hyperlink: string): Promise; + public url(input: string): Promise; public url(data: any, guild: Guild, name: string): Promise; public static maxOrMin(guild: Guild, value: number, min: number, max: number, name: string, suffix: string): boolean; @@ -374,7 +374,7 @@ declare module 'klasa' { } export class SettingGateway extends SchemaManager { - constructor(store: SettingCache, type: T, validateFunction: Function, schema: object); + public constructor(store: SettingCache, type: T, validateFunction: Function, schema: object); public readonly store: SettingCache; public type: T; public engine: string; @@ -400,7 +400,7 @@ declare module 'klasa' { } export class SettingCache { - constructor(client: KlasaClient); + public constructor(client: KlasaClient); public client: KlasaClient; public resolver: SettingResolver; public guilds: SettingGateway<'guilds'>; @@ -412,7 +412,7 @@ declare module 'klasa' { } export class SQL { - constructor(client: KlasaClient, gateway: SettingGateway); + public constructor(client: KlasaClient, gateway: SettingGateway); public readonly client: KlasaClient; public readonly gateway: SettingGateway; @@ -443,7 +443,7 @@ declare module 'klasa' { public static hueToRGB(p: number, q: number, t: number): number; public static formatArray(array: string[]): string|number[]; - public format(string: string, type: { style: string|string[], background: string|number|string[], text: string|number|string[] }): string; + public format(input: string, type: { style: string|string[], background: string|number|string[], text: string|number|string[] }): string; } class KlasaConsole extends Console { @@ -463,7 +463,7 @@ declare module 'klasa' { public wtf(...data: any[]): void; public timestamp(timestamp: Date, time: string): string; - public messages(string: string, message: string): string; + public messages(input: string, message: string): string; public static flatten(data: any, useColors: boolean): string; } @@ -679,10 +679,10 @@ declare module 'klasa' { } export class Store { - init(): Promise; - load(dir: string, file: string|string[]): Piece; - loadAll(): Promise; - resolve(name: Piece|string): Piece; + public init(): Promise; + public load(dir: string, file: string|string[]): Piece; + public loadAll(): Promise; + public resolve(name: Piece|string): Piece; public static applyToClass(structure: object, skips: string[]): void; }