multichat-ts 0.0.2 → 0.0.3

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/README.md CHANGED
@@ -40,14 +40,17 @@ kick_chat.on('message', (message) => {
40
40
 
41
41
  ```svelte
42
42
  <script lang="ts">
43
- import { TwitchIRC, type Message, KickPusher } from 'multichat-ts';
43
+ import { TwitchIRC, type Message } from 'multichat-ts';
44
44
 
45
45
  let messages: Message[] = $state([]);
46
46
 
47
47
  const twitch_chat = new TwitchIRC();
48
+ $effect(() => {
49
+ twitch_chat.connect({
50
+ channelName: 'piratesoftware'
51
+ });
48
52
 
49
- twitch_chat.connect({
50
- channelName: 'piratesoftware'
53
+ return () => twitch_chat.disconnect();
51
54
  });
52
55
 
53
56
  twitch_chat.on('message', (message) => {
package/dist/index.d.ts CHANGED
@@ -134,10 +134,9 @@ export type BadgeURLsByNameOrCount = {
134
134
  [badge_count: number]: string;
135
135
  };
136
136
  };
137
- export type BadgeURLsBySetIDAndVersionID = {
138
- [badge_set_id: string]: {
139
- [badge_version_id: string]: string;
140
- };
137
+ type StringOrAny = '*' | (string & Record<never, never>);
138
+ export type BadgeURLsBySetIDAndVersionIDOrAny = {
139
+ [badge_set_id: string]: Record<StringOrAny, string>;
141
140
  };
142
141
  export type EmoteURLsByName = {
143
142
  [emote_name: string]: string;
package/dist/twitch.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { WebSocket } from 'partysocket';
2
- import { type ClearMessages, type DeleteMessage, type Message, type Event, type EmoteURLsByName, type BadgeURLsBySetIDAndVersionID } from './index.js';
2
+ import { type ClearMessages, type DeleteMessage, type Message, type Event, type EmoteURLsByName, type BadgeURLsBySetIDAndVersionIDOrAny } from './index.js';
3
3
  type EventCallbackFunctions = {
4
4
  message: (data: Message) => unknown;
5
5
  clear_messages: (data: ClearMessages) => unknown;
@@ -11,12 +11,14 @@ export declare class TwitchIRC {
11
11
  channel_name?: string;
12
12
  assets: {
13
13
  external_emotes: EmoteURLsByName;
14
- badges: BadgeURLsBySetIDAndVersionID;
14
+ badges: BadgeURLsBySetIDAndVersionIDOrAny;
15
15
  };
16
16
  latency: number;
17
17
  private ping;
18
18
  private public_listeners;
19
19
  socket?: WebSocket;
20
+ ws?: WebSocket | undefined;
21
+ constructor(ws?: WebSocket);
20
22
  connect(channel?: {
21
23
  channelName?: string;
22
24
  }): void;
package/dist/twitch.js CHANGED
@@ -13,6 +13,10 @@ export class TwitchIRC {
13
13
  ping = {};
14
14
  public_listeners = {};
15
15
  socket;
16
+ ws;
17
+ constructor(ws) {
18
+ this.ws = ws;
19
+ }
16
20
  connect(channel) {
17
21
  if (channel?.channelName)
18
22
  this.channel_name = channel.channelName;
@@ -20,11 +24,12 @@ export class TwitchIRC {
20
24
  return console.error('channel_name not specified');
21
25
  console.log(`connecting to ${this.channel_name}...`);
22
26
  this.socket?.close();
23
- this.socket = new WebSocket('wss://irc-ws.chat.twitch.tv');
27
+ this.socket = new WebSocket('wss://irc-ws.chat.twitch.tv', null, {
28
+ WebSocket: this.ws,
29
+ });
24
30
  this.socket.onopen = () => this.onOpen();
25
31
  this.socket.onclose = () => this.onClose();
26
32
  this.socket.onmessage = (event) => this.onMessage(event);
27
- console.log(parseIRCLine(`@badge-info=;badges=turbo/1;color=#9ACD32;display-name=TestChannel;emotes=;id=3d830f12-795c-447d-af3c-ea05e40fbddb;login=testchannel;mod=0;msg-id=raid;msg-param-displayName=TestChannel;msg-param-login=testchannel;msg-param-viewerCount=15;room-id=33332222;subscriber=0;system-msg=15\sraiders\sfrom\sTestChannel\shave\sjoined\n!;tmi-sent-ts=1507246572675;turbo=1;user-id=123456;user-type= :tmi.twitch.tv USERNOTICE #othertestchannel`));
28
33
  }
29
34
  disconnect() {
30
35
  this.socket?.close();
@@ -183,7 +188,7 @@ export class TwitchIRC {
183
188
  const [set_id, version] = badge.split('/');
184
189
  if (!set_id || !version)
185
190
  return [];
186
- const url = this.assets.badges[set_id]?.[version];
191
+ const url = this.assets.badges[set_id]?.[version] ?? this.assets.badges[set_id]?.['*'];
187
192
  if (!url)
188
193
  return [];
189
194
  return {
@@ -194,7 +199,7 @@ export class TwitchIRC {
194
199
  }) ?? [],
195
200
  color: tags.color ?? '#FFFFFF',
196
201
  id: tags['user-id'],
197
- username: 'IDK',
202
+ username: (tags['display-name'] ?? 'Unknown').toLowerCase(),
198
203
  display_name: tags['display-name'] ?? 'Unknown',
199
204
  roles: {},
200
205
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "multichat-ts",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "description": "Receive type-safe realtime events for chat-related messages on multiple platforms (Twitch, Kick)",
6
6
  "repository": {
package/src/index.ts CHANGED
@@ -155,10 +155,10 @@ export type BadgeURLsByNameOrCount = {
155
155
  };
156
156
  };
157
157
 
158
- export type BadgeURLsBySetIDAndVersionID = {
159
- [badge_set_id: string]: {
160
- [badge_version_id: string]: string;
161
- };
158
+ type StringOrAny = '*' | (string & Record<never, never>);
159
+
160
+ export type BadgeURLsBySetIDAndVersionIDOrAny = {
161
+ [badge_set_id: string]: Record<StringOrAny, string>;
162
162
  };
163
163
 
164
164
  export type EmoteURLsByName = {
package/src/twitch.ts CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  type Message,
8
8
  type Event,
9
9
  type EmoteURLsByName,
10
- type BadgeURLsBySetIDAndVersionID,
10
+ type BadgeURLsBySetIDAndVersionIDOrAny,
11
11
  } from './index.js';
12
12
 
13
13
  const ANONYMOUS_IRC_PASS = 'SCHMOOPIIE';
@@ -28,7 +28,7 @@ export class TwitchIRC {
28
28
  public channel_name?: string;
29
29
  public assets: {
30
30
  external_emotes: EmoteURLsByName;
31
- badges: BadgeURLsBySetIDAndVersionID;
31
+ badges: BadgeURLsBySetIDAndVersionIDOrAny;
32
32
  } = {
33
33
  external_emotes: {},
34
34
  badges: {},
@@ -44,6 +44,11 @@ export class TwitchIRC {
44
44
  private public_listeners: Partial<EventCallbackFunctions> = {};
45
45
 
46
46
  public socket?: WebSocket;
47
+ public ws?: WebSocket | undefined;
48
+
49
+ constructor(ws?: WebSocket) {
50
+ this.ws = ws;
51
+ }
47
52
 
48
53
  public connect(channel?: { channelName?: string }) {
49
54
  if (channel?.channelName) this.channel_name = channel.channelName;
@@ -53,17 +58,12 @@ export class TwitchIRC {
53
58
 
54
59
  this.socket?.close();
55
60
 
56
- this.socket = new WebSocket('wss://irc-ws.chat.twitch.tv');
61
+ this.socket = new WebSocket('wss://irc-ws.chat.twitch.tv', null, {
62
+ WebSocket: this.ws,
63
+ });
57
64
  this.socket.onopen = () => this.onOpen();
58
65
  this.socket.onclose = () => this.onClose();
59
66
  this.socket.onmessage = (event) => this.onMessage(event);
60
-
61
- console.log(
62
- parseIRCLine(
63
- // eslint-disable-next-line no-useless-escape
64
- `@badge-info=;badges=turbo/1;color=#9ACD32;display-name=TestChannel;emotes=;id=3d830f12-795c-447d-af3c-ea05e40fbddb;login=testchannel;mod=0;msg-id=raid;msg-param-displayName=TestChannel;msg-param-login=testchannel;msg-param-viewerCount=15;room-id=33332222;subscriber=0;system-msg=15\sraiders\sfrom\sTestChannel\shave\sjoined\n!;tmi-sent-ts=1507246572675;turbo=1;user-id=123456;user-type= :tmi.twitch.tv USERNOTICE #othertestchannel`,
65
- ),
66
- );
67
67
  }
68
68
 
69
69
  public disconnect() {
@@ -244,7 +244,8 @@ export class TwitchIRC {
244
244
  const [set_id, version] = badge.split('/');
245
245
  if (!set_id || !version) return [];
246
246
 
247
- const url = this.assets.badges[set_id]?.[version];
247
+ const url =
248
+ this.assets.badges[set_id]?.[version] ?? this.assets.badges[set_id]?.['*'];
248
249
  if (!url) return [];
249
250
 
250
251
  return {
@@ -255,7 +256,7 @@ export class TwitchIRC {
255
256
  }) ?? [],
256
257
  color: tags.color ?? '#FFFFFF',
257
258
  id: tags['user-id'],
258
- username: 'IDK',
259
+ username: (tags['display-name'] ?? 'Unknown').toLowerCase(),
259
260
  display_name: tags['display-name'] ?? 'Unknown',
260
261
  roles: {},
261
262
  },