@overlaysymphony/twitch 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/package.json +6 -2
  2. package/src/authentication/authentication.ts +1 -1
  3. package/src/authentication/index.ts +1 -1
  4. package/src/chat/chat.ts +69 -134
  5. package/src/chat/helpers.ts +33 -24
  6. package/src/chat/index.ts +4 -6
  7. package/src/chat/pronouns.ts +141 -0
  8. package/src/eventsub/events/automod.message.hold-2.ts +81 -0
  9. package/src/eventsub/events/automod.message.update-2.ts +94 -0
  10. package/src/eventsub/events/automod.settings.update-1.ts +65 -0
  11. package/src/eventsub/events/automod.terms.update-1.ts +59 -0
  12. package/src/eventsub/events/channel.ad_break.begin-1.ts +50 -0
  13. package/src/eventsub/events/channel.ban-1.ts +58 -0
  14. package/src/eventsub/events/channel.bits.use-1.ts +112 -0
  15. package/src/eventsub/events/channel.channel_points_automatic_reward_redemption.add-2.ts +88 -0
  16. package/src/eventsub/events/channel.channel_points_custom_reward.add-1.ts +101 -0
  17. package/src/eventsub/events/channel.channel_points_custom_reward.remove-1.ts +103 -0
  18. package/src/eventsub/events/channel.channel_points_custom_reward.update-1.ts +103 -0
  19. package/src/eventsub/events/channel.channel_points_custom_reward_redemption.add-1.ts +65 -0
  20. package/src/eventsub/events/channel.channel_points_custom_reward_redemption.update-1.ts +65 -0
  21. package/src/eventsub/events/channel.charity_campaign.donate-1.ts +69 -0
  22. package/src/eventsub/events/channel.charity_campaign.progress-1.ts +74 -0
  23. package/src/eventsub/events/channel.charity_campaign.start-1.ts +76 -0
  24. package/src/eventsub/events/channel.charity_campaign.stop-1.ts +76 -0
  25. package/src/eventsub/events/channel.chat.clear-1.ts +41 -0
  26. package/src/eventsub/events/channel.chat.clear_user_messages-1.ts +47 -0
  27. package/src/eventsub/events/channel.chat.message-1.ts +160 -0
  28. package/src/eventsub/events/channel.chat.message_delete-1.ts +49 -0
  29. package/src/eventsub/events/channel.chat.notification-1.ts +317 -0
  30. package/src/eventsub/events/channel.chat.user_message_hold-1.ts +75 -0
  31. package/src/eventsub/events/channel.chat.user_message_update-1.ts +82 -0
  32. package/src/eventsub/events/channel.chat_settings.update-1.ts +83 -0
  33. package/src/eventsub/events/channel.cheer-1.ts +50 -0
  34. package/src/eventsub/events/channel.follow-2.ts +49 -0
  35. package/src/eventsub/events/channel.goal.begin-1.ts +80 -0
  36. package/src/eventsub/events/channel.goal.end-1.ts +80 -0
  37. package/src/eventsub/events/channel.goal.progress-1.ts +80 -0
  38. package/src/eventsub/events/channel.guest_star_guest.update-beta.ts +85 -0
  39. package/src/eventsub/events/channel.guest_star_session.begin-beta.ts +50 -0
  40. package/src/eventsub/events/channel.guest_star_session.end-beta.ts +58 -0
  41. package/src/eventsub/events/channel.guest_star_settings.update-beta.ts +62 -0
  42. package/src/eventsub/events/channel.hype_train.begin-2.ts +90 -0
  43. package/src/eventsub/events/channel.hype_train.end-2.ts +70 -0
  44. package/src/eventsub/events/channel.hype_train.progress-2.ts +90 -0
  45. package/src/eventsub/events/channel.moderate-2.ts +258 -0
  46. package/src/eventsub/events/channel.moderator.add-1.ts +44 -0
  47. package/src/eventsub/events/channel.moderator.remove-1.ts +44 -0
  48. package/src/eventsub/events/channel.poll.begin-1.ts +73 -0
  49. package/src/eventsub/events/channel.poll.end-1.ts +75 -0
  50. package/src/eventsub/events/channel.poll.progress-1.ts +73 -0
  51. package/src/eventsub/events/channel.prediction.begin-1.ts +72 -0
  52. package/src/eventsub/events/channel.prediction.end-1.ts +76 -0
  53. package/src/eventsub/events/channel.prediction.lock-1.ts +72 -0
  54. package/src/eventsub/events/channel.prediction.progress-1.ts +72 -0
  55. package/src/eventsub/events/channel.raid-1.ts +48 -0
  56. package/src/eventsub/events/channel.shared_chat.begin-1.ts +55 -0
  57. package/src/eventsub/events/channel.shared_chat.end-1.ts +46 -0
  58. package/src/eventsub/events/channel.shared_chat.update-1.ts +55 -0
  59. package/src/eventsub/events/channel.shield_mode.begin-1.ts +51 -0
  60. package/src/eventsub/events/channel.shield_mode.end-1.ts +51 -0
  61. package/src/eventsub/events/channel.shoutout.create-1.ts +61 -0
  62. package/src/eventsub/events/channel.shoutout.receive-1.ts +51 -0
  63. package/src/eventsub/events/channel.subscribe-1.ts +48 -0
  64. package/src/eventsub/events/channel.subscription.end-1.ts +48 -0
  65. package/src/eventsub/events/channel.subscription.gift-1.ts +52 -0
  66. package/src/eventsub/events/channel.subscription.message-1.ts +66 -0
  67. package/src/eventsub/events/channel.suspicious_user.message-1.ts +85 -0
  68. package/src/eventsub/events/channel.suspicious_user.update-1.ts +55 -0
  69. package/src/eventsub/events/channel.unban-1.ts +50 -0
  70. package/src/eventsub/events/channel.unban_request.create-1.ts +53 -0
  71. package/src/eventsub/events/channel.unban_request.resolve-1.ts +64 -0
  72. package/src/eventsub/events/channel.update-2.ts +48 -0
  73. package/src/eventsub/events/channel.vip.add-1.ts +44 -0
  74. package/src/eventsub/events/channel.vip.remove-1.ts +44 -0
  75. package/src/eventsub/events/channel.warning.acknowledge-1.ts +47 -0
  76. package/src/eventsub/events/channel.warning.send-1.ts +57 -0
  77. package/src/eventsub/events/index.ts +73 -284
  78. package/src/eventsub/events/stream.offline-1.ts +38 -0
  79. package/src/eventsub/events/stream.online-1.ts +44 -0
  80. package/src/eventsub/events/user.update-1.ts +48 -0
  81. package/src/eventsub/events/user.whisper.message-1.ts +51 -0
  82. package/src/eventsub/events-helpers.ts +52 -24
  83. package/src/eventsub/eventsub.ts +37 -74
  84. package/src/eventsub/index.ts +8 -6
  85. package/src/eventsub/messages.ts +16 -4
  86. package/src/helix/channel-points/custom-rewards.ts +120 -33
  87. package/src/helix/channel-points/index.ts +1 -1
  88. package/src/helix/channels/channels.ts +39 -0
  89. package/src/helix/channels/index.ts +1 -0
  90. package/src/helix/chat/emotes.ts +49 -0
  91. package/src/helix/chat/index.ts +3 -0
  92. package/src/helix/chat/send.ts +109 -0
  93. package/src/helix/chat/shared.ts +49 -0
  94. package/src/helix/helix.ts +6 -21
  95. package/src/helix/subscriptions/index.ts +1 -1
  96. package/src/helix/subscriptions/subscriptions.ts +46 -48
  97. package/src/helix/users/index.ts +1 -1
  98. package/src/helix/users/users.ts +22 -19
  99. package/src/helpers/alerts/alerts.ts +5 -5
  100. package/src/helpers/alerts/index.ts +2 -2
  101. package/src/helpers/charity/charity.ts +2 -2
  102. package/src/helpers/charity/index.ts +1 -1
  103. package/src/helpers/goal/goal.ts +2 -2
  104. package/src/helpers/goal/index.ts +1 -1
  105. package/src/helpers/hype-train/hype-train.ts +2 -2
  106. package/src/helpers/hype-train/index.ts +1 -1
  107. package/src/helpers/poll/index.ts +1 -1
  108. package/src/helpers/poll/poll.ts +3 -3
  109. package/src/helpers/prediction/index.ts +1 -1
  110. package/src/helpers/prediction/prediction.ts +3 -3
  111. package/src/helpers/redemption/index.ts +1 -1
  112. package/src/helpers/redemption/redemption.ts +2 -2
  113. package/src/helpers/status/index.ts +1 -1
  114. package/src/helpers/status/status.ts +2 -2
  115. package/src/ui/authentication.ts +1 -1
  116. package/src/ui/popup.ts +26 -3
  117. package/src/chat/interfaces/events.ts +0 -269
  118. package/src/chat/interfaces/index.ts +0 -9
  119. package/src/chat/parser.ts +0 -254
  120. package/src/eventsub/events/channel.ad_break.begin.ts +0 -51
  121. package/src/eventsub/events/channel.ban.ts +0 -59
  122. package/src/eventsub/events/channel.channel_points_custom_reward._.ts +0 -29
  123. package/src/eventsub/events/channel.channel_points_custom_reward.add.ts +0 -75
  124. package/src/eventsub/events/channel.channel_points_custom_reward.remove.ts +0 -77
  125. package/src/eventsub/events/channel.channel_points_custom_reward.update.ts +0 -77
  126. package/src/eventsub/events/channel.channel_points_custom_reward_redemption._.ts +0 -10
  127. package/src/eventsub/events/channel.channel_points_custom_reward_redemption.add.ts +0 -59
  128. package/src/eventsub/events/channel.channel_points_custom_reward_redemption.update.ts +0 -59
  129. package/src/eventsub/events/channel.charity_campaign.donate.ts +0 -66
  130. package/src/eventsub/events/channel.charity_campaign.progress.ts +0 -67
  131. package/src/eventsub/events/channel.charity_campaign.start.ts +0 -69
  132. package/src/eventsub/events/channel.charity_campaign.stop.ts +0 -69
  133. package/src/eventsub/events/channel.chat.clear.ts +0 -42
  134. package/src/eventsub/events/channel.chat.clear_user_messages.ts +0 -48
  135. package/src/eventsub/events/channel.chat.message_delete.ts +0 -50
  136. package/src/eventsub/events/channel.chat.notification.ts +0 -50
  137. package/src/eventsub/events/channel.cheer.ts +0 -51
  138. package/src/eventsub/events/channel.follow.ts +0 -50
  139. package/src/eventsub/events/channel.goal.begin.ts +0 -51
  140. package/src/eventsub/events/channel.goal.end.ts +0 -55
  141. package/src/eventsub/events/channel.goal.progress.ts +0 -51
  142. package/src/eventsub/events/channel.guest_star_guest.update.ts +0 -66
  143. package/src/eventsub/events/channel.guest_star_session.begin.ts +0 -46
  144. package/src/eventsub/events/channel.guest_star_session.end.ts +0 -48
  145. package/src/eventsub/events/channel.guest_star_settings.update.ts +0 -50
  146. package/src/eventsub/events/channel.hype_train._.ts +0 -12
  147. package/src/eventsub/events/channel.hype_train.begin.ts +0 -57
  148. package/src/eventsub/events/channel.hype_train.end.ts +0 -55
  149. package/src/eventsub/events/channel.hype_train.progress.ts +0 -70
  150. package/src/eventsub/events/channel.moderator.add.ts +0 -45
  151. package/src/eventsub/events/channel.moderator.remove.ts +0 -45
  152. package/src/eventsub/events/channel.poll._.ts +0 -26
  153. package/src/eventsub/events/channel.poll.begin.ts +0 -55
  154. package/src/eventsub/events/channel.poll.end.ts +0 -57
  155. package/src/eventsub/events/channel.poll.progress.ts +0 -55
  156. package/src/eventsub/events/channel.prediction._.ts +0 -25
  157. package/src/eventsub/events/channel.prediction.begin.ts +0 -51
  158. package/src/eventsub/events/channel.prediction.end.ts +0 -55
  159. package/src/eventsub/events/channel.prediction.lock.ts +0 -51
  160. package/src/eventsub/events/channel.prediction.progress.ts +0 -51
  161. package/src/eventsub/events/channel.raid.ts +0 -49
  162. package/src/eventsub/events/channel.shield_mode.begin.ts +0 -50
  163. package/src/eventsub/events/channel.shield_mode.end.ts +0 -50
  164. package/src/eventsub/events/channel.shoutout.create.ts +0 -62
  165. package/src/eventsub/events/channel.shoutout.receive.ts +0 -52
  166. package/src/eventsub/events/channel.subscribe.ts +0 -49
  167. package/src/eventsub/events/channel.subscription.end.ts +0 -49
  168. package/src/eventsub/events/channel.subscription.gift.ts +0 -53
  169. package/src/eventsub/events/channel.subscription.message.ts +0 -67
  170. package/src/eventsub/events/channel.unban.ts +0 -51
  171. package/src/eventsub/events/channel.update.ts +0 -49
  172. package/src/eventsub/events/stream.offline.ts +0 -39
  173. package/src/eventsub/events/stream.online.ts +0 -45
  174. package/src/eventsub/events/user.update.ts +0 -45
@@ -1 +1 @@
1
- export * from "./subscriptions.js"
1
+ export * from "./subscriptions.ts"
@@ -1,11 +1,7 @@
1
- import { type Authentication } from "../../authentication/index.js"
2
- import {
3
- type TwitchSubscription,
4
- type TwitchSubscriptionType,
5
- buildSubscription,
6
- } from "../../eventsub/events/index.js"
7
- import { type BaseSubscription } from "../../eventsub/events-helpers.js"
8
- import { helix } from "../helix.js"
1
+ import { type Authentication } from "../../authentication/index.ts"
2
+ import { type EventConfigs, type EventType } from "../../eventsub/index.ts"
3
+
4
+ import { helix } from "../helix.ts"
9
5
 
10
6
  interface SubscriptionWebhookTransport {
11
7
  method: "webhook"
@@ -22,15 +18,15 @@ type SubscriptionTransport =
22
18
  | SubscriptionWebhookTransport
23
19
  | SubscriptionWebsocketTransport
24
20
 
25
- export interface SubscriptionRequest<Subscription extends BaseSubscription> {
26
- type: Subscription["type"]
27
- version: Subscription["version"]
28
- condition: Subscription["condition"]
21
+ interface SubscriptionRequest<Type extends EventType> {
22
+ type: EventConfigs[Type]["Type"]
23
+ version: EventConfigs[Type]["Version"]
24
+ condition: EventConfigs[Type]["Condition"]
29
25
  transport: SubscriptionTransport
30
26
  }
31
27
 
32
- export type ActiveSubscription<Subscription extends BaseSubscription> =
33
- Subscription & {
28
+ type ActiveSubscription<Type extends EventType> =
29
+ EventConfigs[Type]["Subscription"] & {
34
30
  id: string
35
31
  status:
36
32
  | "enabled"
@@ -53,60 +49,62 @@ export type ActiveSubscription<Subscription extends BaseSubscription> =
53
49
  transport: SubscriptionTransport
54
50
  }
55
51
 
56
- export async function createSubscription<
57
- Type extends TwitchSubscriptionType,
58
- Subscription extends TwitchSubscription<Type>,
59
- >(
60
- sessionId: string,
61
- authentication: Authentication,
62
- type: Type,
63
- ): Promise<ActiveSubscription<Subscription>> {
64
- const subscription = buildSubscription(type, authentication.user.id)
52
+ type ActiveSubscriptionResponse<Type extends EventType> = {
53
+ data: Array<ActiveSubscription<Type>>
54
+ }
65
55
 
66
- const [activeSubscription] = await helix(authentication, {
67
- method: "post",
56
+ export async function createSubscription<Type extends EventType>(
57
+ authentication: Authentication,
58
+ transport: SubscriptionTransport,
59
+ subscription: EventConfigs[Type]["Subscription"],
60
+ ): Promise<ActiveSubscription<Type>> {
61
+ const {
62
+ data: [activeSubscription],
63
+ } = await helix<
64
+ ActiveSubscriptionResponse<EventType>,
65
+ never,
66
+ SubscriptionRequest<EventType>
67
+ >(authentication, {
68
+ method: "POST",
68
69
  path: "/eventsub/subscriptions",
69
70
  body: {
70
71
  ...subscription,
71
- transport: {
72
- method: "websocket" as const,
73
- session_id: sessionId,
74
- },
72
+ transport,
75
73
  },
76
74
  })
77
75
 
78
76
  return activeSubscription
79
77
  }
80
78
 
81
- export async function deleteSubscription(
82
- authentication: Authentication,
83
- id: string,
84
- ): Promise<void> {
85
- await helix<never, never, { id: string }>(authentication, {
86
- method: "delete",
87
- path: "/eventsub/subscriptions",
88
- params: {
89
- id,
90
- },
91
- })
92
- }
93
-
94
79
  export async function getSubscriptions(
95
80
  authentication: Authentication,
96
- ): Promise<Array<ActiveSubscription<TwitchSubscription>>> {
97
- const subscriptions = await helix<
98
- ActiveSubscription<TwitchSubscription>,
81
+ ): Promise<Array<ActiveSubscription<EventType>>> {
82
+ const { data: subscriptions } = await helix<
83
+ ActiveSubscriptionResponse<EventType>,
99
84
  never,
100
85
  {
101
- status?: ActiveSubscription<TwitchSubscription>["status"]
102
- type?: TwitchSubscriptionType
86
+ status?: ActiveSubscription<EventType>["status"]
87
+ type?: EventType
103
88
  user_id?: string
104
89
  after?: string
105
90
  }
106
91
  >(authentication, {
107
- method: "get",
92
+ method: "GET",
108
93
  path: "/eventsub/subscriptions",
109
94
  })
110
95
 
111
96
  return subscriptions
112
97
  }
98
+
99
+ export async function deleteSubscription(
100
+ authentication: Authentication,
101
+ id: string,
102
+ ): Promise<void> {
103
+ await helix<never, { id: string }>(authentication, {
104
+ method: "DELETE",
105
+ path: "/eventsub/subscriptions",
106
+ params: {
107
+ id,
108
+ },
109
+ })
110
+ }
@@ -1 +1 @@
1
- export * from "./users.js"
1
+ export * from "./users.ts"
@@ -1,5 +1,5 @@
1
- import { type Authentication } from "../../authentication/index.js"
2
- import { helix } from "../helix.js"
1
+ import { type Authentication } from "../../authentication/index.ts"
2
+ import { helix } from "../helix.ts"
3
3
 
4
4
  export interface TwitchUser {
5
5
  id: string
@@ -13,8 +13,12 @@ export interface TwitchUser {
13
13
  created_at: Date
14
14
  }
15
15
 
16
- type RawUser = Omit<TwitchUser, "created_at"> & {
17
- created_at: string
16
+ interface UsersResponse {
17
+ data: Array<
18
+ Omit<TwitchUser, "created_at"> & {
19
+ created_at: string
20
+ }
21
+ >
18
22
  }
19
23
 
20
24
  export async function getUsers(
@@ -22,21 +26,20 @@ export async function getUsers(
22
26
  id?: string | string[],
23
27
  login?: string | string[],
24
28
  ): Promise<TwitchUser[]> {
25
- const data = await helix<TwitchUser, RawUser>(
26
- authentication,
27
- {
28
- method: "get",
29
- path: "/users",
30
- params: {
31
- id,
32
- login,
33
- },
29
+ const { data: users } = await helix<
30
+ UsersResponse,
31
+ { id?: string | string[]; login?: string | string[] }
32
+ >(authentication, {
33
+ method: "GET",
34
+ path: "/users",
35
+ params: {
36
+ id,
37
+ login,
34
38
  },
35
- ({ created_at, ...data }) => ({
36
- ...data,
37
- created_at: new Date(created_at),
38
- }),
39
- )
39
+ })
40
40
 
41
- return data
41
+ return users.map(({ created_at, ...user }) => ({
42
+ ...user,
43
+ created_at: new Date(created_at),
44
+ }))
42
45
  }
@@ -1,16 +1,16 @@
1
1
  import createQueue, { type Queue } from "@overlaysymphony/core/libs/queue"
2
2
 
3
- import { type TwitchNotificationMessage } from "../../eventsub/events/index.js"
4
- import { type TwitchEventSub } from "../../eventsub/index.js"
3
+ import { type EventPayload } from "../../eventsub/events-helpers.ts"
4
+ import { type TwitchEventSub } from "../../eventsub/index.ts"
5
5
 
6
- export type Alert = TwitchNotificationMessage<
6
+ export type Alert = EventPayload<
7
7
  | "channel.cheer"
8
8
  | "channel.follow"
9
9
  | "channel.raid"
10
10
  | "channel.subscribe"
11
11
  | "channel.subscription.gift"
12
12
  | "channel.subscription.message"
13
- >["payload"]
13
+ >
14
14
 
15
15
  export const mapTypeToPriority = {
16
16
  "channel.follow": 0,
@@ -25,7 +25,7 @@ export function onAlert(
25
25
  eventsub: TwitchEventSub,
26
26
  handleAlert: (alert: Alert) => void,
27
27
  ): void {
28
- eventsub.subscribe(
28
+ eventsub.on(
29
29
  [
30
30
  "channel.cheer",
31
31
  "channel.follow",
@@ -1,2 +1,2 @@
1
- export { default } from "./alerts.js"
2
- export * from "./alerts.js"
1
+ export { default } from "./alerts.ts"
2
+ export * from "./alerts.ts"
@@ -1,4 +1,4 @@
1
- import { type TwitchEventSub } from "../../eventsub/index.js"
1
+ import { type TwitchEventSub } from "../../eventsub/index.ts"
2
2
 
3
3
  export interface Charity {
4
4
  name: string
@@ -42,7 +42,7 @@ export function onCharity(
42
42
  targetAmount: 0,
43
43
  }
44
44
 
45
- eventsub.subscribe(
45
+ eventsub.on(
46
46
  [
47
47
  "channel.charity_campaign.start",
48
48
  "channel.charity_campaign.progress",
@@ -1 +1 @@
1
- export * from "./charity.js"
1
+ export * from "./charity.ts"
@@ -1,4 +1,4 @@
1
- import { type TwitchEventSub } from "../../eventsub/index.js"
1
+ import { type TwitchEventSub } from "../../eventsub/index.ts"
2
2
 
3
3
  export interface Goal {
4
4
  type: string
@@ -24,7 +24,7 @@ export function onGoal(
24
24
  targetAmount: 0,
25
25
  }
26
26
 
27
- eventsub.subscribe(
27
+ eventsub.on(
28
28
  ["channel.goal.begin", "channel.goal.progress", "channel.goal.end"],
29
29
  (payload) => {
30
30
  goal.type = payload.event.type
@@ -1 +1 @@
1
- export * from "./goal.js"
1
+ export * from "./goal.ts"
@@ -1,4 +1,4 @@
1
- import { type TwitchEventSub } from "../../eventsub/index.js"
1
+ import { type TwitchEventSub } from "../../eventsub/index.ts"
2
2
 
3
3
  export interface HypeTrain {
4
4
  level: number
@@ -27,7 +27,7 @@ export function onHypeTrain(
27
27
  goal: 0,
28
28
  }
29
29
 
30
- eventsub.subscribe(
30
+ eventsub.on(
31
31
  [
32
32
  "channel.hype_train.begin",
33
33
  "channel.hype_train.progress",
@@ -1 +1 @@
1
- export * from "./hype-train.js"
1
+ export * from "./hype-train.ts"
@@ -1 +1 @@
1
- export * from "./poll.js"
1
+ export * from "./poll.ts"
@@ -1,4 +1,4 @@
1
- import { type TwitchEventSub } from "../../eventsub/index.js"
1
+ import { type TwitchEventSub } from "../../eventsub/index.ts"
2
2
 
3
3
  export interface Poll {
4
4
  id: string
@@ -31,7 +31,7 @@ export function onPoll(
31
31
  endsAt: undefined,
32
32
  }
33
33
 
34
- eventsub.subscribe(
34
+ eventsub.on(
35
35
  ["channel.poll.begin", "channel.poll.progress", "channel.poll.end"],
36
36
  (payload) => {
37
37
  // Twitch sometimes sends duplicate end events.
@@ -66,7 +66,7 @@ export function onPoll(
66
66
  payload.type === "channel.poll.begin" ||
67
67
  payload.type === "channel.poll.progress"
68
68
  ) {
69
- poll.endsAt = payload.event.ends_at
69
+ poll.endsAt = new Date(payload.event.ends_at)
70
70
  } else {
71
71
  poll.endsAt = undefined
72
72
  }
@@ -1 +1 @@
1
- export * from "./prediction.js"
1
+ export * from "./prediction.ts"
@@ -1,4 +1,4 @@
1
- import { type TwitchEventSub } from "../../eventsub/index.js"
1
+ import { type TwitchEventSub } from "../../eventsub/index.ts"
2
2
 
3
3
  export interface Prediction {
4
4
  title: string
@@ -32,7 +32,7 @@ export function onPrediction(
32
32
  locksAt: new Date(""),
33
33
  }
34
34
 
35
- eventsub.subscribe(
35
+ eventsub.on(
36
36
  [
37
37
  "channel.prediction.begin",
38
38
  "channel.prediction.progress",
@@ -55,7 +55,7 @@ export function onPrediction(
55
55
  payload.type === "channel.prediction.begin" ||
56
56
  payload.type === "channel.prediction.progress"
57
57
  ) {
58
- prediction.locksAt = payload.event.locks_at
58
+ prediction.locksAt = new Date(payload.event.locks_at)
59
59
  } else {
60
60
  prediction.locksAt = undefined
61
61
  }
@@ -1 +1 @@
1
- export * from "./redemption.js"
1
+ export * from "./redemption.ts"
@@ -1,4 +1,4 @@
1
- import { type TwitchEventSub } from "../../eventsub/index.js"
1
+ import { type TwitchEventSub } from "../../eventsub/index.ts"
2
2
 
3
3
  export interface Redemption {
4
4
  id: string
@@ -38,7 +38,7 @@ export function onRedemption(
38
38
  ? config[1]
39
39
  : undefined
40
40
 
41
- eventsub.subscribe(
41
+ eventsub.on(
42
42
  ["channel.channel_points_custom_reward_redemption.add"],
43
43
  (payload) => {
44
44
  if (typeof id === "undefined" || payload.event.reward.id === id) {
@@ -1 +1 @@
1
- export * from "./status.js"
1
+ export * from "./status.ts"
@@ -1,4 +1,4 @@
1
- import { type TwitchEventSub } from "../../eventsub/index.js"
1
+ import { type TwitchEventSub } from "../../eventsub/index.ts"
2
2
 
3
3
  export interface Status {
4
4
  online: boolean
@@ -22,7 +22,7 @@ export function onStatus(
22
22
  labels: [],
23
23
  }
24
24
 
25
- eventsub.subscribe(
25
+ eventsub.on(
26
26
  [
27
27
  "channel.update",
28
28
  "stream.online",
@@ -2,7 +2,7 @@ import {
2
2
  clearCachedAuthentication,
3
3
  getAuthentication,
4
4
  popupAuthentication,
5
- } from "../authentication/index.js"
5
+ } from "../authentication/index.ts"
6
6
 
7
7
  declare global {
8
8
  interface Window {
package/src/ui/popup.ts CHANGED
@@ -3,11 +3,27 @@ import querystring from "@overlaysymphony/core/libs/querystring"
3
3
  import {
4
4
  type BareAuthentication,
5
5
  validateAuthentication,
6
- } from "../authentication/index.js"
6
+ } from "../authentication/index.ts"
7
+
8
+ const status = document.getElementById("status")
9
+ const statuses = {
10
+ error: "Something went wrong.",
11
+ initializing: "Initializing Twitch authentication.",
12
+ validating: "Validating Twitch authenticate.",
13
+ ready: "Twitch authentication validated. You may close this window.",
14
+ }
15
+ function updateStatus(key: keyof typeof statuses, message?: string) {
16
+ if (!status) return
17
+
18
+ status.innerText = statuses[key] + (message ? ` ${message}` : "")
19
+ }
7
20
 
8
21
  const state = getState()
9
22
 
10
23
  if (state.step === "initial") {
24
+ updateStatus("initializing")
25
+ setTimeout(() => updateStatus("error"), 500)
26
+
11
27
  initiateAuthentication(
12
28
  state.clientId,
13
29
  `${window.location.origin}${window.location.pathname}`,
@@ -16,14 +32,21 @@ if (state.step === "initial") {
16
32
  }
17
33
 
18
34
  if (state.step === "token") {
35
+ updateStatus("validating")
36
+
19
37
  const authentication = await authenticateResult(state.clientId, state)
20
38
  const opener = window.opener as Window | undefined
21
39
  opener?.postMessage({ type: "authentication", authentication }, "*")
40
+
41
+ updateStatus("ready")
22
42
  window.close()
23
43
  }
24
44
 
25
45
  if (state.step === "error") {
26
- alert(`${state.error}. ${state.description ?? ""}`)
46
+ updateStatus(
47
+ "error",
48
+ `${state.error}${state.description ? `: ${state.description}` : "."}`,
49
+ )
27
50
  }
28
51
 
29
52
  function getState():
@@ -62,7 +85,7 @@ function getState():
62
85
  !scope ? "Missing scope." : "",
63
86
  !clientId ? "Missing state." : "",
64
87
  ]
65
- .filter(Boolean)
88
+ .filter((value) => !!value)
66
89
  .join(" "),
67
90
  }
68
91
  }