multichat-ts 0.0.6 → 0.0.8

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/kick.d.ts CHANGED
@@ -2,6 +2,8 @@ import Pusher from 'pusher-js';
2
2
  import { type BadgeURLsByNameOrCount, type EmoteURLsByName, type Message } from './index.js';
3
3
  type EventCallbackFunctions = {
4
4
  message: (message: Message) => unknown;
5
+ subscription: (data: ChatSubscriptionEvent) => unknown;
6
+ gifted: (data: ChatGiftedEvent) => unknown;
5
7
  raw_message: (message: ChatMessageEvent) => unknown;
6
8
  };
7
9
  type EventNames = keyof EventCallbackFunctions;
@@ -22,6 +24,8 @@ export declare class KickPusher {
22
24
  disconnect(): void;
23
25
  on<EventName extends EventNames>(event_name: EventName, callback_fn: EventCallbackFunctions[EventName]): void;
24
26
  private onSubscriptionSuccess;
27
+ private onChatSubscription;
28
+ private onChatGifted;
25
29
  private onChatMessage;
26
30
  }
27
31
  interface ChatMessageEvent {
@@ -44,4 +48,14 @@ interface ChatMessageEvent {
44
48
  };
45
49
  };
46
50
  }
51
+ interface ChatSubscriptionEvent {
52
+ chatroom_id: string;
53
+ username: string;
54
+ months: number;
55
+ }
56
+ interface ChatGiftedEvent {
57
+ chatroom_id: string;
58
+ gifted_usernames: string[];
59
+ gifter_username: string;
60
+ }
47
61
  export {};
package/dist/kick.js CHANGED
@@ -61,7 +61,9 @@ export class KickPusher {
61
61
  this.socket
62
62
  .subscribe(`chatrooms.${channel_response.chatroom.id}.v2`)
63
63
  .bind('pusher:subscription_succeeded', () => this.onSubscriptionSuccess())
64
- .bind('App\\Events\\ChatMessageEvent', (data) => this.onChatMessage(data));
64
+ .bind('App\\Events\\ChatMessageEvent', (data) => this.onChatMessage(data))
65
+ .bind('App\\Events\\SubscriptionEvent', (data) => this.onChatSubscription(data))
66
+ .bind('App\\Events\\GiftedSubscriptionsEvent', (data) => this.onChatGifted(data));
65
67
  }
66
68
  disconnect() {
67
69
  this.socket?.disconnect();
@@ -73,6 +75,12 @@ export class KickPusher {
73
75
  onSubscriptionSuccess() {
74
76
  console.log(`Connected to Kick Pusher (${this.channel_name})`);
75
77
  }
78
+ onChatSubscription(data) {
79
+ this.public_listeners.subscription?.(data);
80
+ }
81
+ onChatGifted(data) {
82
+ this.public_listeners.gifted?.(data);
83
+ }
76
84
  onChatMessage(data) {
77
85
  this.public_listeners.raw_message?.(data);
78
86
  const text = data.content;
package/dist/twitch.js CHANGED
@@ -86,7 +86,7 @@ export class TwitchIRC {
86
86
  onMessage(event) {
87
87
  if (!event.data)
88
88
  return;
89
- const lines = String(event.data).trim().split('\r\n');
89
+ const lines = event.data.trim().split('\r\n');
90
90
  const messages = lines.map(parseIRCLine);
91
91
  messages.forEach((message) => {
92
92
  this.public_listeners.raw_message?.(message);
@@ -258,9 +258,7 @@ function parseIRCLine(line) {
258
258
  }
259
259
  }
260
260
  if (params[0])
261
- params[0] = String.raw `${params[0]}`.replaceAll(new RegExp(`\\\\.+ACTION (.*)\\\\.+`, 'g'), function (_original, text_only) {
262
- return text_only;
263
- });
261
+ params[0] = String.raw `${params[0]}`.replaceAll(/.+ACTION (.*).+/g, (_original, group) => group);
264
262
  const tags = raw_tags_component ? parseTags(raw_tags_component, command) : undefined;
265
263
  return {
266
264
  channel,
package/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import { TwitchIRC } from './dist/twitch.js';
2
+ import WS from 'ws';
3
+
4
+ const twitch_chat = new TwitchIRC();
5
+ twitch_chat.ws = WS;
6
+
7
+ twitch_chat.connect({
8
+ channelName: '3b006',
9
+ });
package/package.json CHANGED
@@ -1,54 +1,54 @@
1
- {
2
- "name": "multichat-ts",
3
- "version": "0.0.6",
4
- "type": "module",
5
- "description": "Receive type-safe realtime events for chat-related messages on multiple platforms (Twitch, Kick)",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/0Abdullah/multichat-ts.git"
9
- },
10
- "homepage": "https://github.com/0Abdullah/multichat-ts",
11
- "main": "dist/index.js",
12
- "types": "dist/index.d.ts",
13
- "exports": {
14
- ".": "./dist/index.js"
15
- },
16
- "scripts": {
17
- "build": "tsc",
18
- "prepublishOnly": "pnpm build",
19
- "pub": "npm publish --access public",
20
- "lint": "eslint .",
21
- "lint:fix": "eslint . --fix",
22
- "format": "prettier --check src",
23
- "format:fix": "prettier --write src"
24
- },
25
- "keywords": [
26
- "chat",
27
- "multichat",
28
- "twitch",
29
- "kick",
30
- "realtime",
31
- "irc",
32
- "pusher",
33
- "typescript",
34
- "ts"
35
- ],
36
- "author": {
37
- "name": "Abdullah",
38
- "url": "https://github.com/0Abdullah"
39
- },
40
- "license": "MIT",
41
- "devDependencies": {
42
- "@eslint/js": "^9.10.0",
43
- "@types/node": "^22.5.4",
44
- "eslint": "^9.10.0",
45
- "eslint-config-prettier": "^9.1.0",
46
- "prettier": "^3.3.3",
47
- "typescript": "^5.5.4",
48
- "typescript-eslint": "^8.4.0"
49
- },
50
- "dependencies": {
51
- "partysocket": "^1.0.2",
52
- "pusher-js": "8.4.0-rc2"
53
- }
54
- }
1
+ {
2
+ "name": "multichat-ts",
3
+ "version": "0.0.8",
4
+ "type": "module",
5
+ "description": "Receive type-safe realtime events for chat-related messages on multiple platforms (Twitch, Kick)",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/0Abdullah/multichat-ts.git"
9
+ },
10
+ "homepage": "https://github.com/0Abdullah/multichat-ts",
11
+ "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "exports": {
14
+ ".": "./dist/index.js"
15
+ },
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "prepublishOnly": "pnpm build",
19
+ "pub": "npm publish --access public",
20
+ "lint": "eslint .",
21
+ "lint:fix": "eslint . --fix",
22
+ "format": "prettier --check src",
23
+ "format:fix": "prettier --write src"
24
+ },
25
+ "keywords": [
26
+ "chat",
27
+ "multichat",
28
+ "twitch",
29
+ "kick",
30
+ "realtime",
31
+ "irc",
32
+ "pusher",
33
+ "typescript",
34
+ "ts"
35
+ ],
36
+ "author": {
37
+ "name": "Abdullah",
38
+ "url": "https://github.com/0Abdullah"
39
+ },
40
+ "license": "MIT",
41
+ "devDependencies": {
42
+ "@eslint/js": "^9.10.0",
43
+ "@types/node": "^22.5.4",
44
+ "eslint": "^9.10.0",
45
+ "eslint-config-prettier": "^9.1.0",
46
+ "prettier": "^3.3.3",
47
+ "typescript": "^5.5.4",
48
+ "typescript-eslint": "^8.4.0"
49
+ },
50
+ "dependencies": {
51
+ "partysocket": "^1.0.2",
52
+ "pusher-js": "8.4.0-rc2"
53
+ }
54
+ }
package/src/kick.ts CHANGED
@@ -9,6 +9,8 @@ import {
9
9
 
10
10
  type EventCallbackFunctions = {
11
11
  message: (message: Message) => unknown;
12
+ subscription: (data: ChatSubscriptionEvent) => unknown;
13
+ gifted: (data: ChatGiftedEvent) => unknown;
12
14
  raw_message: (message: ChatMessageEvent) => unknown;
13
15
  };
14
16
 
@@ -106,7 +108,13 @@ export class KickPusher {
106
108
  this.socket
107
109
  .subscribe(`chatrooms.${channel_response.chatroom.id}.v2`)
108
110
  .bind('pusher:subscription_succeeded', () => this.onSubscriptionSuccess())
109
- .bind('App\\Events\\ChatMessageEvent', (data: ChatMessageEvent) => this.onChatMessage(data));
111
+ .bind('App\\Events\\ChatMessageEvent', (data: ChatMessageEvent) => this.onChatMessage(data))
112
+ .bind('App\\Events\\SubscriptionEvent', (data: ChatSubscriptionEvent) =>
113
+ this.onChatSubscription(data),
114
+ )
115
+ .bind('App\\Events\\GiftedSubscriptionsEvent', (data: ChatGiftedEvent) =>
116
+ this.onChatGifted(data),
117
+ );
110
118
  }
111
119
 
112
120
  public disconnect() {
@@ -125,6 +133,14 @@ export class KickPusher {
125
133
  console.log(`Connected to Kick Pusher (${this.channel_name})`);
126
134
  }
127
135
 
136
+ private onChatSubscription(data: ChatSubscriptionEvent) {
137
+ this.public_listeners.subscription?.(data);
138
+ }
139
+
140
+ private onChatGifted(data: ChatGiftedEvent) {
141
+ this.public_listeners.gifted?.(data);
142
+ }
143
+
128
144
  private onChatMessage(data: ChatMessageEvent) {
129
145
  this.public_listeners.raw_message?.(data);
130
146
  const text = data.content;
@@ -381,3 +397,15 @@ interface ChatMessageEvent {
381
397
  };
382
398
  };
383
399
  }
400
+
401
+ interface ChatSubscriptionEvent {
402
+ chatroom_id: string;
403
+ username: string;
404
+ months: number;
405
+ }
406
+
407
+ interface ChatGiftedEvent {
408
+ chatroom_id: string;
409
+ gifted_usernames: string[];
410
+ gifter_username: string;
411
+ }
package/src/twitch.ts CHANGED
@@ -136,7 +136,7 @@ export class TwitchIRC {
136
136
 
137
137
  private onMessage(event: MessageEvent) {
138
138
  if (!event.data) return;
139
- const lines = String(event.data).trim().split('\r\n');
139
+ const lines = (event.data as string).trim().split('\r\n');
140
140
  const messages = lines.map(parseIRCLine);
141
141
  messages.forEach((message) => {
142
142
  this.public_listeners.raw_message?.(message);
@@ -327,10 +327,8 @@ function parseIRCLine(line: string): IRC_Message {
327
327
  // TODO: handle message actions like "/me"
328
328
  if (params[0])
329
329
  params[0] = String.raw`${params[0]}`.replaceAll(
330
- new RegExp(`\\\\.+ACTION (.*)\\\\.+`, 'g'),
331
- function (_original, text_only) {
332
- return text_only;
333
- },
330
+ /.+ACTION (.*).+/g,
331
+ (_original, group) => group,
334
332
  );
335
333
 
336
334
  const tags = raw_tags_component ? parseTags(raw_tags_component, command) : undefined;