summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
author8cy <[email protected]>2020-06-27 22:52:54 -0700
committer8cy <[email protected]>2020-06-27 22:52:54 -0700
commit80951013e391aab140800e4f386867e6c391553f (patch)
tree3d7101237ef1cd8d6fe2a2fab751a2dc55ae7d84 /src/utils
parentmore config shit (diff)
downloaddep-core-80951013e391aab140800e4f386867e6c391553f.tar.xz
dep-core-80951013e391aab140800e4f386867e6c391553f.zip
add ts defs so not a lot of errors left
- made .todo file for epic error tracking
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/Canvas.ts2
-rw-r--r--src/utils/Util.ts46
-rw-r--r--src/utils/gameDigHelper.ts5
-rw-r--r--src/utils/genCmdURL.ts2
-rw-r--r--src/utils/simpleFormat.ts2
-rw-r--r--src/utils/stripWebhookURL.ts3
-rw-r--r--src/utils/truncateText.ts2
-rw-r--r--src/utils/wait.ts2
-rw-r--r--src/utils/winPercentage.ts2
9 files changed, 37 insertions, 29 deletions
diff --git a/src/utils/Canvas.ts b/src/utils/Canvas.ts
index 4cbcac6..23ae558 100644
--- a/src/utils/Canvas.ts
+++ b/src/utils/Canvas.ts
@@ -1,3 +1,5 @@
+// TODO: all this
+//@ts-nocheck
import { createCanvas } from 'canvas'
module.exports = class CanvasUtil {
diff --git a/src/utils/Util.ts b/src/utils/Util.ts
index 6e00d04..4ad20a3 100644
--- a/src/utils/Util.ts
+++ b/src/utils/Util.ts
@@ -3,11 +3,12 @@ const yes = ['yes', 'y', 'ye', 'yeah', 'yup', 'yea', 'ya', 'hai', 'si', 'sí', '
const no = ['no', 'n', 'nah', 'nope', 'nop', 'iie', 'いいえ', 'non', 'fuck off'];
module.exports = class Util {
- static delay(ms) {
+ static delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
- static shuffle(array) {
+ // TODO: maybe infer this
+ static shuffle(array: any) {
const arr = array.slice(0);
for (let i = arr.length - 1; i >= 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
@@ -18,22 +19,22 @@ module.exports = class Util {
return arr;
}
- static list(arr, conj = 'and') {
+ static list(arr: any[], conj = 'and') {
const len = arr.length;
if (len === 0) return '';
if (len === 1) return arr[0];
return `${arr.slice(0, -1).join(', ')}${len > 1 ? `${len > 2 ? ',' : ''} ${conj} ` : ''}${arr.slice(-1)}`;
}
- static shorten(text, maxLen = 2000) {
+ static shorten(text: string, maxLen = 2000) {
return text.length > maxLen ? `${text.substr(0, maxLen - 3)}...` : text;
}
- static randomRange(min, max) {
+ static randomRange(min: number, max: number) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
- static trimArray(arr, maxLen = 10) {
+ static trimArray(arr: string[], maxLen = 10) {
if (arr.length > maxLen) {
const len = arr.length - maxLen;
arr = arr.slice(0, maxLen);
@@ -42,9 +43,9 @@ module.exports = class Util {
return arr;
}
- static removeDuplicates(arr) {
+ static removeDuplicates(arr: string | any[]) {
if (arr.length === 0 || arr.length === 1) return arr;
- const newArr = [];
+ const newArr: any[] = [];
for (let i = 0; i < arr.length; i++) {
if (newArr.includes(arr[i])) continue;
newArr.push(arr[i]);
@@ -52,42 +53,45 @@ module.exports = class Util {
return newArr;
}
- static sortByName(arr, prop) {
+ static sortByName(arr: any[], prop: string | number) {
return arr.sort((a, b) => {
if (prop) return a[prop].toLowerCase() > b[prop].toLowerCase() ? 1 : -1;
return a.toLowerCase() > b.toLowerCase() ? 1 : -1;
});
}
- static firstUpperCase(text, split = ' ') {
+ static firstUpperCase(text: string, split = ' ') {
return text.split(split).map(word => `${word.charAt(0).toUpperCase()}${word.slice(1)}`).join(' ');
}
- static formatNumber(number, minimumFractionDigits = 0) {
+ static formatNumber(number: string, minimumFractionDigits = 0) {
return Number.parseFloat(number).toLocaleString(undefined, {
minimumFractionDigits,
maximumFractionDigits: 2
});
}
- static base64(text, mode = 'encode') {
+ //TODO: maybe infer this
+ static base64(text: any, mode = 'encode') {
if (mode === 'encode') return Buffer.from(text).toString('base64');
if (mode === 'decode') return Buffer.from(text, 'base64').toString('utf8') || null;
throw new TypeError(`${mode} is not a supported base64 mode.`);
}
- static hash(text, algorithm) {
+ //TODO: maybe infer this
+ static hash(text: any, algorithm: any) {
return crypto.createHash(algorithm).update(text).digest('hex');
}
- static streamToArray(stream) {
+ //TODO: maybe infer this
+ static streamToArray(stream: any) {
if (!stream.readable) return Promise.resolve([]);
return new Promise((resolve, reject) => {
- const array = [];
- function onData(data) {
+ const array: any = [];
+ function onData(data: any) {
array.push(data);
}
- function onEnd(error) {
+ function onEnd(error: any) {
if (error) reject(error);
else resolve(array);
cleanup();
@@ -109,7 +113,7 @@ module.exports = class Util {
});
}
- static percentColor(pct, percentColors) {
+ static percentColor(pct: number, percentColors: string | any[]) {
let i = 1;
for (i; i < percentColors.length - 1; i++) {
if (pct < percentColors[i].pct) {
@@ -130,7 +134,7 @@ module.exports = class Util {
return `#${color.r}${color.g}${color.b}`;
}
- static today(timeZone) {
+ static today(timeZone: number) {
const now = new Date();
now.setHours(0);
now.setMinutes(0);
@@ -140,13 +144,13 @@ module.exports = class Util {
return now;
}
- static tomorrow(timeZone) {
+ static tomorrow(timeZone: any) {
const today = Util.today(timeZone);
today.setDate(today.getDate() + 1);
return today;
}
- static embedURL(title, url, display) {
+ static embedURL(title: any, url: string, display: any) {
return `[${title}](${url.replace(/\)/g, '%27')}${display ? ` "${display}"` : ''})`;
}
diff --git a/src/utils/gameDigHelper.ts b/src/utils/gameDigHelper.ts
index 647777d..482c87a 100644
--- a/src/utils/gameDigHelper.ts
+++ b/src/utils/gameDigHelper.ts
@@ -1,3 +1,4 @@
+//@ts-ignore no types
import ms from "ms";
import { Util, MessageEmbed } from 'discord.js'
@@ -7,7 +8,7 @@ import { Util, MessageEmbed } from 'discord.js'
* @param {Object} res Result from GameDig
* @returns {MessageEmbed}
*/
-module.exports = res => {
+module.exports = (res: any) => {
const playerCount = res.players.length
const maxPlayers = res.maxPlayers
@@ -34,7 +35,7 @@ module.exports = res => {
])
const unconfirmedValues = new Map([
- [res.raw.secure, secure => emb.addField('Vac Secured', secure ? 'Yes' : 'No')],
+ [res.raw.secure, (secure: any) => emb.addField('Vac Secured', secure ? 'Yes' : 'No')],
[res.raw.games, game => emb.addField('Game', Util.escapeMarkdown(game))]
])
diff --git a/src/utils/genCmdURL.ts b/src/utils/genCmdURL.ts
index 4d658bc..0519de0 100644
--- a/src/utils/genCmdURL.ts
+++ b/src/utils/genCmdURL.ts
@@ -1 +1 @@
-module.exports = cmd => `/commands/${cmd.group.name.toLowerCase().replace(/\s/g, "-")}/${cmd.name}`; \ No newline at end of file
+module.exports = (cmd: { group: { name: string; }; name: any; }) => `/commands/${cmd.group.name.toLowerCase().replace(/\s/g, "-")}/${cmd.name}`; \ No newline at end of file
diff --git a/src/utils/simpleFormat.ts b/src/utils/simpleFormat.ts
index 0985546..4564778 100644
--- a/src/utils/simpleFormat.ts
+++ b/src/utils/simpleFormat.ts
@@ -3,7 +3,7 @@
* @param {number|string} value Value to format
* @returns {number} A number in fixed-point notation up to 2 decimal points
*/
-module.exports = value => {
+module.exports = (value: string) => {
const result = parseFloat(parseFloat(value).toFixed(2));
return result;
}; \ No newline at end of file
diff --git a/src/utils/stripWebhookURL.ts b/src/utils/stripWebhookURL.ts
index fa8c240..73a227c 100644
--- a/src/utils/stripWebhookURL.ts
+++ b/src/utils/stripWebhookURL.ts
@@ -3,9 +3,10 @@
* @param {string} url URL for the webhook from the Discord client
* @returns {Object} Object with the webhook ID and token
*/
-module.exports = url => {
+module.exports = (url: string) => {
const regex = /https:\/\/discordapp\.com\/api\/webhooks\/(\d{1,})\/([\w-_]{1,})/;
const matches = regex.exec(url);
+ //@ts-ignore dont care if null
return { id: matches[1], token: matches[2] };
}; \ No newline at end of file
diff --git a/src/utils/truncateText.ts b/src/utils/truncateText.ts
index bd2f311..f2fa7d0 100644
--- a/src/utils/truncateText.ts
+++ b/src/utils/truncateText.ts
@@ -3,4 +3,4 @@
* @param {number} [number=2048] Number to truncate to
* @returns {string} Truncated string or original if string was short enough to begin with
*/
-module.exports = (string, number = 2048) => (string.length > number ? `${string.substring(0, number - 3)}...` : string); \ No newline at end of file
+module.exports = (string: any, number = 2048) => (string.length > number ? `${string.substring(0, number - 3)}...` : string); \ No newline at end of file
diff --git a/src/utils/wait.ts b/src/utils/wait.ts
index bac3b72..4af65f1 100644
--- a/src/utils/wait.ts
+++ b/src/utils/wait.ts
@@ -3,4 +3,4 @@
* @param {number} delay Delay in milliseconds to wait for
* @returns {Promise<resolve>}
*/
-module.exports = delay => new Promise(resolve => setTimeout(resolve, delay)); \ No newline at end of file
+module.exports = (delay: number) => new Promise(resolve => setTimeout(resolve, delay)); \ No newline at end of file
diff --git a/src/utils/winPercentage.ts b/src/utils/winPercentage.ts
index 022f079..627dab8 100644
--- a/src/utils/winPercentage.ts
+++ b/src/utils/winPercentage.ts
@@ -5,7 +5,7 @@ import config from '../config.json'
* @param {User} user User to calculate win percentage for
* @returns {number} User balance
*/
-module.exports = (multiplier, user) => {
+module.exports = (multiplier: any, user: any) => {
// Load the default setting
//let { houseEdgePercentage } = config;