feat(global): add sprecators team and implement basic RET API for now

README will be then included in the future.

Signed-off-by: Andrei Jiroh Eugenio Halili <ajhalili2006@gmail.com>
This commit is contained in:
Andrei Jiroh Halili 2022-03-13 22:32:38 +08:00
parent d5111dfee7
commit 634a84f00a
Signed by: ajhalili2006
GPG Key ID: A30EBE40AD856D88
4 changed files with 71 additions and 1 deletions

37
app.js Normal file
View File

@ -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" });

View File

@ -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(),

27
lib/teams.js Normal file
View File

@ -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

View File

@ -21,5 +21,7 @@
},
"scripts": {
"start": "node app.js"
}
},
"license": "MIT",
"version": "0.1.0"
}