diff --git a/app.js b/app.js new file mode 100644 index 0000000..a3b64c1 --- /dev/null +++ b/app.js @@ -0,0 +1,37 @@ +const express = require("express") +const app = new express() +const RPC = require('discord-rpc'); +const client = new RPC.Client({ transport: 'ipc' }); +const { defaultActivity } = require("./lib/defaults"); +const { teamsIndex } = require("./lib/teams") +const port = process.env.PORT || 60881 + +app.get("/changeTeams/:teamSlug", (res, req) => { + if (req.teamSlug == "sprecators") { + client.setActivity({ + pid: process.pid, + activity: teamsIndex.regularEvents.sprecators + }) + } else { + res.status(404).json({ + ok: false, + error: "Team not found on index." + }) + } +}) + +app.listen(port, () => { + console.log("info: REST API is up at http://localhost:"+port+", see the docs for details on how to use it.") +}) + +client.on('ready', async () => { + client.request("SET_ACTIVITY", { pid: process.pid, activity: defaultActivity }); + console.log("info: Successfully set default activity for upcoming stream. Check docs on how to change them via API."); +}); +client.on('connected', async () => { + console.log("info: Connected to Discord RPC"); +}); + + +// Uses the unofficial MCC.Live OAuth client ID from Andrei Jiroh. +client.login({ clientId: "952456760948559932" }); \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js index 168cc3d..726d614 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -11,6 +11,10 @@ let defaultActivity = { "label": "Check event stats", "url": "https://mcc.live" }, + { + "label": "View source", + "url": "https://gitlab.com/RecapTime/mcc-discord-rpc" + } ], timestamp: { start: Date.now(), diff --git a/lib/teams.js b/lib/teams.js new file mode 100644 index 0000000..3c21ac3 --- /dev/null +++ b/lib/teams.js @@ -0,0 +1,27 @@ +let teamsIndex = { + regularEvents: { + sprecators: { + description: "Watching Admin Stream", + assets: { + large_image: "mcc-twitter", + large_text: "MC Championship" + }, + buttons: [ + { + "label": "Check event stats / Where To Watch", + "url": "https://mcc.live" + }, + { + "label": "View source", + "url": "https://gitlab.com/RecapTime/mcc-discord-rpc" + } + ], + timestamp: { + start: Date.now() + } + } + }, + specialEvents: {} +} + +module.exports = teamsIndex \ No newline at end of file diff --git a/package.json b/package.json index ad233a1..c031ac3 100644 --- a/package.json +++ b/package.json @@ -21,5 +21,7 @@ }, "scripts": { "start": "node app.js" - } + }, + "license": "MIT", + "version": "0.1.0" }