Skip to content

Commit

Permalink
feat(Toyhouse): add presence (PreMiD#6752)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Rakoff <64903135+EncryptedDev@users.noreply.github.com>
  • Loading branch information
RisingSunLight42 and EncryptedDev authored Sep 5, 2022
1 parent e37477b commit 0acfde9
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
33 changes: 33 additions & 0 deletions websites/T/Toyhouse/dist/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "https://schemas.premid.app/metadata/1.7",
"author": {
"name": "RisingSunLight",
"id": "240521747852558347"
},
"service": "Toyhouse",
"description": {
"en": "A community for collaborative character creation and trading, worldbuilding and roleplay.",
"fr": "Une communauté pour collaborer dans la création et l'échange de personnages, le worldbuilding et le roleplay."
},
"url": "toyhou.se",
"version": "1.0.0",
"logo": "https://i.imgur.com/3ltOcr0.png",
"thumbnail": "https://i.imgur.com/KPSN06b.png",
"color": "#5ab5d1",
"category": "other",
"tags": [
"community",
"toyhouse",
"worldbuilding",
"roleplay",
"trading"
],
"settings": [
{
"id": "buttons",
"title": "Show Buttons",
"icon": "fas fa-compress-arrows-alt",
"value": true
}
]
}
72 changes: 72 additions & 0 deletions websites/T/Toyhouse/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const presence = new Presence({ clientId: "1014873319419424869" }),
browsingTimestamp = Math.floor(Date.now() / 1000),
staticsPages: { [name: string]: string } = {
"": "Viewing homepage",
"~rules": "Reading rules",
"~tos": "Reading ToS",
"~account": "Managing their account",
};

enum Assets {
Logo = "https://i.imgur.com/3ltOcr0.png",
Reading = "https://i.imgur.com/53N4eY6.png",
}

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: Assets.Logo,
startTimestamp: browsingTimestamp,
},
{ pathname } = document.location,
pathArr = pathname.split("/"),
showButtons = await presence.getSetting<boolean>("buttons");

switch (pathArr[1]) {
case "~faq":
case "~browse": {
const condition = pathArr[1] === "~faq";
presenceData.details = condition ? "Browsing characters" : "Reading FAQ";
presenceData.state = `Category: ${pathArr[2]}`;
if (condition) presenceData.largeImageKey = Assets.Reading;
break;
}
default: {
const pageType = document.querySelector("li.header").textContent.trim();
if (Object.keys(staticsPages).includes(pathArr[1]))
presenceData.details = staticsPages[pathArr[1]];
else if (pageType === "User") {
presenceData.details = "Viewing an user page";
presenceData.state = document.querySelector(
".display-user-username"
).textContent;
presenceData.buttons = [
{
label: "View User",
url: document.querySelector<HTMLLinkElement>("span > a").href,
},
];
} else if (pageType === "Character") {
const characterQuery = document.querySelector<HTMLLinkElement>(
".display-character > a"
);
presenceData.details = "Viewing a character";
presenceData.state = characterQuery.textContent;
presenceData.buttons = [
{
label: "View Character",
url: characterQuery.href,
},
{
label: "View Possessor",
url: document.querySelector<HTMLLinkElement>("span > a").href,
},
];
}
}
}

if (!showButtons) delete presenceData.buttons;

if (presenceData.details) presence.setActivity(presenceData);
else presence.setActivity();
});
6 changes: 6 additions & 0 deletions websites/T/Toyhouse/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist/"
}
}

0 comments on commit 0acfde9

Please sign in to comment.