This repository has been archived by the owner on May 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
91 lines (89 loc) · 2.82 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
const { ValClient } = require("valclient.js");
const RPC = require("discord-rpc");
const client = new ValClient();
const rpc = new RPC.Client({
transport: "ipc",
});
const gamemodeToString = (mode) => {
return mode === "unrated"
? "Unrated"
: mode === "competitive"
? "Competitive"
: mode === "spikerush"
? "Spike Rush"
: mode === "deathmatch"
? "Deathmatch"
: mode === "onefa"
? "Replication"
: "Escalation";
};
console.clear();
console.log("Starting");
client
.init({ region: "ap" })
.then(async () => {
rpc.once("ready", () => {
console.clear();
console.log("Running");
console.log("VALORANT Rich Presence by EmangGek");
let time = null;
rpc.setActivity({
details: "Loading",
state: "Loading",
startTimestamp: "",
largeImageKey: "logo",
});
setInterval(async () => {
try {
const data = {
details: "Loading",
state: "Loading",
startTimestamp: "",
largeImageKey: "logo",
};
const session = await client.session.current();
if (session.loopState !== "INGAME") time = null;
if (session.loopState == "MENUS") {
const party = await client.group.currentDetails();
data.details = "In Menu";
if (party.State === "CUSTOM_GAME_SETUP") {
data.state = `Custom Game (${party.Members.length} of ${party.CustomGameData.MaxPartySize})`;
} else {
if (party.State === "MATCHMAKING") data.details = "In Queue";
data.state = `${gamemodeToString(
party.MatchmakingData.QueueID
)} (${party.Members.length} of 5)`;
}
} else if (session.loopState == "PREGAME") {
const pregame = await client.pre_game.details();
data.details = "Agent Select";
data.state = gamemodeToString(pregame.QueueID) || "Custom Game";
} else if (session.loopState == "INGAME") {
const game = await client.live_game.details();
data.details = "In Game";
if (time === null) {
time = Date.now();
}
data.startTimestamp = time;
if (game.ProvisioningFlow === "Matchmaking") {
data.state = gamemodeToString(game.MatchmakingData.QueueID);
} else {
data.state = "Custom Game";
}
}
rpc.setActivity(data);
} catch (e) {
console.clear();
console.log("FAILED TO FETCH ACTIVITY");
}
}, 15000);
});
rpc.login({ clientId: "937135989330182174" });
})
.catch(async (e) => {
console.clear();
console.log("VALORANT is not running");
await new Promise((resolve) => {
setTimeout(resolve, 5000);
});
});