2024-01-18 11:43:46 +00:00
|
|
|
const DiscordRPC = require("discord-auto-rpc");
|
|
|
|
const { appName, appVersion } = require("./appInfo.js");
|
|
|
|
|
|
|
|
const clientId = "1032772293220384808";
|
2024-03-11 16:34:36 +00:00
|
|
|
|
|
|
|
/** @type {DiscordRPC.AutoClient} */
|
2024-01-18 11:43:46 +00:00
|
|
|
let richPresence;
|
2024-03-11 16:34:36 +00:00
|
|
|
|
2024-01-22 11:53:59 +00:00
|
|
|
let intervalId;
|
2024-01-19 14:04:58 +00:00
|
|
|
|
2024-01-18 11:43:46 +00:00
|
|
|
let currentStatus = {
|
|
|
|
details: " ",
|
|
|
|
state: "Idle in Launcher...",
|
|
|
|
startTimestamp: new Date(),
|
|
|
|
largeImageKey: "ezppfarm",
|
|
|
|
largeImageText: `${appName} ${appVersion}`,
|
|
|
|
smallImageKey: " ",
|
|
|
|
smallImageText: " ",
|
|
|
|
buttons: [
|
|
|
|
{
|
|
|
|
label: "Download the Launcher",
|
|
|
|
url: "https://git.ez-pp.farm/EZPPFarm/EZPPLauncher/releases/latest",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Join EZPPFarm",
|
|
|
|
url: "https://ez-pp.farm/discord",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
instance: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
connect: () => {
|
|
|
|
if (!richPresence) {
|
|
|
|
richPresence = new DiscordRPC.AutoClient({ transport: "ipc" });
|
|
|
|
richPresence.endlessLogin({ clientId });
|
|
|
|
richPresence.once("ready", () => {
|
2024-04-15 11:07:40 +00:00
|
|
|
console.log(
|
|
|
|
"connected presence with user " + richPresence.user.username,
|
|
|
|
);
|
2024-01-20 00:27:22 +00:00
|
|
|
richPresence.setActivity(currentStatus);
|
|
|
|
intervalId = setInterval(() => {
|
|
|
|
richPresence.setActivity(currentStatus);
|
2024-01-18 11:43:46 +00:00
|
|
|
}, 2500);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
disconnect: async () => {
|
|
|
|
if (richPresence) {
|
2024-01-20 00:27:22 +00:00
|
|
|
clearInterval(intervalId);
|
2024-01-18 11:43:46 +00:00
|
|
|
await richPresence.clearActivity();
|
|
|
|
await richPresence.destroy();
|
|
|
|
richPresence = null;
|
|
|
|
}
|
|
|
|
},
|
2024-03-11 14:38:20 +00:00
|
|
|
updateStatus: ({ state, details, largeImageKey }) => {
|
2024-01-18 11:43:46 +00:00
|
|
|
currentStatus.state = state ?? " ";
|
|
|
|
currentStatus.details = details ?? " ";
|
2024-03-11 14:38:20 +00:00
|
|
|
currentStatus.largeImageKey = largeImageKey ?? "ezppfarm";
|
2024-01-18 11:43:46 +00:00
|
|
|
},
|
2024-03-11 17:06:24 +00:00
|
|
|
updateUser: ({ username, id }) => {
|
|
|
|
currentStatus.smallImageKey = id ? `https://a.ez-pp.farm/${id}` : " ";
|
2024-03-11 17:46:04 +00:00
|
|
|
currentStatus.smallImageText = username ?? " ";
|
2024-01-18 11:43:46 +00:00
|
|
|
},
|
2024-01-18 18:47:56 +00:00
|
|
|
update: () => {
|
2024-03-11 16:34:36 +00:00
|
|
|
if (richPresence && richPresence.user) {
|
2024-01-19 14:04:58 +00:00
|
|
|
richPresence.setActivity(currentStatus);
|
|
|
|
}
|
|
|
|
},
|
2024-01-22 15:25:29 +00:00
|
|
|
hasPresence: () => richPresence != undefined,
|
2024-01-19 14:04:58 +00:00
|
|
|
};
|