multichat-ts 0.0.83 → 0.0.85
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.
- package/dist/default/index.d.ts +5 -0
- package/dist/default/kick.d.ts +10 -2
- package/dist/default/kick.js +21 -7
- package/dist/worker/index.d.ts +5 -0
- package/dist/worker/kick.d.ts +10 -2
- package/dist/worker/kick.js +21 -7
- package/package.json +1 -1
- package/src/default/index.ts +5 -0
- package/src/default/kick.ts +45 -10
- package/src/worker/index.ts +173 -168
- package/src/worker/kick.ts +446 -411
- package/src/worker/twitch.ts +540 -540
package/src/worker/kick.ts
CHANGED
|
@@ -1,411 +1,446 @@
|
|
|
1
|
-
import Pusher from 'pusher-js/worker';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
type BadgeURLsByNameOrCount,
|
|
5
|
-
type BodyComponent,
|
|
6
|
-
type EmoteURLsByName,
|
|
7
|
-
type Message,
|
|
8
|
-
} from './index.js';
|
|
9
|
-
|
|
10
|
-
type EventCallbackFunctions = {
|
|
11
|
-
message: (message: Message) => unknown;
|
|
12
|
-
subscription: (data: ChatSubscriptionEvent) => unknown;
|
|
13
|
-
gifted: (data: ChatGiftedEvent) => unknown;
|
|
14
|
-
raw_message: (message: ChatMessageEvent) => unknown;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type EventNames = keyof EventCallbackFunctions;
|
|
18
|
-
|
|
19
|
-
const DEFAULT_KICK_PUSHER_KEY = '32cbd69e4b950bf97679';
|
|
20
|
-
|
|
21
|
-
export class KickPusher {
|
|
22
|
-
public kick_pusher_key = DEFAULT_KICK_PUSHER_KEY;
|
|
23
|
-
public channel_name?: string;
|
|
24
|
-
private assets: {
|
|
25
|
-
external_emotes: EmoteURLsByName;
|
|
26
|
-
badges: BadgeURLsByNameOrCount;
|
|
27
|
-
} = {
|
|
28
|
-
external_emotes: {},
|
|
29
|
-
badges: {
|
|
30
|
-
founder: '/svgs/badges/default-kick/founder.svg',
|
|
31
|
-
moderator: '/svgs/badges/default-kick/moderator.svg',
|
|
32
|
-
og: '/svgs/badges/default-kick/og.svg',
|
|
33
|
-
sub_gifter: {
|
|
34
|
-
1: '/svgs/badges/default-kick/sub-gifter-blue.svg',
|
|
35
|
-
25: '/svgs/badges/default-kick/sub-gifter-purple.svg',
|
|
36
|
-
50: '/svgs/badges/default-kick/sub-gifter-red.svg',
|
|
37
|
-
100: '/svgs/badges/default-kick/sub-gifter-yellow.svg',
|
|
38
|
-
200: '/svgs/badges/default-kick/sub-gifter-green.svg',
|
|
39
|
-
},
|
|
40
|
-
verified: '/svgs/badges/default-kick/verified.svg',
|
|
41
|
-
vip: '/svgs/badges/default-kick/vip.svg',
|
|
42
|
-
broadcaster: '/svgs/badges/default-kick/broadcaster.svg',
|
|
43
|
-
staff: '/svgs/badges/default-kick/staff.svg',
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
private public_listeners: Partial<EventCallbackFunctions> = {};
|
|
48
|
-
|
|
49
|
-
public socket?: Pusher;
|
|
50
|
-
public isConnected = false;
|
|
51
|
-
|
|
52
|
-
public setBadges(badges: BadgeURLsByNameOrCount) {
|
|
53
|
-
this.assets.badges = { ...this.assets.badges, ...badges };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public setExternalEmotes(external_emotes: EmoteURLsByName) {
|
|
57
|
-
this.assets.external_emotes = { ...this.assets.external_emotes, ...external_emotes };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public getStoredBadges() {
|
|
61
|
-
return this.assets.badges;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public getStoredExternalEmotes() {
|
|
65
|
-
return this.assets.external_emotes;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
public async connect(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
this.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
| 'App\\Events\\
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
export interface
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
1
|
+
import Pusher from 'pusher-js/worker';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type BadgeURLsByNameOrCount,
|
|
5
|
+
type BodyComponent,
|
|
6
|
+
type EmoteURLsByName,
|
|
7
|
+
type Message,
|
|
8
|
+
} from './index.js';
|
|
9
|
+
|
|
10
|
+
type EventCallbackFunctions = {
|
|
11
|
+
message: (message: Message) => unknown;
|
|
12
|
+
subscription: (data: ChatSubscriptionEvent) => unknown;
|
|
13
|
+
gifted: (data: ChatGiftedEvent) => unknown;
|
|
14
|
+
raw_message: (message: ChatMessageEvent) => unknown;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type EventNames = keyof EventCallbackFunctions;
|
|
18
|
+
|
|
19
|
+
const DEFAULT_KICK_PUSHER_KEY = '32cbd69e4b950bf97679';
|
|
20
|
+
|
|
21
|
+
export class KickPusher {
|
|
22
|
+
public kick_pusher_key = DEFAULT_KICK_PUSHER_KEY;
|
|
23
|
+
public channel_name?: string;
|
|
24
|
+
private assets: {
|
|
25
|
+
external_emotes: EmoteURLsByName;
|
|
26
|
+
badges: BadgeURLsByNameOrCount;
|
|
27
|
+
} = {
|
|
28
|
+
external_emotes: {},
|
|
29
|
+
badges: {
|
|
30
|
+
founder: '/svgs/badges/default-kick/founder.svg',
|
|
31
|
+
moderator: '/svgs/badges/default-kick/moderator.svg',
|
|
32
|
+
og: '/svgs/badges/default-kick/og.svg',
|
|
33
|
+
sub_gifter: {
|
|
34
|
+
1: '/svgs/badges/default-kick/sub-gifter-blue.svg',
|
|
35
|
+
25: '/svgs/badges/default-kick/sub-gifter-purple.svg',
|
|
36
|
+
50: '/svgs/badges/default-kick/sub-gifter-red.svg',
|
|
37
|
+
100: '/svgs/badges/default-kick/sub-gifter-yellow.svg',
|
|
38
|
+
200: '/svgs/badges/default-kick/sub-gifter-green.svg',
|
|
39
|
+
},
|
|
40
|
+
verified: '/svgs/badges/default-kick/verified.svg',
|
|
41
|
+
vip: '/svgs/badges/default-kick/vip.svg',
|
|
42
|
+
broadcaster: '/svgs/badges/default-kick/broadcaster.svg',
|
|
43
|
+
staff: '/svgs/badges/default-kick/staff.svg',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
private public_listeners: Partial<EventCallbackFunctions> = {};
|
|
48
|
+
|
|
49
|
+
public socket?: Pusher;
|
|
50
|
+
public isConnected = false;
|
|
51
|
+
|
|
52
|
+
public setBadges(badges: BadgeURLsByNameOrCount) {
|
|
53
|
+
this.assets.badges = { ...this.assets.badges, ...badges };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public setExternalEmotes(external_emotes: EmoteURLsByName) {
|
|
57
|
+
this.assets.external_emotes = { ...this.assets.external_emotes, ...external_emotes };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public getStoredBadges() {
|
|
61
|
+
return this.assets.badges;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public getStoredExternalEmotes() {
|
|
65
|
+
return this.assets.external_emotes;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public async connect(
|
|
69
|
+
channel?: { channelName?: string },
|
|
70
|
+
get_channel: (channelName: string) => Promise<GetChannelResponse | undefined> = async (
|
|
71
|
+
channelName,
|
|
72
|
+
) => {
|
|
73
|
+
const res = await fetch(`https://kick.com/api/v2/channels/${channelName}`, {
|
|
74
|
+
headers: {
|
|
75
|
+
accept: 'aplication/json',
|
|
76
|
+
'user-agent':
|
|
77
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
const json = await res.json();
|
|
81
|
+
return json as GetChannelResponse | undefined;
|
|
82
|
+
},
|
|
83
|
+
) {
|
|
84
|
+
if (channel?.channelName) this.channel_name = channel.channelName;
|
|
85
|
+
if (!this.channel_name) return console.error('channel_name not specified');
|
|
86
|
+
|
|
87
|
+
console.log(`connecting to ${this.channel_name}...`);
|
|
88
|
+
|
|
89
|
+
const channel_response = await get_channel(this.channel_name);
|
|
90
|
+
|
|
91
|
+
if (!channel_response) return console.error('Failed to connect to Kick.com chat');
|
|
92
|
+
|
|
93
|
+
channel_response.subscriber_badges.forEach((subscriber_badge) => {
|
|
94
|
+
this.assets.badges['subscriber'] = {
|
|
95
|
+
...(this.assets.badges['subscriber'] ?? {}),
|
|
96
|
+
[subscriber_badge.months]: subscriber_badge.badge_image.src,
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
this.disconnect();
|
|
101
|
+
|
|
102
|
+
this.socket = new Pusher(this.kick_pusher_key, {
|
|
103
|
+
cluster: 'us2',
|
|
104
|
+
});
|
|
105
|
+
/*
|
|
106
|
+
| 'App\\Events\\ChatMessageEvent'
|
|
107
|
+
| 'App\\Events\\ChatroomClearEvent'
|
|
108
|
+
| 'App\\Events\\ChatroomUpdatedEvent'
|
|
109
|
+
| 'App\\Events\\GiftedSubscriptionsEvent'
|
|
110
|
+
| 'App\\Events\\MessageDeletedEvent'
|
|
111
|
+
| 'App\\Events\\PinnedMessageCreatedEvent'
|
|
112
|
+
| 'App\\Events\\PinnedMessageDeletedEvent'
|
|
113
|
+
| 'App\\Events\\PollDeleteEvent'
|
|
114
|
+
| 'App\\Events\\PollUpdateEvent'
|
|
115
|
+
| 'App\\Events\\StreamHostEvent'
|
|
116
|
+
| 'App\\Events\\SubscriptionEvent'
|
|
117
|
+
| 'App\\Events\\UserBannedEvent'
|
|
118
|
+
| 'App\\Events\\UserUnbannedEvent'
|
|
119
|
+
*/
|
|
120
|
+
this.socket
|
|
121
|
+
.subscribe(`chatrooms.${channel_response.chatroom.id}.v2`)
|
|
122
|
+
.bind('pusher:subscription_succeeded', () => this.onSubscriptionSuccess())
|
|
123
|
+
.bind('App\\Events\\ChatMessageEvent', (data: ChatMessageEvent) => this.onChatMessage(data))
|
|
124
|
+
.bind('App\\Events\\SubscriptionEvent', (data: ChatSubscriptionEvent) =>
|
|
125
|
+
this.onChatSubscription(data),
|
|
126
|
+
)
|
|
127
|
+
.bind('App\\Events\\GiftedSubscriptionsEvent', (data: ChatGiftedEvent) =>
|
|
128
|
+
this.onChatGifted(data),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
{"event":"App\\Events\\ChatMessageSentEvent","data":"{\"message\":{\"id\":\"e676ab50-d59c-43ae-b7cd-2b60c5b89c08\",\"message\":null,\"type\":\"info\",\"replied_to\":null,\"is_info\":null,\"link_preview\":null,\"chatroom_id\":5755510,\"role\":\"user\",\"created_at\":1736022879,\"action\":\"gift\",\"optional_message\":null,\"months_subscribed\":null,\"subscriptions_count\":5,\"giftedUsers\":[{\"username\":\"lovesxb1\",\"monthsSubscribed\":1},{\"username\":\"O7no\",\"monthsSubscribed\":1},{\"username\":\"viiRayan\",\"monthsSubscribed\":1},{\"username\":\"Shabib_3005\",\"monthsSubscribed\":1},{\"username\":\"Khadielja\",\"monthsSubscribed\":1}]},\"user\":{\"id\":34844645,\"username\":\"Jana_ai\",\"role\":\"user\",\"isSuperAdmin\":null,\"profile_thumb\":\"https:\\/\\/kick-files-prod.s3.us-west-2.amazonaws.com\\/images\\/user\\/34844645\\/profile_image\\/conversion\\/90b8d01a-acda-4cdb-896b-8ce6d40b6767-thumb.webp?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAS3MDRZGPDOOAYROR%2F20250104%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20250104T203439Z&X-Amz-SignedHeaders=host&X-Amz-Expires=300&X-Amz-Signature=ac0e479335c68c7be15861e9f78866410d64fa1627fc87433365f110901243c0\",\"verified\":false,\"follower_badges\":[],\"is_subscribed\":null,\"is_founder\":false,\"months_subscribed\":null,\"quantity_gifted\":0}}","channel":"chatrooms.5755510"}
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
/*
|
|
136
|
+
{"event":"App\\Events\\LuckyUsersWhoGotGiftSubscriptionsEvent","data":"{\"channel\":{\"id\":5789932,\"user_id\":5882384,\"slug\":\"sulaiman\",\"is_banned\":false,\"playback_url\":\"https:\\/\\/fa723fc1b171.us-west-2.playback.live-video.net\\/api\\/video\\/v1\\/us-west-2.196233775518.channel.L29JBfLzKok0.m3u8\",\"name_updated_at\":null,\"vod_enabled\":true,\"subscription_enabled\":true,\"is_affiliate\":false,\"can_host\":true,\"chatroom\":{\"id\":5755510,\"chatable_type\":\"App\\\\Models\\\\Channel\",\"channel_id\":5789932,\"created_at\":\"2023-06-08T08:24:23.000000Z\",\"updated_at\":\"2024-12-11T07:20:32.000000Z\",\"chat_mode_old\":\"public\",\"chat_mode\":\"public\",\"slow_mode\":false,\"chatable_id\":5789932,\"followers_mode\":true,\"subscribers_mode\":false,\"emotes_mode\":false,\"message_interval\":6,\"following_min_duration\":0}},\"usernames\":[\"lovesxb1\",\"O7no\",\"viiRayan\",\"Shabib_3005\",\"Khadielja\"],\"gifter_username\":\"Jana_ai\"}","channel":"channel.5789932"}
|
|
137
|
+
*/
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public disconnect() {
|
|
141
|
+
this.socket?.disconnect();
|
|
142
|
+
this.socket?.unbind_all();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public on<EventName extends EventNames>(
|
|
146
|
+
event_name: EventName,
|
|
147
|
+
callback_fn: EventCallbackFunctions[EventName],
|
|
148
|
+
) {
|
|
149
|
+
this.public_listeners[event_name] = callback_fn;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private onSubscriptionSuccess() {
|
|
153
|
+
console.log(`Connected to Kick Pusher (${this.channel_name})`);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private onChatSubscription(data: ChatSubscriptionEvent) {
|
|
157
|
+
this.public_listeners.subscription?.(data);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private onChatGifted(data: ChatGiftedEvent) {
|
|
161
|
+
this.public_listeners.gifted?.(data);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private onChatMessage(data: ChatMessageEvent) {
|
|
165
|
+
this.public_listeners.raw_message?.(data);
|
|
166
|
+
const text = data.content;
|
|
167
|
+
const emote_matches = [...data.content.matchAll(/\[emote:\d+:[a-zA-Z0-9]*\]/g)];
|
|
168
|
+
|
|
169
|
+
const body: BodyComponent[] = [];
|
|
170
|
+
|
|
171
|
+
emote_matches.forEach((match) => {
|
|
172
|
+
const emote_string = match[0];
|
|
173
|
+
const emote_parts = emote_string.slice(1, emote_string.length - 1).split(':');
|
|
174
|
+
const emote_id = emote_parts[1];
|
|
175
|
+
if (!emote_id) return;
|
|
176
|
+
console.log(emote_id);
|
|
177
|
+
|
|
178
|
+
body.push({
|
|
179
|
+
type: 'emote',
|
|
180
|
+
start_inclusive: match.index,
|
|
181
|
+
end_exclusive: match.index + emote_string.length,
|
|
182
|
+
url: `https://files.kick.com/emotes/${emote_id}/fullsize`,
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
body.sort((a, b) => a.start_inclusive - b.start_inclusive);
|
|
187
|
+
|
|
188
|
+
const old_body_length = body.length;
|
|
189
|
+
|
|
190
|
+
if (old_body_length > 0) {
|
|
191
|
+
body.forEach((segment, index) => {
|
|
192
|
+
const previous_segment = body[index - 1];
|
|
193
|
+
|
|
194
|
+
const text_start_inclusive =
|
|
195
|
+
previous_segment?.end_exclusive !== undefined ? previous_segment.end_exclusive + 1 : 0;
|
|
196
|
+
const text_end_exclusive = Math.max(0, segment.start_inclusive);
|
|
197
|
+
|
|
198
|
+
if (text_end_exclusive - text_start_inclusive > 0) {
|
|
199
|
+
body.push({
|
|
200
|
+
type: 'text',
|
|
201
|
+
text: text.slice(text_start_inclusive, text_end_exclusive),
|
|
202
|
+
start_inclusive: text_start_inclusive,
|
|
203
|
+
end_exclusive: text_end_exclusive,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
if (index === old_body_length - 1 && segment.end_exclusive < text.length - 1) {
|
|
207
|
+
body.push({
|
|
208
|
+
type: 'text',
|
|
209
|
+
text: text.slice(segment.end_exclusive),
|
|
210
|
+
start_inclusive: segment.end_exclusive,
|
|
211
|
+
end_exclusive: text.length,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
} else {
|
|
216
|
+
body.push({
|
|
217
|
+
type: 'text',
|
|
218
|
+
text,
|
|
219
|
+
start_inclusive: 0,
|
|
220
|
+
end_exclusive: text.length,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
body.sort((a, b) => a.start_inclusive - b.start_inclusive);
|
|
225
|
+
const message: Message = {
|
|
226
|
+
id: data.id,
|
|
227
|
+
user: {
|
|
228
|
+
id: `${data.sender.id}`,
|
|
229
|
+
username: data.sender.slug ?? data.sender.username.toLowerCase(),
|
|
230
|
+
display_name: data.sender.username,
|
|
231
|
+
roles: {},
|
|
232
|
+
color: data.sender.identity.color,
|
|
233
|
+
badges: data.sender.identity.badges.flatMap((badge) => {
|
|
234
|
+
let badge_url: string | undefined = undefined;
|
|
235
|
+
|
|
236
|
+
const badge_url_or_counts = this.assets.badges[badge.type];
|
|
237
|
+
const badge_count = badge.count;
|
|
238
|
+
|
|
239
|
+
if (typeof badge_url_or_counts === 'string') badge_url = badge_url_or_counts;
|
|
240
|
+
else if (typeof badge_url_or_counts === 'object' && badge_count !== undefined) {
|
|
241
|
+
const badge_entry_by_count = Object.entries(badge_url_or_counts)
|
|
242
|
+
.sort(([a_min_count], [b_min_count]) => Number(a_min_count) - Number(b_min_count))
|
|
243
|
+
.find(([min_count]) => badge_count >= Number(min_count));
|
|
244
|
+
if (badge_entry_by_count) badge_url = badge_entry_by_count[1];
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (!badge_url) return [];
|
|
248
|
+
return {
|
|
249
|
+
set_id: badge.type,
|
|
250
|
+
url: badge_url,
|
|
251
|
+
info: String(badge.count),
|
|
252
|
+
};
|
|
253
|
+
}),
|
|
254
|
+
},
|
|
255
|
+
body,
|
|
256
|
+
channel: {
|
|
257
|
+
room_id: String(data.chatroom_id),
|
|
258
|
+
name: this.channel_name ?? 'unknown',
|
|
259
|
+
},
|
|
260
|
+
raw_text: data.content,
|
|
261
|
+
timestamp_sent: Date.parse(data.created_at),
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
if (data.type === 'celebration' && data.metadata?.celebration) {
|
|
265
|
+
message.resubscription = {
|
|
266
|
+
id: data.metadata.celebration.id,
|
|
267
|
+
months: data.metadata.celebration.total_months,
|
|
268
|
+
subscribed_since_timestamp: data.metadata.celebration.created_at,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
this.public_listeners.message?.(message);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export interface GetChannelResponse {
|
|
276
|
+
id: number;
|
|
277
|
+
user_id: number;
|
|
278
|
+
slug: string;
|
|
279
|
+
is_banned: boolean;
|
|
280
|
+
playback_url?: string;
|
|
281
|
+
vod_enabled: boolean;
|
|
282
|
+
subscription_enabled: boolean;
|
|
283
|
+
followers_count: number;
|
|
284
|
+
following?: boolean;
|
|
285
|
+
subscription?: unknown;
|
|
286
|
+
subscriber_badges: Array<{
|
|
287
|
+
id: number;
|
|
288
|
+
channel_id: number;
|
|
289
|
+
months: number;
|
|
290
|
+
badge_image: {
|
|
291
|
+
srcset: string;
|
|
292
|
+
src: string;
|
|
293
|
+
};
|
|
294
|
+
}>;
|
|
295
|
+
banner_image?: {
|
|
296
|
+
url: string;
|
|
297
|
+
};
|
|
298
|
+
livestream?: ChannelLivestream;
|
|
299
|
+
role?: unknown;
|
|
300
|
+
muted: boolean;
|
|
301
|
+
follower_badges: unknown[];
|
|
302
|
+
offline_banner_image: unknown;
|
|
303
|
+
verified: boolean;
|
|
304
|
+
recent_categories: Array<{
|
|
305
|
+
id: number;
|
|
306
|
+
category_id: number;
|
|
307
|
+
name: string;
|
|
308
|
+
slug: string;
|
|
309
|
+
tags: string[];
|
|
310
|
+
description?: string;
|
|
311
|
+
deleted_at: unknown;
|
|
312
|
+
viewers: number;
|
|
313
|
+
banner: {
|
|
314
|
+
responsive: string;
|
|
315
|
+
url: string;
|
|
316
|
+
};
|
|
317
|
+
category: {
|
|
318
|
+
id: number;
|
|
319
|
+
name: string;
|
|
320
|
+
slug: string;
|
|
321
|
+
icon: string;
|
|
322
|
+
};
|
|
323
|
+
}>;
|
|
324
|
+
can_host: boolean;
|
|
325
|
+
user: {
|
|
326
|
+
id: number;
|
|
327
|
+
username: string;
|
|
328
|
+
agreed_to_terms: true;
|
|
329
|
+
email_verified_at: Date;
|
|
330
|
+
bio?: string;
|
|
331
|
+
country?: string;
|
|
332
|
+
state?: string;
|
|
333
|
+
city?: string;
|
|
334
|
+
instagram?: string;
|
|
335
|
+
twitter?: string;
|
|
336
|
+
youtube?: string;
|
|
337
|
+
discord?: string;
|
|
338
|
+
tiktok?: string;
|
|
339
|
+
facebook?: string;
|
|
340
|
+
profile_pic?: string;
|
|
341
|
+
};
|
|
342
|
+
chatroom: ChannelChatroom;
|
|
343
|
+
ascending_links?: Array<{
|
|
344
|
+
id: number;
|
|
345
|
+
channel_id: number;
|
|
346
|
+
description: string;
|
|
347
|
+
link: string;
|
|
348
|
+
created_at: Date;
|
|
349
|
+
updated_at: Date;
|
|
350
|
+
order: number;
|
|
351
|
+
title: string;
|
|
352
|
+
}>;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export interface ChannelLivestream {
|
|
356
|
+
id: number;
|
|
357
|
+
slug: string;
|
|
358
|
+
channel_id: number;
|
|
359
|
+
created_at: Date;
|
|
360
|
+
session_title: string;
|
|
361
|
+
is_live: boolean;
|
|
362
|
+
risk_level_id: unknown;
|
|
363
|
+
start_time: Date;
|
|
364
|
+
source: unknown;
|
|
365
|
+
twitch_channel: unknown;
|
|
366
|
+
duration: number;
|
|
367
|
+
language: string;
|
|
368
|
+
is_mature: boolean;
|
|
369
|
+
viewer_count: number;
|
|
370
|
+
thumbnail: {
|
|
371
|
+
url: string;
|
|
372
|
+
};
|
|
373
|
+
categories: Array<{
|
|
374
|
+
id: number;
|
|
375
|
+
category_id: number;
|
|
376
|
+
name: string;
|
|
377
|
+
slug: string;
|
|
378
|
+
tags: string[];
|
|
379
|
+
description?: string;
|
|
380
|
+
deleted_at: unknown;
|
|
381
|
+
viewers: number;
|
|
382
|
+
category: {
|
|
383
|
+
id: number;
|
|
384
|
+
name: string;
|
|
385
|
+
slug: string;
|
|
386
|
+
icon: string;
|
|
387
|
+
};
|
|
388
|
+
}>;
|
|
389
|
+
tags: unknown[];
|
|
390
|
+
}
|
|
391
|
+
export interface ChannelChatroom {
|
|
392
|
+
id: number;
|
|
393
|
+
chatable_type: string;
|
|
394
|
+
channel_id: string;
|
|
395
|
+
created_at: Date;
|
|
396
|
+
updated_at: Date;
|
|
397
|
+
chat_mode_old: string;
|
|
398
|
+
chat_mode: string;
|
|
399
|
+
slow_mode: boolean;
|
|
400
|
+
chatable_id: number;
|
|
401
|
+
followers_mode: boolean;
|
|
402
|
+
subscribers_mode: boolean;
|
|
403
|
+
emotes_mode: boolean;
|
|
404
|
+
message_interval: number;
|
|
405
|
+
following_min_duration: number;
|
|
406
|
+
}
|
|
407
|
+
export interface ChatMessageEvent {
|
|
408
|
+
id: string;
|
|
409
|
+
chatroom_id: number;
|
|
410
|
+
content: string;
|
|
411
|
+
type: 'message' | 'celebration';
|
|
412
|
+
created_at: string;
|
|
413
|
+
metadata?: {
|
|
414
|
+
celebration: {
|
|
415
|
+
created_at: string;
|
|
416
|
+
id: string;
|
|
417
|
+
total_months: number;
|
|
418
|
+
type: 'subscription_renewed';
|
|
419
|
+
};
|
|
420
|
+
};
|
|
421
|
+
sender: {
|
|
422
|
+
id: number;
|
|
423
|
+
username: string;
|
|
424
|
+
slug?: string;
|
|
425
|
+
identity: {
|
|
426
|
+
color: string;
|
|
427
|
+
badges: Array<{
|
|
428
|
+
type: string;
|
|
429
|
+
text: string;
|
|
430
|
+
count?: number;
|
|
431
|
+
}>;
|
|
432
|
+
};
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export interface ChatSubscriptionEvent {
|
|
437
|
+
chatroom_id: string;
|
|
438
|
+
username: string;
|
|
439
|
+
months: number;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export interface ChatGiftedEvent {
|
|
443
|
+
chatroom_id: string;
|
|
444
|
+
gifted_usernames: string[];
|
|
445
|
+
gifter_username: string;
|
|
446
|
+
}
|