Skip to content

Commit

Permalink
feat(ChompuBot): add presence (#8193)
Browse files Browse the repository at this point in the history
* Create ChompuBot

Signed-off-by: SomboyTiger <[email protected]>

* Delete websites/C/ChompuBot

Signed-off-by: SomboyTiger <[email protected]>

* Create text

Signed-off-by: SomboyTiger <[email protected]>

* chompubot.work

Signed-off-by: SomboyTiger <[email protected]>

* Delete websites/C/ChompuBot/text

Signed-off-by: SomboyTiger <[email protected]>

* update

Signed-off-by: SomboyTiger <[email protected]>

* update

Signed-off-by: SomboyTiger <[email protected]>

* playing & pause to function boolean

Signed-off-by: SomboyTiger <[email protected]>

* Add files via upload

Signed-off-by: SomboyTiger <[email protected]>

* update

Signed-off-by: SomboyTiger <[email protected]>

* delete endtimestamp TT

Signed-off-by: SomboyTiger <[email protected]>

* update

Signed-off-by: SomboyTiger <[email protected]>

* up camelCase

Signed-off-by: SomboyTiger <[email protected]>

* update

Signed-off-by: SomboyTiger <[email protected]>

* update

Signed-off-by: SomboyTiger <[email protected]>

* remove status loading

Signed-off-by: SomboyTiger <[email protected]>

* update

Signed-off-by: SomboyTiger <[email protected]>

---------

Signed-off-by: SomboyTiger <[email protected]>
  • Loading branch information
somboytiger authored Mar 29, 2024
1 parent 99197fa commit 381839b
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 0 deletions.
30 changes: 30 additions & 0 deletions websites/C/ChompuBot/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://schemas.premid.app/metadata/1.10",
"author": {
"id": "919878532228841532",
"name": "somboytiger"
},
"service": "ChompuBot",
"description": {
"en": "Chompu is Discord bot music support stream Joox, TikTok, Distrokid, Spotify, AppleMusic, Soundcloud, Clyp, PornHub and etc. Can req song on website/dashboard",
"th": "Chompu คือ บอทดิสคอร์ดที่มาพร้อมด้วยระบบสตรีมเล่นเพลงที่สามารถจัดการหรือเพิ่มคิวเพลงบนเว็บไซต์! รองรับสตรีมเล่นเพลงหลายแพลตฟอร์ม Joox, TikTok, Distrokid, Spotify, AppleMusic, Soundcloud, Clyp, PornHub และอื่นๆอีกมากมาย!"
},
"url": "chompubot.work",
"matches": [
"*://chompubot.work/*"
],
"version": "1.0.0",
"logo": "https://chompubot.work/logo.jpg",
"thumbnail": "https://chompubot.work/thumbnail.jpg",
"color": "#ffbcff",
"category": "music",
"tags": [
"music",
"music-room",
"discordbot",
"dashboard",
"chompu",
"chompubot",
"player"
]
}
138 changes: 138 additions & 0 deletions websites/C/ChompuBot/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
const presence = new Presence({
clientId: "1219713910165209169",
}),
browsingTimestamp = Math.floor(Date.now() / 1000);

const enum Assets {
Logo = "https://chompubot.work/logo.jpg",
}

const enum Pages {
Home = "/",
Commands = "/commands",
Dashboard = "/dashboard",
FAQ = "/faq",
Contact = "/contact",
}

let presenceData: PresenceData;

presence.on("UpdateData", async () => {
const base = document.location.pathname;

if (/\/dashboard\/guild\/(.*[0-9_].*)\/music-room/gi.test(base)) {
let username,
title,
author,
playing,
timeStartPlayer,
timeEndPlayer,
startPlayer,
durationPlayer,
startTimestamp,
endTimestamp;

if (
document.querySelector<HTMLElement>("div.hidden.-player-status")
.textContent === "true"
) {
username = document.querySelector<HTMLAnchorElement>(
"[data-label='player-requester']"
).textContent;
title = document.querySelector<HTMLAnchorElement>(
"h1.text-large.font-medium.-player-title"
);
author = document.querySelector<HTMLAnchorElement>(
"p.text-small.mt-1.text-foreground\\/80.-player-author"
);
playing = document.querySelector<HTMLAnchorElement>(
"svg.-player-playing"
);
timeStartPlayer = document.querySelector<HTMLElement>(
"p.text-small.-player-position-start"
).textContent;
timeEndPlayer = document.querySelector<HTMLElement>(
"p.text-small.text-foreground\\/50.-player-position-end"
).textContent;
[startPlayer, durationPlayer] = [
presence.timestampFromFormat(timeStartPlayer),
(() => {
return presence.timestampFromFormat(timeEndPlayer);
})(),
];
[startTimestamp, endTimestamp] = presence.getTimestamps(
startPlayer,
durationPlayer
);

presenceData = {
details: title,
state: author,
largeImageKey: document.querySelector<HTMLImageElement>(
"[data-label='guild-logo']"
).src,
smallImageKey: playing ? Assets.Play : Assets.Pause,
smallImageText: playing ? "Playing" : "Pause",
startTimestamp,
endTimestamp,
buttons: [
{
label: `Join Player ${username}`,
url: document.location.href,
},
],
};

if (!playing) {
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
}
} else {
presenceData = {
details: "No song queue found",
state: "In the server...",
largeImageKey: document.querySelector<HTMLImageElement>(
"[data-label='guild-logo']"
).src,
smallImageKey: Assets.Reading,
smallImageText: "Zzz",
startTimestamp: browsingTimestamp,
buttons: [
{
label: "Join Player",
url: document.location.href,
},
],
};
}
} else {
presenceData = {
details: "Idk",
state: "Browsing...",
largeImageKey: Assets.Logo,
smallImageKey: Assets.Reading,
smallImageText: "Zzz",
startTimestamp: browsingTimestamp,
};

switch (base) {
case Pages.Home:
presenceData.details = "Home";
break;
case Pages.Commands:
presenceData.details = "Commands";
break;
case Pages.Dashboard:
presenceData.details = "Dashboard";
break;
case Pages.FAQ:
presenceData.details = "FAQ";
break;
case Pages.Contact:
presenceData.details = "Contact";
break;
}
}

presence.setActivity(presenceData);
});

0 comments on commit 381839b

Please sign in to comment.