@averagehelper/corde
Version:
A simple library for Discord bot tests. (Republished fork to demonstrate a bugfix)
64 lines (63 loc) • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
class UtilsManager {
constructor() {
this._delayValue = 800;
}
/**
* Default delay value for Corde interaction with Discord.js
*/
get delayValue() {
return this._delayValue;
}
/**
* Defines a delay for corde interaction with Discord data.
*
* If this interaction occur right after a message sending,
* is possible that the returned value from discord.js is not
* what is expected
*
* This is in a variable and not directly inject in the class due to
* tests purposes.
*/
setDelayValue(value) {
this._delayValue = value;
}
/**
* Pick some properties of a object
*
* @see https://www.typescriptlang.org/docs/handbook/utility-types.html#picktk
* @param obj Object to get its properties
* @param keys Properties that must be got
*/
pick(obj, ...keys) {
const copy = {};
keys.forEach((key) => (copy[key] = obj[key]));
return copy;
}
/**
* Creates a promise that finish after a defined time in milliseconds
* @param timeMilliseconds Time to the promise wait.
*/
wait(timeMilliseconds) {
return new Promise((resolve, reject) => {
if (!timeMilliseconds) {
return reject(new Error("Invalid value"));
}
if (timeMilliseconds < 0) {
return reject(new Error("Time can not be lower than 0"));
}
setTimeout(() => {
resolve();
}, timeMilliseconds);
});
}
isValuePrimitive(value) {
return (typeof value === "number" ||
typeof value === "string" ||
typeof value === "boolean" ||
typeof value === "bigint");
}
}
const Utils = new UtilsManager();
exports.default = Utils;