-
Notifications
You must be signed in to change notification settings - Fork 0
/
timers.js
37 lines (33 loc) · 1.06 KB
/
timers.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
/* eslint-disable indent */
module.export = async (client, db) => {
var timers = await db.get("timers");
if (timers.length < 1) return;
for (var i = 0; i < timers.length; i++) {
var timer = timers[i];
if (timer.expires > Date.now()) return;
switch (timer.type) {
case "pollend":
var poll = await db.get(`poll_${timer.id}`);
var totalVotes = Object.values(poll.votes).reduce((a, b) => a + b);
var fields = poll.options.map((option) => {
return {
name: option,
value: `${poll.votes[option]} votes (${(
(poll.votes[option] / totalVotes) *
100
).toFixed(2)}%)`,
inline: true,
};
});
var pollEmbed = poll.embed;
pollEmbed.fields = fields;
var channel = client.channels.cache.get(poll.channel);
channel.messages.fetch(poll.message).then((msg) => {
msg.edit({ embeds: [pollEmbed] });
});
db.delete(`poll_${timer.id}`);
db.pull("timers", timer);
break;
}
}
};