presence.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { extToCountry } from "./extToCountry";
  2. import { getDropDownSelected, getInp, toDate } from "./utils";
  3. import { handleStation } from "./handleStation";
  4. const presence = new Presence({
  5. clientId: "1217153856665026580",
  6. });
  7. export const enum Assets {
  8. Logo = "https://cdn.rcd.gg/PreMiD/websites/M/MyOnlineRadio/assets/logo.png",
  9. MicIco = "https://cdn.rcd.gg/PreMiD/websites/M/MyOnlineRadio/assets/0.png",
  10. }
  11. const enum Pages {
  12. homepage = "/",
  13. contact = "/contact",
  14. playlists = "/playlists",
  15. schedule = "/schedule",
  16. news = "/news",
  17. parteners = "/partnership",
  18. embed = "/embed-radio",
  19. }
  20. presence.on("UpdateData", async () => {
  21. if (!document.location.toString()) return;
  22. const presenceData: PresenceData = {
  23. largeImageKey: Assets.Logo,
  24. name: `My Online Radio${extToCountry(document.location.origin)}`,
  25. type: ActivityType.Listening,
  26. };
  27. switch (document.location.pathname) {
  28. case Pages.homepage:
  29. presenceData.details = "Browsing Stations (home)";
  30. break;
  31. case Pages.contact:
  32. {
  33. const to = getDropDownSelected("to");
  34. presenceData.details = `Sending feedback${
  35. to ? ` to ${to.split(" - ")[0]}` : ""
  36. }`;
  37. }
  38. break;
  39. case Pages.parteners:
  40. {
  41. presenceData.details = "Applying to be a partener!";
  42. }
  43. break;
  44. case Pages.embed:
  45. {
  46. const to = getDropDownSelected("rid");
  47. presenceData.details = `Embdedding${
  48. to ? ` ${to.split(" - ")[0]}` : ""
  49. }`;
  50. if (to) {
  51. const server = getDropDownSelected("rsu_id");
  52. if (server) presenceData.largeImageText = server;
  53. }
  54. }
  55. break;
  56. case Pages.playlists:
  57. {
  58. const title = getInp("name") || "",
  59. from = getInp("from"),
  60. to = getInp("to"),
  61. channel = getDropDownSelected("rid");
  62. presenceData.details = `Searching playlists ${
  63. title ? `for ${title}` : ""
  64. }`;
  65. if (from && to)
  66. presenceData.largeImageText = `From ${toDate(from)} to ${toDate(to)}`;
  67. if (channel === "Radio channel") presenceData.state = " any channel";
  68. else if (channel) presenceData.state = `In Channel ${channel}`;
  69. }
  70. break;
  71. case Pages.news:
  72. {
  73. const title = getInp("name"),
  74. from = getInp("from"),
  75. to = getInp("to");
  76. presenceData.details = `Browsing news from ${
  77. title ? `for ${title}` : ""
  78. }`;
  79. if (from && to)
  80. presenceData.state = `From ${toDate(from)} to ${toDate(to)}`;
  81. }
  82. break;
  83. case Pages.schedule:
  84. {
  85. presenceData.details = "Browsing Radio Programs";
  86. }
  87. break;
  88. default:
  89. // deal with individual radio stations here
  90. handleStation(presence, presenceData);
  91. break;
  92. }
  93. presence.setActivity(presenceData);
  94. });