This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
97 lines (85 loc) · 3.36 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
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
95
96
97
const DiscordRPC = require("discord-rpc");
const WebSocket = require("ws");
const config = require("./config");
const ws = new WebSocket(config.wsURL);
const rpc = new DiscordRPC.Client({ transport: "ipc" });
const cooldown = 15 * 1000; // activity can only be set every 15 seconds
rpc.on("ready", () => {
console.log("osu!rpc ready!");
console.log(
`Welcome ${rpc.user.username}#${rpc.user.discriminator}! (ID: ${rpc.user.id})`
);
let data;
ws.on("message", (rd) => {
data = JSON.parse(rd);
});
let setActivity = () => {
if (!data) return;
if (data.menu.bm.set <= 1) {
return rpc.setActivity({
details: `${data.menu.bm.metadata.artist} - ${data.menu.bm.metadata.title}`,
state: `In menu`,
largeImageKey: config.assetId,
});
}
let formattedData = {
beatmap: {
url: `https://osu.ppy.sh/beatmapsets/${data.menu.bm.set}`,
title: `${data.menu.bm.metadata.artist} - ${data.menu.bm.metadata.title}`,
mapper: data.menu.bm.metadata.mapper,
difficulty: data.menu.bm.metadata.difficulty,
bpm: `${
data.menu.bm.stats.BPM.min !== data.menu.bm.stats.BPM.max
? `${data.menu.bm.stats.BPM.min}-${data.menu.bm.stats.BPM.max}`
: data.menu.bm.stats.BPM.min.toString()
}`,
},
score: data.gameplay.score,
accuracy: data.gameplay.accuracy,
combo: data.gameplay.combo,
hits: {
0: data.gameplay.hits["0"],
50: data.gameplay.hits["50"],
100: data.gameplay.hits["100"],
300: data.gameplay.hits["300"],
grade: data.gameplay.hits.grade.current,
},
pp: data.gameplay.pp,
};
// In menu
if (!formattedData.hits.grade) {
return rpc.setActivity({
details: formattedData.beatmap.title,
state: `In menu`,
largeImageKey: config.assetId,
largeImageText: `BPM: ${formattedData.beatmap.bpm} | Mapper: ${formattedData.beatmap.mapper}`,
instance: false,
buttons: [{ label: "Beatmap", url: formattedData.beatmap.url }],
});
}
// In game
// let hits = `${formattedData.hits["300"]}x300 : ${formattedData.hits["100"]}x100 : ${formattedData.hits["50"]}x50 : ${formattedData.hits["0"]}xMiss`;
rpc.setActivity({
// details: `${formattedData.beatmap.title} [${formattedData.beatmap.difficulty}] mapped by ${formattedData.beatmap.mapper}`,
// state: `${formattedData.pp.current}pp | ${formattedData.hits.grade} : ${formattedData.accuracy}% : Score: ${formattedData.score} | ${hits}`,
details: `${formattedData.beatmap.title} [${formattedData.beatmap.difficulty}]`,
state: `${formattedData.pp.current}pp | ${formattedData.hits.grade} : ${formattedData.accuracy}% | Score: ${formattedData.score}`,
largeImageKey: config.assetId,
largeImageText: `Combo: ${formattedData.combo.current}x (${formattedData.combo.max}x max) | BPM: ${formattedData.beatmap.bpm}`,
buttons: [
{ label: "Beatmap", url: formattedData.beatmap.url },
{
label: "Profile",
url: `https://osu.ppy.sh/users/${encodeURI(data.gameplay.name)}`,
},
],
});
};
setActivity();
const interval = setInterval(setActivity, cooldown);
ws.on("close", () => {
clearInterval(interval);
process.exit(1);
});
});
rpc.login({ clientId: config.applicationId }).catch(console.error);