-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
94 lines (87 loc) · 2.82 KB
/
Copy pathapp.js
File metadata and controls
94 lines (87 loc) · 2.82 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
// Requires
const fetch = require("node-fetch");
const usuario = require("./config.json");
const link = `https://play.retro-mmo.com/users/${usuario.username}` + ".json";
// Discord
const DiscordRPC = require("discord-rpc");
const client = new DiscordRPC.Client({ transport: "ipc" });
require("dotenv").config();
// Event
(async () => {
client.on("ready", async () => {
let rank = 0;
let lifetimeExperience = "";
let username = "";
// Fetching data
const getData = () => {
fetch(link)
.then((res) => res.json())
.then(async (json) => {
// Setting data
rank = await json.rank;
lifetimeExperience = await json.lifetimeExperience;
username = await json.username;
await client
.setActivity({
// Setting the Rich Presence Activity based on what is passed in here.
buttons: [
{
label: "Play the game",
url: "https://retro-mmo.com/",
},
{
label: "Join Discord",
url: "https://discord.com/invite/bUHUKF6",
},
],
details: `Character: ${username}`,
state: `Rank: ${rank}th - Total EXP ${lifetimeExperience}`,
endTimestamp: new Date(Date.now() + 300000), // Remaining time until next update
largeImageKey: "logo",
largeImageText: "Retro MMO",
instance: true,
})
// Catch errors
.catch((err) => console.log(err));
});
};
// Initializing the Rich Presence
getData();
console.log("Discord rich presence is now running.");
console.log("Visit https://retro-mmo.com/ to play the game!");
});
// Logging in
await client
.login({ clientId: process.env.applicationID })
.catch(console.error);
})();
// Update the Rich Presence every 5 minutes
setInterval(async () => {
fetch(link)
.then((res) => res.json())
.then(async (json) => {
rank = await json.rank;
lifetimeExperience = await json.lifetimeExperience;
username = await json.username;
await client
.setActivity({
buttons: [
{
label: "Play the game",
url: "https://retro-mmo.com/",
},
{
label: "Join Discord",
url: "https://discord.com/invite/bUHUKF6",
},
],
details: `Character: ${username}`,
state: `Rank: ${rank}th - Total EXP ${lifetimeExperience}`,
endTimestamp: new Date(Date.now() + 300000),
largeImageKey: "logo",
largeImageText: "Retro MMO",
instance: true,
})
.catch((err) => console.log(err));
});
}, 300000); //Setting the interval to 5 minutes