Skip to content

Commit

Permalink
feat(Websim): add presence (#8951)
Browse files Browse the repository at this point in the history
  • Loading branch information
gwashark authored Dec 13, 2024
1 parent 3c462e3 commit da20b9f
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
38 changes: 38 additions & 0 deletions websites/W/Websim/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "https://schemas.premid.app/metadata/1.11",
"apiVersion": 1,
"author": {
"id": "1255528657058009088",
"name": "gwashark"
},
"service": "Websim",
"description": {
"en": "Websim.ai is an AI-powered platform that allows users to generate and explore a simulated version of the internet."
},
"url": "websim.ai",
"version": "1.0.0",
"logo": "https://i.imgur.com/zDNmRxT.png",
"thumbnail": "https://i.imgur.com/9U7mrjE.png",
"color": "#38bdf8",
"category": "other",
"tags": [
"websim","ai"
],
"settings": [
{
"id": "showButtons",
"title": "Show Buttons",
"icon": "fas fa-toggle-on",
"value": true
},
{
"id": "btnPrivacy",
"title": "Buttons Privacy",
"icon": "fas fa-user-secret",
"value": true,
"if": {
"showButtons": true
}
}
]
}
74 changes: 74 additions & 0 deletions websites/W/Websim/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const presence = new Presence({
clientId: "1315383978878046411",
}),
browsingTimestamp = Math.floor(Date.now() / 1000);

presence.on("UpdateData", async () => {
const [showButtons, btnPrivacy] = await Promise.all([
presence.getSetting("showButtons"),
presence.getSetting("btnPrivacy"),
]),
presenceData: PresenceData = {
startTimestamp: browsingTimestamp,
largeImageKey: "https://i.imgur.com/zDNmRxT.png",
},
path = document.location.pathname;

if (path === "/") presenceData.details = "Browsing the homepage.";
else if (path === "/fyp") {
presenceData.details = "Browsing the FYP.";
if (showButtons) {
presenceData.buttons = [
{
label: "View FYP",
url: "https://websim.ai/fyp",
},
];
}
} else if (path.startsWith("/@")) {
const upath = path.substring(2).split("/"),
username = upath[0];
if (upath.length === 2) {
presenceData.details = `Viewing ${document.title}`;
presenceData.state = `By ${username}`;
if (showButtons) {
presenceData.buttons = [
{
label: "View Project",
url: `https://websim.ai/@${username}/${upath[1]}`,
},
];
}
} else {
presenceData.details = `Viewing ${username}'s profile.`;
if (showButtons) {
presenceData.buttons = [
{
label: "View Profile",
url: `https://websim.ai/@${username}`,
},
];
}
}
} else if (path.startsWith("/p/")) {
const projPath = path.substring(3).split("/");
presenceData.details = `Viewing ${document.title}`;
presenceData.state = `${projPath[1] ? `Revision #${projPath[1]}` : ""}`;
if (showButtons) {
presenceData.buttons = [
{
label: "View Project",
url: `https://websim.ai/p/${projPath[0]}`,
},
];
if (!btnPrivacy) {
presenceData.buttons.push({
label: "View Revision",
url: `https://websim.ai/p/${projPath[0]}/${projPath[1]}`,
});
}
}
}

presence.setActivity(presenceData);
});

0 comments on commit da20b9f

Please sign in to comment.