-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.js
64 lines (58 loc) · 2.3 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const config = require("./config.json");
const fs = require("fs");
const randomDelay = function(min, max) {
return Math.round(min*1000+(Math.random()*(max-min)*1000));
}
const naturalDelay = async function(bot={processCount: 0}, min=config.naturalDelay.min, max=config.naturalDelay.max, silent=false) {
return new Promise(resolve => {
const delay = randomDelay(min, max)*bot.processCount;
const process = bot.processCount;
if (!silent) console.log(`(Process ${process}) Starting ${delay}ms delay...`);
bot.processHistory.push([Date.now(), bot.processCount]);
setTimeout(() => {
if (!silent) console.log(`(Process ${process}) Finished ${delay}ms delay!`);
bot.processCount--;
bot.processHistory.push([Date.now(), bot.processCount]);
if (bot.processCount < 0) bot.processCount = 0;
resolve();
}, delay);
});
}
const price = function(usd, pkr=usd*300) {
return `*Price:* $${usd.toFixed(2)} ≈ ₨ ${pkr.toFixed(2)}`
}
const bot = {
commands: null,
help: null,
processCount: 0,
processHistory: [],
loadCommands: null,
messagesList: new Map(),
stickerQueue: []
}
bot.loadCommands = function() {
bot.commands = new Map();
fs.readdir("./commands/", (err, files) => {
if (err) return console.log(err);
let jsfile = files.filter(f => f.split(".").pop() == "js");
bot.help = "No commands were found!"
if (jsfile.length <= 0) return console.log("No commands were discovered.");
bot.help = "Commands you can use:\n\n";
jsfile.forEach((f, i) => {
delete require.cache[require.resolve(`./commands/${f}`)]
let props = require(`./commands/${f}`);
console.log(`[${i+1}] ${f} was discovered.`);
bot.commands.set(props.help.name, props);
props.help.aliases.forEach(name => bot.commands.set(name, props));
let cmd = `${i+1}. *${config.prefix}${props.help.name}* ${props.help.args}`.trim();
if (!config.enabled_commands.includes("*") && !config.enabled_commands.includes(props.help.name)) cmd = `~${cmd}~`;
bot.help += cmd+"\n";
});
bot.help += "\n<> - required\n[] - optional";
});
}
module.exports = {
naturalDelay,
price,
bot
}