@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,269 +0,0 @@
1
- export interface ChatEventSource {
2
- host: string
3
- user?: string
4
- }
5
-
6
- type AllOrNothing<T> = T | Partial<Record<keyof T, undefined>>
7
-
8
- type TagUserType = "staff" | "global_mod" | "admin" | undefined
9
- type TagBadges = Record<string, number>
10
- type TagBadgeInfo = Record<string, number>
11
- type TagEmotes = Record<
12
- string,
13
- Array<[startPosition: string, endPosition: string]>
14
- >
15
-
16
- export interface PingEvent {
17
- type: "PING"
18
- message: string
19
- source?: ChatEventSource
20
- }
21
-
22
- export interface WelcomeEvent {
23
- type: "001" // Logged in (successfully authenticated)
24
- channel: string
25
- message: string
26
- source?: ChatEventSource
27
- }
28
-
29
- export interface CapabilitiesEvent {
30
- type: "CAP"
31
- enabled: boolean
32
- nickname: string
33
- capabilities: string[]
34
- source?: ChatEventSource
35
- }
36
-
37
- export interface JoinEvent {
38
- type: "JOIN"
39
- channel: string
40
- source?: ChatEventSource
41
- }
42
-
43
- export interface PartEvent {
44
- type: "PART"
45
- channel: string
46
- source?: ChatEventSource
47
- }
48
-
49
- export interface GlobalUserStateEvent {
50
- type: "GLOBALUSERSTATE"
51
- tags?: {
52
- userId: string
53
- userType: TagUserType
54
- displayName?: string
55
- color?: string
56
- badges?: TagBadges
57
- badgeInfo?: TagBadgeInfo
58
- emoteSets?: string[]
59
- }
60
- source?: ChatEventSource
61
- }
62
-
63
- export interface ReconnectEvent {
64
- type: "RECONNECT"
65
- source?: ChatEventSource
66
- }
67
-
68
- export interface ClearChatEvent {
69
- type: "CLEARCHAT"
70
- channel: string
71
- tags?: {
72
- roomId: string
73
- targetUserId: string
74
- banDuration: number
75
- }
76
- source?: ChatEventSource
77
- }
78
-
79
- export interface HostTargetEvent {
80
- type: "HOSTTARGET"
81
- channel: string
82
- source?: ChatEventSource
83
- }
84
-
85
- export interface NoticeEvent {
86
- type: "NOTICE"
87
- channel: string
88
- tags?: {
89
- msgId: string
90
- targetUserId: string
91
- }
92
- source?: ChatEventSource
93
- }
94
-
95
- export interface RoomStateEvent {
96
- type: "ROOMSTATE"
97
- channel: string
98
- tags?: {
99
- roomId: string
100
- slow: number
101
- emoteOnly: boolean
102
- followersOnly: boolean
103
- subsOnly: boolean
104
- }
105
- source?: ChatEventSource
106
- }
107
-
108
- export interface UserStateEvent {
109
- type: "USERSTATE"
110
- channel: string
111
- tags?: {
112
- id: string
113
- userId: string
114
- userType: TagUserType
115
- displayName?: string
116
- color?: string
117
- badges?: TagBadges
118
- badgeInfo?: TagBadgeInfo
119
- emoteSets?: string[]
120
-
121
- mod: boolean
122
- subscriber: boolean
123
- vip: boolean
124
- turbo: boolean
125
- }
126
- source?: ChatEventSource
127
- }
128
-
129
- export interface ClearMessageEvent {
130
- type: "CLEARMSG"
131
- channel: string
132
- tags?: {
133
- login: string
134
- roomId: string
135
- targetMsgId?: string
136
- }
137
- source?: ChatEventSource
138
- }
139
-
140
- export interface UserNoticeEvent {
141
- type: "USERNOTICE"
142
- channel: string
143
- tags?: {
144
- id: string
145
- userId: string
146
- userType: TagUserType
147
- displayName?: string
148
- login: string
149
- color?: string
150
- badges?: TagBadges
151
- badgeInfo?: TagBadgeInfo
152
- emotes?: TagEmotes
153
- roomId: string
154
- systemMsg: string
155
- msgId:
156
- | "sub"
157
- | "resub"
158
- | "subgift"
159
- | "submysterygift"
160
- | "giftpaidupgrade"
161
- | "rewardgift"
162
- | "anongiftpaidupgrade"
163
- | "raid"
164
- | "unraid"
165
- | "ritual"
166
- | "bitsbadgetier"
167
-
168
- mod: boolean
169
- subscriber: boolean
170
- vip: boolean
171
- turbo: boolean
172
- }
173
- source?: ChatEventSource
174
- }
175
-
176
- export interface ChatMessageEvent {
177
- type: "PRIVMSG"
178
- channel: string
179
- message: string
180
- tags?: {
181
- id: string
182
- userId: string
183
- userType: TagUserType
184
- displayName?: string
185
- color?: string
186
- badges?: TagBadges
187
- badgeInfo?: TagBadgeInfo
188
- emotes?: TagEmotes
189
- roomId: string
190
-
191
- firstMsg: boolean
192
- mod: boolean
193
- subscriber: boolean
194
- vip: boolean
195
- turbo: boolean
196
- } & AllOrNothing<{
197
- replyThreadParentMsgId: string
198
- replyThreadParentUserLogin: string
199
- replyParentMsgId: string
200
- replyParentUserId: string
201
- replyParentUserLogin: string
202
- replyParentDisplayName: string
203
- replyParentMsgBody: string
204
- }> &
205
- AllOrNothing<{
206
- pinnedChatPaidIsSystemMessage: boolean
207
- pinnedChatPaidLevel: string
208
- pinnedChatPaidAmount: number
209
- pinnedChatPaidExponent: number
210
- pinnedChatPaidCurrency: string
211
- }>
212
- source?: ChatEventSource
213
- }
214
-
215
- export interface WhisperMessageEvent {
216
- type: "WHISPER"
217
- channel: string
218
- message: string
219
- tags?: {
220
- messageId: string
221
- threadId: string
222
- userId: string
223
- userType: TagUserType
224
- displayName?: string
225
- color?: string
226
- badges?: TagBadges
227
- emotes?: TagEmotes
228
- turbo: boolean
229
- }
230
- source?: ChatEventSource
231
- }
232
-
233
- export interface ChatCommandEvent {
234
- type: "PRIVMSG-COMMAND"
235
- channel: string
236
- command: string
237
- parameters?: string
238
- tags?: ChatMessageEvent["tags"]
239
- source?: ChatEventSource
240
- }
241
-
242
- export interface WhisperCommandEvent {
243
- type: "WHISPER-COMMAND"
244
- channel: string
245
- command: string
246
- parameters?: string
247
- tags?: WhisperMessageEvent["tags"]
248
- source?: ChatEventSource
249
- }
250
-
251
- export type ChatEvent =
252
- | PingEvent
253
- | WelcomeEvent
254
- | CapabilitiesEvent
255
- | JoinEvent
256
- | PartEvent
257
- | GlobalUserStateEvent
258
- | ReconnectEvent
259
- | ClearChatEvent
260
- | HostTargetEvent
261
- | NoticeEvent
262
- | RoomStateEvent
263
- | UserStateEvent
264
- | ClearMessageEvent
265
- | UserNoticeEvent
266
- | ChatMessageEvent
267
- | WhisperMessageEvent
268
- | ChatCommandEvent
269
- | WhisperCommandEvent
@@ -1,9 +0,0 @@
1
- import { type ChatEvent } from "./events.js"
2
-
3
- export type { ChatEvent, ChatEventSource } from "./events.js"
4
-
5
- export type TwitchChatEventType = ChatEvent["type"]
6
-
7
- export type TwitchChatEvent<
8
- Type extends TwitchChatEventType = TwitchChatEventType,
9
- > = Extract<ChatEvent, { type: Type }>
@@ -1,254 +0,0 @@
1
- import { type ChatEvent, type ChatEventSource } from "./interfaces/index.js"
2
-
3
- // Parses an IRC message and returns a JSON object with the message's
4
- // component parts (tags, source (nick and host), command, parameters).
5
- // from https://dev.twitch.tv/docs/irc/example-parser/
6
-
7
- export default function parseEvent(input: string): ChatEvent | undefined {
8
- let tags: Record<string, unknown> | undefined = undefined
9
- let source: ChatEventSource | undefined = undefined
10
-
11
- let idx = 0
12
-
13
- // tags
14
- if (input[idx] === "@") {
15
- const endIdx = input.indexOf(" ", idx)
16
- tags = parseTags(input.slice(idx + 1, endIdx))
17
- idx = endIdx + 1
18
- }
19
-
20
- // source
21
- if (input[idx] === ":") {
22
- const endIdx = input.indexOf(" ", idx)
23
- source = parseSource(input.slice(idx + 1, endIdx))
24
- idx = endIdx + 1
25
-
26
- if (source.user && tags?.["display-name"]) {
27
- source.user = tags["display-name"] as string
28
- }
29
- }
30
-
31
- // core
32
- try {
33
- const hasParameters = input.includes(":", idx)
34
- if (hasParameters) {
35
- const endIdx = input.indexOf(":", idx)
36
-
37
- const message = parseCore(
38
- input.slice(idx, endIdx - 1),
39
- input.slice(endIdx + 1),
40
- )
41
-
42
- return {
43
- ...message,
44
- source,
45
- // @ts-expect-error: generic objects are complicated
46
- tags,
47
- }
48
- } else {
49
- const message = parseCore(input.slice(idx, input.length), "")
50
-
51
- return {
52
- ...message,
53
- source,
54
- // @ts-expect-error: generic objects are complicated
55
- tags,
56
- }
57
- }
58
- } catch (error) {
59
- return undefined
60
- }
61
- }
62
-
63
- function parseSource(input: string): ChatEventSource {
64
- const parts = input.split("!")
65
-
66
- if (parts.length === 1) {
67
- return {
68
- host: parts[0],
69
- }
70
- }
71
-
72
- return {
73
- host: parts[1],
74
- user: parts[0],
75
- }
76
- }
77
-
78
- function parseTags(input: string): Record<string, unknown> {
79
- const tags: Record<string, unknown> = {}
80
-
81
- const parsedTags = input.split(";")
82
- for (const tag of parsedTags) {
83
- const [dashKey, value] = tag.split("=")
84
- const key = toCamelCase(dashKey)
85
-
86
- if (!value) {
87
- tags[key] = undefined
88
- continue
89
- }
90
-
91
- if (key === "badges" || key === "badgeInfo") {
92
- const dict: Record<string, number> = {}
93
-
94
- const badges = value.split(",")
95
- for (const badge of badges) {
96
- const parts = badge.split("/")
97
- dict[parts[0]] = parseInt(parts[1])
98
- }
99
-
100
- tags[key] = dict
101
- continue
102
- }
103
-
104
- if (key === "emotes") {
105
- const dict: Record<string, Array<[string, string]>> = {}
106
-
107
- const emotes = value.split("/")
108
- for (const emote of emotes) {
109
- const [id, rawPositions] = emote.split(":")
110
- dict[id] = []
111
-
112
- const positions = rawPositions.split(",")
113
- for (const position of positions) {
114
- const positionParts = position.split("-")
115
- dict[id].push([positionParts[0], positionParts[1]])
116
- }
117
- }
118
-
119
- tags[key] = dict
120
- continue
121
- }
122
-
123
- if (key === "emoteSets") {
124
- tags[key] = value.split(",")
125
- continue
126
- }
127
-
128
- if (
129
- key === "banDuration" ||
130
- key === "pinnedChatPaidAmount" ||
131
- key === "pinnedChatPaidExponent" ||
132
- key === "slow"
133
- ) {
134
- tags[key] = parseInt(value)
135
- continue
136
- }
137
-
138
- if (
139
- key === "firstMsg" ||
140
- key === "mod" ||
141
- key === "vip" ||
142
- key === "subscriber" ||
143
- key === "turbo" ||
144
- key === "emoteOnly" ||
145
- key === "followersOnly" ||
146
- key === "subsOnly" ||
147
- key === "pinnedChatPaidIsSystemMessage"
148
- ) {
149
- tags[key] = !!parseInt(value)
150
- continue
151
- }
152
-
153
- tags[key] = value
154
- }
155
-
156
- return tags
157
- }
158
-
159
- function parseCore(inputEvent: string, parameters: string): ChatEvent {
160
- const [type, ...parts] = inputEvent.split(" ")
161
-
162
- switch (type) {
163
- case "PING":
164
- return {
165
- type,
166
- message: parameters,
167
- }
168
-
169
- case "001":
170
- return {
171
- type,
172
- channel: parts[0],
173
- message: parameters,
174
- }
175
-
176
- case "CAP":
177
- return {
178
- type,
179
- enabled: parts[1] === "ACK",
180
- nickname: parts[0],
181
- capabilities: parameters.split(" "),
182
- }
183
-
184
- case "JOIN":
185
- case "PART":
186
- return {
187
- type,
188
- channel: parts[0],
189
- }
190
-
191
- case "GLOBALUSERSTATE":
192
- case "RECONNECT":
193
- return {
194
- type,
195
- }
196
-
197
- case "CLEARCHAT":
198
- case "HOSTTARGET":
199
- case "NOTICE":
200
- case "ROOMSTATE":
201
- case "USERSTATE":
202
- return {
203
- type,
204
- channel: parts[0],
205
- }
206
-
207
- case "CLEARMSG":
208
- case "USERNOTICE":
209
- return {
210
- type,
211
- channel: parts[0],
212
- }
213
-
214
- case "PRIVMSG":
215
- case "WHISPER":
216
- if (parameters.startsWith("!")) {
217
- const index = parameters.indexOf(" ")
218
-
219
- return {
220
- type: `${type}-COMMAND`,
221
- channel: parts[0],
222
- command: parameters.slice(1, index > -1 ? index : undefined),
223
- parameters: index > -1 ? parameters.slice(index + 1) : undefined,
224
- }
225
- } else {
226
- return {
227
- type,
228
- channel: parts[0],
229
- message: parameters,
230
- }
231
- }
232
-
233
- // Ignoring all other numeric messages.
234
- case "002":
235
- case "003":
236
- case "004":
237
- case "353": // Tells you who else is in the chat room you're joining.
238
- case "366":
239
- case "372":
240
- case "375":
241
- case "376":
242
- throw new Error(`Ignored message: ${type}`)
243
-
244
- case "421":
245
- throw new Error(`Unsupported message: ${type}`)
246
-
247
- default:
248
- throw new Error(`Unknown message: ${type}`)
249
- }
250
- }
251
-
252
- function toCamelCase(dashedCase: string): string {
253
- return dashedCase.replace(/[-:]([a-z])/g, (_, b: string) => b.toUpperCase())
254
- }
@@ -1,51 +0,0 @@
1
- import { type BaseSubscription } from "../events-helpers.js"
2
-
3
- type ChannelAdBreakBeginType = "channel.ad_break.begin"
4
- type ChannelAdBreakBeginVersion = "beta"
5
-
6
- /** The parameters under which an event fires when A midroll commercial break starts running. */
7
- export interface ChannelAdBreakBeginCondition {
8
- /** The user ID of the broadcaster. */
9
- broadcaster_id: string
10
- }
11
-
12
- /** The event information when A midroll commercial break starts running. */
13
- export interface ChannelAdBreakBeginEvent {
14
- /** Integer. Length in seconds of the mid-roll ad break requested. */
15
- length_seconds: number
16
- /** The time the ad break began. Note that there is potential delay between this event, when the streamer requested the ad break, and when the viewers will see ads. */
17
- timestamp: Date
18
- /** Indicates if the ad was automatically scheduled via Ads Manager. */
19
- is_automatic: boolean
20
- /** The user ID of the broadcaster. */
21
- broadcaster_user_id: string
22
- /** The user login of the broadcaster. */
23
- broadcaster_user_login: string
24
- /** The user name of the broadcaster. */
25
- broadcaster_user_name: string
26
- /** The user ID of the user who requested the ad. For automatic ads, this will be the ID of the broadcaster. */
27
- requester_user_id: string
28
- /** The user name of the user who requested the ad. */
29
- requester_user_name: string
30
- /** The user login of the user who requested the ad. */
31
- requester_user_login: string
32
- }
33
-
34
- /** The event notification received when A midroll commercial break starts running. */
35
- export type ChannelAdBreakBeginSubscription = BaseSubscription<
36
- ChannelAdBreakBeginType,
37
- ChannelAdBreakBeginVersion,
38
- ChannelAdBreakBeginCondition
39
- >
40
-
41
- export function makeChannelAdBreakBeginSubscription(
42
- userId: string,
43
- ): ChannelAdBreakBeginSubscription {
44
- return {
45
- type: "channel.ad_break.begin",
46
- version: "beta",
47
- condition: {
48
- broadcaster_id: userId,
49
- },
50
- }
51
- }
@@ -1,59 +0,0 @@
1
- import { type BaseSubscription } from "../events-helpers.js"
2
-
3
- type ChannelBanType = "channel.ban"
4
- type ChannelBanVersion = "1"
5
-
6
- /** The parameters under which an event fires when A moderator bans a user. */
7
- export interface ChannelBanCondition {
8
- /** The user ID of the broadcaster. */
9
- broadcaster_user_id: string
10
- }
11
-
12
- /** The event information when A moderator bans a user. */
13
- export interface ChannelBanEvent {
14
- /** The user ID of the user who was banned. */
15
- user_id: string
16
- /** The user login of the user who was banned. */
17
- user_login: string
18
- /** The user name of the user who was banned. */
19
- user_name: string
20
- /** The user ID of the broadcaster. */
21
- broadcaster_user_id: string
22
- /** The user login of the broadcaster. */
23
- broadcaster_user_login: string
24
- /** The user name of the broadcaster. */
25
- broadcaster_user_name: string
26
- /** The user ID of the issuer of the ban. */
27
- moderator_user_id: string
28
- /** The user login of the issuer of the ban. */
29
- moderator_user_login: string
30
- /** The user name of the issuer of the ban. */
31
- moderator_user_name: string
32
- /** The reason behind the ban. */
33
- reason: string
34
- /** The time the user was banned or put in a timeout. */
35
- banned_at: Date
36
- /** The time the timeout ends. Is null if the user was banned instead of put in a timeout. */
37
- ends_at: Date
38
- /** Indicates whether the ban is permanent (true) or a timeout (false). If true, ends_at will be null. */
39
- is_permanent: boolean
40
- }
41
-
42
- /** The event notification received when A moderator bans a user. */
43
- export type ChannelBanSubscription = BaseSubscription<
44
- ChannelBanType,
45
- ChannelBanVersion,
46
- ChannelBanCondition
47
- >
48
-
49
- export function makeChannelBanSubscription(
50
- userId: string,
51
- ): ChannelBanSubscription {
52
- return {
53
- type: "channel.ban",
54
- version: "1",
55
- condition: {
56
- broadcaster_user_id: userId,
57
- },
58
- }
59
- }
@@ -1,29 +0,0 @@
1
- export interface ChannelPointsCustomRewardGlobalCooldown {
2
- /** Is the setting enabled. */
3
- is_enabled: boolean
4
- /** Integer. The cooldown in seconds. */
5
- seconds: number
6
- }
7
-
8
- export interface ChannelPointsCustomRewardMaxPerStream {
9
- /** Is the setting enabled. */
10
- is_enabled: boolean
11
- /** Integer. The max per stream limit. */
12
- value: number
13
- }
14
-
15
- export interface ChannelPointsCustomRewardMaxPerUserPerStream {
16
- /** Is the setting enabled. */
17
- is_enabled: boolean
18
- /** Integer. The max per user per stream limit. */
19
- value: number
20
- }
21
-
22
- export interface ChannelPointsCustomRewardImage {
23
- /** URL for the image at 1x size. */
24
- url_1x: string
25
- /** URL for the image at 2x size. */
26
- url_2x: string
27
- /** URL for the image at 3x size. */
28
- url_4x: string
29
- }