forked from Siris2314/NecroAtomicBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions2.js
More file actions
110 lines (110 loc) · 4.29 KB
/
functions2.js
File metadata and controls
110 lines (110 loc) · 4.29 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
module.exports = {
getMember: function(message, toFind = "") {
try{
toFind = toFind.toLowerCase();
let target = message.guild.members.get(toFind);
if (!target && message.mentions.members) target = message.mentions.members.first();
if (!target && toFind) {
target = message.guild.members.find((member) => {
return member.displayName.toLowerCase().includes(toFind) || member.user.tag.toLowerCase().includes(toFind);
});
}
if (!target) target = message.member;
return target;
}catch (e){
console.log(String(e.stack).bgRed)
}
},
//changeging the duration from ms to a date
duration: function(ms) {
const sec = Math.floor((ms / 1000) % 60).toString();
const min = Math.floor((ms / (60 * 1000)) % 60).toString();
const hrs = Math.floor((ms / (60 * 60 * 1000)) % 60).toString();
const days = Math.floor((ms / (24 * 60 * 60 * 1000)) % 60).toString();
return `\`${days}Days\`,\`${hrs}Hours\`,\`${min}Minutes\`,\`${sec}Seconds\``;
},
//function for awaiting reactions
promptMessage: async function(message, author, time, validReactions) {
try{
time *= 1000;
for (const reaction of validReactions) await message.react(reaction);
const filter = (reaction, user) => validReactions.includes(reaction.emoji.name) && user.id === author.id;
return message.awaitReactions(filter, {
max: 1,
time: time
}).then((collected) => collected.first() && collected.first().emoji.name);
}catch (e){
console.log(String(e.stack).bgRed)
}
},
//Function to wait some time
delay: function(delayInms) {
try{
return new Promise((resolve) => {
setTimeout(() => {
resolve(2);
}, delayInms);
});
}catch (e){
console.log(String(e.stack).bgRed)
}
},
//randomnumber between 0 and x
getRandomInt: function(max) {
try{
return Math.floor(Math.random() * Math.floor(max));
}catch (e){
console.log(String(e.stack).bgRed)
}
},
//random number between y and x
getRandomNum: function(min, max) {
try{
return Math.floor(Math.random() * Math.floor((max - min) + min));
}catch (e){
console.log(String(e.stack).bgRed)
}
},
//function for creating a bar
createBar: function(maxtime, currenttime, size = 25, line = "▬", slider = "🔶") {
try{
let bar = currenttime > maxtime ? [line.repeat(size / 2 * 2), (currenttime / maxtime) * 100] : [line.repeat(Math.round(size / 2 * (currenttime / maxtime))).replace(/.$/, slider) + line.repeat(size - Math.round(size * (currenttime / maxtime)) + 1), currenttime / maxtime];
if (!String(bar).includes("🔶")) return `**[🔶${line.repeat(size - 1)}]**\n**00:00:00 / 00:00:00**`;
return `**[${bar[0]}]**\n**${new Date(currenttime).toISOString().substr(11, 8)+" / "+(maxtime==0?" ◉ LIVE":new Date(maxtime).toISOString().substr(11, 8))}**`;
}catch (e) {
console.log(String(e.stack).bgRed)
}
},
format: function(millis) {
try{
var h = Math.floor(millis / 3600000),
m = Math.floor(millis / 60000),
s = ((millis % 60000) / 1000).toFixed(0);
if (h < 1) return (m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s + " | " + (Math.floor(millis / 1000)) + " Seconds";
else return (h < 10 ? "0" : "") + h + ":" + (m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s + " | " + (Math.floor(millis / 1000)) + " Seconds";
}catch (e){
console.log(String(e.stack).bgRed)
}
},
escapeRegex: function(str) {
try{
return str.replace(/[.*+?^${}()|[\]\\]/g, `\\$&`);
}catch (e){
console.log(String(e.stack).bgRed)
}
},
arrayMove: function(array, from, to) {
try{
array = [...array];
const startIndex = from < 0 ? array.length + from : from;
if (startIndex >= 0 && startIndex < array.length) {
const endIndex = to < 0 ? array.length + to : to;
const [item] = array.splice(from, 1);
array.splice(endIndex, 0, item);
}
return array;
}catch (e){
console.log(String(e.stack).bgRed)
}
}
}