From 381839be09be2e1b1fa563e17b7cf16e6d31a97a Mon Sep 17 00:00:00 2001 From: SomboyTiger <103308315+somboytiger@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:20:26 +0700 Subject: [PATCH] feat(ChompuBot): add presence (#8193) * Create ChompuBot Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * Delete websites/C/ChompuBot Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * Create text Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * chompubot.work Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * Delete websites/C/ChompuBot/text Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * update Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * update Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * playing & pause to function boolean Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * Add files via upload Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * update Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * delete endtimestamp TT Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * update Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * up camelCase Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * update Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * update Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * remove status loading Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> * update Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> --------- Signed-off-by: SomboyTiger <103308315+somboytiger@users.noreply.github.com> --- websites/C/ChompuBot/metadata.json | 30 +++++++ websites/C/ChompuBot/presence.ts | 138 +++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 websites/C/ChompuBot/metadata.json create mode 100644 websites/C/ChompuBot/presence.ts diff --git a/websites/C/ChompuBot/metadata.json b/websites/C/ChompuBot/metadata.json new file mode 100644 index 000000000000..8b63d0b39adc --- /dev/null +++ b/websites/C/ChompuBot/metadata.json @@ -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" + ] +} \ No newline at end of file diff --git a/websites/C/ChompuBot/presence.ts b/websites/C/ChompuBot/presence.ts new file mode 100644 index 000000000000..9333d75871db --- /dev/null +++ b/websites/C/ChompuBot/presence.ts @@ -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("div.hidden.-player-status") + .textContent === "true" + ) { + username = document.querySelector( + "[data-label='player-requester']" + ).textContent; + title = document.querySelector( + "h1.text-large.font-medium.-player-title" + ); + author = document.querySelector( + "p.text-small.mt-1.text-foreground\\/80.-player-author" + ); + playing = document.querySelector( + "svg.-player-playing" + ); + timeStartPlayer = document.querySelector( + "p.text-small.-player-position-start" + ).textContent; + timeEndPlayer = document.querySelector( + "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( + "[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( + "[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); +});