-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (51 loc) · 1.7 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
const getAccesToken = require("./logsApi/accessToken");
const getReportData = require("./logsApi/reportData");
const dotenv = require("dotenv").config();
const Discord = require("discord.js");
const client = new Discord.Client();
const fs = require("fs");
const embedMaker = require("./embedMaker");
const files = fs.readdirSync(__dirname);
client.on("ready", () => {
console.log("online");
});
client.on("message", async (message) => {
let reportCode;
if (message.content == "pleasemakeemojis") {
const emojiList = message.guild.emojis.cache;
for (const file of files) {
const emojiname = file.slice(0, -4);
if (file == "index.js") continue;
if (emojiList.find((element) => element.name == emojiname) != undefined) {
console.log(`Already have ${emojiname}`);
continue;
}
await message.guild.emojis
.create(file, file.slice(0, -4))
.then((emoji) =>
console.log(`Created new emoji with name ${emoji.name}!`)
)
.catch(console.error);
}
}
if (message.content.startsWith("https://www.warcraftlogs.com/reports/")) {
reportCode = message.content.slice(37);
if (reportCode.length >= 16) reportCode = reportCode.slice(0, 16);
if (reportCode.length != 16) return;
} else return;
try {
const botToken = await getAccesToken();
const reportData = await getReportData(botToken, reportCode);
if (reportData.report.rankings.data.length > 1)
return message.reply(
"Make sure your report contains only one dungeon report."
);
const embed = embedMaker(message.guild, reportData, reportCode)
message.channel.send(embed);
message.delete();
} catch (error) {
message.channel.send(error)
return console.log(error)
}
});
client.login(process.env.DISCORD_BOT_TOKEN);