Skip to content
This repository has been archived by the owner on Aug 28, 2020. It is now read-only.

Typings (Second attempt, damn you CRLF) #26

Merged
merged 12 commits into from
Sep 20, 2017
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>}
*/
async login(token) {
const start = now();
Expand All @@ -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);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/lib/parsers/ArgResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/parsers/Resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/parsers/SettingResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/lib/settings/SQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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]]);
}
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/lib/settings/SchemaManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/settings/SettingGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 2 additions & 11 deletions src/lib/structures/CommandStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ class CommandStore extends Collection {
this.name = 'commands';
}

/**
* The specific command information needed to make our help command.
* @type {Array<Object>}
* @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.
Expand Down Expand Up @@ -121,7 +112,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) {
Expand All @@ -132,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();
Expand Down
1 change: 0 additions & 1 deletion src/lib/structures/Extendable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/structures/Finalizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down Expand Up @@ -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}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/structures/interfaces/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
83 changes: 42 additions & 41 deletions src/lib/util/Console.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,33 @@ 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.
*/

/**
* @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.
Expand Down Expand Up @@ -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;
Expand All @@ -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}
*/
Expand Down
Loading