forked from PreMiD/Presences
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Toyhouse): add presence (PreMiD#6752)
Co-authored-by: Rhys Rakoff <64903135+EncryptedDev@users.noreply.github.com>
- Loading branch information
1 parent
e37477b
commit 0acfde9
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist/" | ||
} | ||
} |