1
0
mirror of https://github.com/spacebarchat/spacebarchat.git synced 2024-11-25 03:43:31 +01:00

discord rpc

This commit is contained in:
TimSchweiz 2021-02-07 07:52:57 +01:00
parent 48e391611d
commit dd70e1192b
4 changed files with 1615 additions and 0 deletions

1
rpc/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/node_modules/

52
rpc/index.js Normal file
View File

@ -0,0 +1,52 @@
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({
details: `Working Discord Open Source `,
state: `Collaboration open`,
startTimestamp,
largeImageKey: "logo2",
largeImageText: "Discord Open Source",
instance: false,
buttons: [
{ label: "Discord", url: "https://discord.gg/ZrnGQP6p3d" },
{
label: "Repository",
url:
"https://github.com/discord-open-source/discord-open-source",
},
],
});
});
rpc.on("disconnected", async () => {
console.log("disconnected");
await reconnect();
});
return rpc.login({ clientId: "807686638742142988" });
}

1547
rpc/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

15
rpc/package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "rpc",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"discord-rpc": "github:discordjs/rpc",
"pm2": "^4.5.4"
}
}