presence.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. const presence = new Presence({
  2. clientId: "1315383978878046411",
  3. }),
  4. browsingTimestamp = Math.floor(Date.now() / 1000);
  5. presence.on("UpdateData", async () => {
  6. const [showButtons, btnPrivacy] = await Promise.all([
  7. presence.getSetting("showButtons"),
  8. presence.getSetting("btnPrivacy"),
  9. ]),
  10. presenceData: PresenceData = {
  11. startTimestamp: browsingTimestamp,
  12. largeImageKey:
  13. "https://cdn.rcd.gg/PreMiD/websites/W/Websim/assets/logo.png",
  14. },
  15. path = document.location.pathname;
  16. if (path === "/") presenceData.details = "Browsing the homepage.";
  17. else if (path === "/fyp") {
  18. presenceData.details = "Browsing the FYP.";
  19. if (showButtons) {
  20. presenceData.buttons = [
  21. {
  22. label: "View FYP",
  23. url: "https://websim.ai/fyp",
  24. },
  25. ];
  26. }
  27. } else if (path.startsWith("/@")) {
  28. const upath = path.substring(2).split("/"),
  29. username = upath[0];
  30. if (upath.length === 2) {
  31. presenceData.details = `Viewing ${document.title}`;
  32. presenceData.state = `By ${username}`;
  33. if (showButtons) {
  34. presenceData.buttons = [
  35. {
  36. label: "View Project",
  37. url: `https://websim.ai/@${username}/${upath[1]}`,
  38. },
  39. ];
  40. }
  41. } else {
  42. presenceData.details = `Viewing ${username}'s profile.`;
  43. if (showButtons) {
  44. presenceData.buttons = [
  45. {
  46. label: "View Profile",
  47. url: `https://websim.ai/@${username}`,
  48. },
  49. ];
  50. }
  51. }
  52. } else if (path.startsWith("/p/")) {
  53. const projPath = path.substring(3).split("/");
  54. presenceData.details = `Viewing ${document.title}`;
  55. presenceData.state = `${projPath[1] ? `Revision #${projPath[1]}` : ""}`;
  56. if (showButtons) {
  57. presenceData.buttons = [
  58. {
  59. label: "View Project",
  60. url: `https://websim.ai/p/${projPath[0]}`,
  61. },
  62. ];
  63. if (!btnPrivacy) {
  64. presenceData.buttons.push({
  65. label: "View Revision",
  66. url: `https://websim.ai/p/${projPath[0]}/${projPath[1]}`,
  67. });
  68. }
  69. }
  70. }
  71. presence.setActivity(presenceData);
  72. });