1
0
mirror of https://github.com/spacebarchat/spacebarchat.git synced 2024-11-22 18:32:36 +01:00
spacebarchat/scripts/rpc/index.js

53 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-02-07 07:52:57 +01:00
const { Client } = require("discord-rpc");
var startTimestamp = new Date();
async function reconnect() {
try {
await login();
} catch (error) {
console.error("discord not open:", error);
setTimeout(async () => {
await reconnect();
}, 1000 * 10);
}
}
reconnect();
async function login() {
console.log("login");
rpc = new Client({
transport: "ipc",
});
rpc.on("ready", () => {
console.log("logged in: ", rpc.user.username);
rpc.setActivity({
2021-08-01 23:46:28 +02:00
details: `Free open source selfhostable`,
state: `Chat, voice, video and discord-compatible platform`,
2021-02-07 07:52:57 +01:00
startTimestamp,
2021-08-01 23:46:28 +02:00
smallImageText: "flam3rboy",
2021-02-07 07:52:57 +01:00
largeImageKey: "logo2",
2021-02-09 12:19:42 +01:00
largeImageText: "Fosscord",
2021-02-07 07:52:57 +01:00
instance: false,
buttons: [
{ label: "Discord", url: "https://discord.gg/ZrnGQP6p3d" },
{
2021-08-01 23:46:28 +02:00
label: "Website",
url: "https://fosscord.com",
2021-02-07 07:52:57 +01:00
},
],
});
});
rpc.on("disconnected", async () => {
console.log("disconnected");
await reconnect();
});
return rpc.login({ clientId: "807686638742142988" });
}