-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (38 loc) · 1.5 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
const { Client } = require("discord-rpc");
const rpc = new Client({ transport: "ipc" });
const axios = require("axios");
const { clientID, epicID, apiKey, assets } = require("./settings.json");
async function GetStats() {
try {
await axios.get(`https://fortnite-api.com/v2/stats/br/v2/${epicID}`, {
headers: {
'Authorization': apiKey
}
}).catch(err => {
if (err.response) throw `[ERROR] ${err.response.data.error}, Status Code: ${err.response.data.status}`;
if (err) throw err;
}).then(res => {
let data = res.data.data;
return setStatus(data.battlePass.level, data.stats.all.overall.wins, data.stats.all.overall.kills, data.stats.all.overall.deaths, data.battlePass.progress, data.account.name);
});
} catch (err) {
console.error(err);
}
}
async function setStatus(bp, wins, kills, deaths, progress, username) {
rpc.setActivity({
details: `👑 ${bp.toLocaleString()} | ${progress}% (${100 - progress}% Left)`,
state: `🏆 ${wins.toLocaleString()} | 🎯 ${kills.toLocaleString()} | 💀 ${deaths.toLocaleString()}`,
largeImageKey: assets.large_img_key,
largeImageText: `Fortnite Stats for: ${username}`
});
await new Promise((p => setTimeout(p, 60000)));
GetStats();
}
rpc.on("ready", async () => {
console.log(`FN-RPC is now initalized for Discord User: ${rpc.user.username}.`);
GetStats();
});
rpc.login({
clientId: clientID
});