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
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
11 changes: 1 addition & 10 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 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
2 changes: 1 addition & 1 deletion 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should just be a string here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, in the typings, I wrote

public file: string;

But wrote the wrong type in the JSDocs (got confused with Command). Fixed 👍

* @param {FinalizerOptions} [options = {}] Optional Finalizer settings
*/
constructor(client, dir, file, options = {}) {
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
61 changes: 61 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
Loading