presence.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const presence = new Presence({
  2. clientId: '994723983415062548',
  3. })
  4. const browsingTimestamp = Math.floor(Date.now() / 1000)
  5. presence.on('UpdateData', async () => {
  6. const presenceData: PresenceData = {
  7. largeImageKey: 'https://cdn.rcd.gg/PreMiD/websites/D/Dungeon%20Crawl%20Stone%20Soup/assets/logo.png',
  8. startTimestamp: browsingTimestamp,
  9. }
  10. if (window.location.hash === '#lobby') {
  11. presenceData.details = 'Browsing lobby'
  12. }
  13. else if (window.location.hash.startsWith('#watch')) {
  14. presenceData.details = `Spectating: ${
  15. document.querySelector<HTMLSpanElement>('#stats_titleline')?.textContent
  16. }`
  17. presenceData.state = `XL: ${
  18. document.querySelector<HTMLSpanElement>('#stats_xl')?.textContent
  19. } | Location: ${
  20. document.querySelector<HTMLSpanElement>('#stats_place')?.textContent
  21. }`
  22. presenceData.buttons = [
  23. {
  24. label: 'Spectate',
  25. url: document.location.href,
  26. },
  27. ]
  28. }
  29. else if (window.location.hash.startsWith('#play-')) {
  30. presenceData.details = `Playing as: ${
  31. document.querySelector<HTMLSpanElement>('#stats_titleline')?.textContent
  32. }`
  33. presenceData.state = `XL: ${
  34. document.querySelector<HTMLSpanElement>('#stats_xl')?.textContent
  35. } | Location: ${
  36. document.querySelector<HTMLSpanElement>('#stats_place')?.textContent
  37. }`
  38. presenceData.buttons = [
  39. {
  40. label: 'Spectate',
  41. url: `${document.location.origin}/#watch-${document
  42. .querySelector<HTMLSpanElement>('#stats_titleline')
  43. ?.textContent
  44. ?.split('the')[0]
  45. ?.trim()}`,
  46. },
  47. ]
  48. }
  49. if (presenceData.details)
  50. presence.setActivity(presenceData)
  51. else presence.setActivity()
  52. })