-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (52 loc) · 1.78 KB
/
index.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
const Discord = require("discord.js");
const mvpModel = require("./models/mvp");
const { discord, guildId, avatar, channel, audios } = require("./utils/horizonUtils");
const { timer } = require("./commands/timer");
require("./database");
require('./server');
const bot = new Discord.Client();
bot.on("ready", () => {
console.log("[Bot] Connected");
});
bot.on("message", async (message) => {
if (message.author.bot) return;
if (message.channel.id != channel) return;
if (message.content === "!timer") {
timer(message);
}
});
async function mvpAlert(player, name, spot) {
const guild = bot.guilds.cache.get(guildId);
const channelId = guild.voiceStates.cache.get(player).channelID;
if (channelId) {
const connection = await guild.channels.cache.get(channelId).join();
connection.play(audios.tuturu).on("finish", () => {
connection.play(audios.mvpAlert).on("finish", () => {
guild.channels.cache.get(channelId).leave();
});
});
}
const msg = new Discord.MessageEmbed()
.setTitle("MVP Timer")
.setDescription(
`O MVP \`${name}\` irá renascer em 5 minutos no spot \`${spot}\` <@${player}>`
)
.setTimestamp(Date.now())
.setFooter("by Bravan", avatar);
const textChannel = guild.channels.cache.get(channel);
textChannel.send(msg);
}
setInterval(async () => {
const mvps = await mvpModel.find({});
mvps.forEach(async(mvp) => {
if (!mvp.alive) {
var now = Date.now();
const time = mvp.nextRespawn - now;
if (time < 0) {
await mvp.updateOne({ alive: true });
mvpAlert(mvp.player, mvp.name, mvp.spot);
}
}
});
}, 5000);
bot.login(discord);