dimsum-chat 0.4.7 → 0.5.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.
- package/dist/dimsum-chat.js +245 -96
- package/dist/dimsum-chat.umd.cjs +2 -2
- package/dist/dimsumMessage.d.ts +8 -1
- package/dist/index.d.ts +10 -0
- package/dist/parser.d.ts +149 -2
- package/dist/websocket.d.ts +96 -0
- package/package.json +49 -49
package/dist/dimsum-chat.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var T = Object.defineProperty;
|
|
2
|
-
var A = (
|
|
3
|
-
var
|
|
4
|
-
const
|
|
2
|
+
var A = (b, t, i) => t in b ? T(b, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : b[t] = i;
|
|
3
|
+
var a = (b, t, i) => (A(b, typeof t != "symbol" ? t + "" : t, i), i);
|
|
4
|
+
const k = {
|
|
5
5
|
type: "LIVE_OPEN_PLATFORM_DM",
|
|
6
6
|
content: {
|
|
7
7
|
cmd: "LIVE_OPEN_PLATFORM_DM",
|
|
@@ -14,7 +14,7 @@ const I = {
|
|
|
14
14
|
dm_type: 0
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
},
|
|
17
|
+
}, I = {
|
|
18
18
|
type: "LIVE_OPEN_PLATFORM_SEND_GIFT",
|
|
19
19
|
content: {
|
|
20
20
|
cmd: "LIVE_OPEN_PLATFORM_SEND_GIFT",
|
|
@@ -30,17 +30,17 @@ const I = {
|
|
|
30
30
|
gift_icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAB+FBMVEX/////UFD/TFD/TVD/TE7/TU//TU//TU//SUv/Skz/Sk3/S03/S07/TE3/TE7/TE//TU7/TU//TVD/Tk//TlD/T1D/T1H/UFH/UFL/UFP/UVL/UVP/UlP/UlT/U1T/U1X/VFX/VFb/VVb/VVf/Vlf/Vlj/V1j/V1n/WFn/WFr/WVr/WVv/Wlv/Wl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TKdy41e4jln77VqWQy6bZGEASlvPZtwCIo1BSTDpXxOfnlYu5ND7rMIbnWA+aj/BM2gUYdJwilJgYyJDKKtcS4IpKYsMu21cVZHPjq0GyveGQK6lcuxsbXwmShBvHFTR4d46rR5LY3PhKkCwrj6tmJ7sbnrJzVTi2N1bI1tUolM2NlXJt9wqo1bUNP7KZuKq11dXSr62NdeRlRdldDwMr2M7Lx7KzuRFINrdfIpbdoBQGzPZuIvEigRKJnZ2tlRr1/4Wmmz6Gx9JTAAAAAElFTkSuQmCC"
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
},
|
|
33
|
+
}, D = [k, I], f = class f {
|
|
34
34
|
constructor() {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
a(this, "AUTH_HOST", "https://dimsum-widget-auth-1301031323.cos.ap-guangzhou.myqcloud.com");
|
|
36
|
+
a(this, "WHITELIST_WIDGETS", ["dimsum-bonk-2024-widget", "douyin-bonk-2024-widget"]);
|
|
37
|
+
a(this, "MAX_RETRY_COUNT", 3);
|
|
38
|
+
a(this, "authenticatedPlatformAndRoomId");
|
|
39
|
+
a(this, "isPiracy", !1);
|
|
40
|
+
a(this, "retryCount", 0);
|
|
41
41
|
}
|
|
42
42
|
static getInstance() {
|
|
43
|
-
return
|
|
43
|
+
return f.instance || (f.instance = new f()), f.instance;
|
|
44
44
|
}
|
|
45
45
|
updateWidgetId(t) {
|
|
46
46
|
return t === "douyin-bonk-2024-widget" ? "dimsum-bonk-2024-widget" : t;
|
|
@@ -77,15 +77,15 @@ const I = {
|
|
|
77
77
|
this.checkAuthentication(n, s, e);
|
|
78
78
|
}
|
|
79
79
|
if (this.isPiracy)
|
|
80
|
-
return
|
|
80
|
+
return D[Math.floor(Math.random() * D.length)];
|
|
81
81
|
} catch (i) {
|
|
82
82
|
console.log("DimSumAuth error", i);
|
|
83
83
|
}
|
|
84
84
|
return t;
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
|
-
|
|
88
|
-
let
|
|
87
|
+
a(f, "instance");
|
|
88
|
+
let _ = f;
|
|
89
89
|
const B = {
|
|
90
90
|
type: "LIVE_OPEN_PLATFORM_DM",
|
|
91
91
|
content: {
|
|
@@ -108,7 +108,7 @@ const B = {
|
|
|
108
108
|
guard_level: 1
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
},
|
|
111
|
+
}, w = {
|
|
112
112
|
connected: B,
|
|
113
113
|
welcome: M
|
|
114
114
|
};
|
|
@@ -116,34 +116,57 @@ function E() {
|
|
|
116
116
|
const t = window.location.pathname.split("/");
|
|
117
117
|
return t.length > 1 ? t[1] : "unknown base name";
|
|
118
118
|
}
|
|
119
|
-
function L(
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
function L(b, t = {}) {
|
|
120
|
+
const { widgetNickName: i } = t;
|
|
121
|
+
let s;
|
|
122
|
+
switch (b.type) {
|
|
122
123
|
case "DimSumChatWidgetInfoRequest":
|
|
123
|
-
|
|
124
|
+
s = {
|
|
124
125
|
type: "DimSumChatWidgetInfoResponse",
|
|
125
126
|
content: {
|
|
126
127
|
base: E(),
|
|
127
|
-
url: window.location.href
|
|
128
|
+
url: window.location.href,
|
|
129
|
+
...i ? { widgetNickName: i } : {}
|
|
128
130
|
}
|
|
129
131
|
};
|
|
130
132
|
}
|
|
131
|
-
return
|
|
133
|
+
return s;
|
|
132
134
|
}
|
|
133
135
|
const x = class x {
|
|
134
136
|
constructor() {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
a(this, "webSocket");
|
|
138
|
+
a(this, "messageListeners");
|
|
139
|
+
/**
|
|
140
|
+
* Nickname for this widget instance.
|
|
141
|
+
* Set before connection (via onMessageOptions) or dynamically at runtime.
|
|
142
|
+
* When non-empty, it will be included in DimSumChatWidgetInfoResponse
|
|
143
|
+
* so other components can identify this widget via DimSumChatCallMessageRequest.
|
|
144
|
+
*/
|
|
145
|
+
a(this, "widgetNickName", "");
|
|
137
146
|
this.webSocket = null, this.messageListeners = [];
|
|
138
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* 获取唯一的 WebSocket 管理器实例。
|
|
150
|
+
*
|
|
151
|
+
* @returns WebSocketManager 单例
|
|
152
|
+
*/
|
|
139
153
|
static getInstance() {
|
|
140
154
|
return x.instance || (x.instance = new x()), x.instance;
|
|
141
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* 连接到指定 WebSocket 服务器。
|
|
158
|
+
*
|
|
159
|
+
* 仅可调用一次,重复调用将被忽略。
|
|
160
|
+
* 连接断开后自动每 3 秒尝试重连。
|
|
161
|
+
*
|
|
162
|
+
* @param url - WebSocket 服务器 URL
|
|
163
|
+
* @see {@link https://dimsum.chat/zh/api/websocket-manager.html#websocketmanager-connect}
|
|
164
|
+
*/
|
|
142
165
|
connect(t) {
|
|
143
166
|
this.webSocket || (this.webSocket = new WebSocket(t), this.webSocket.onmessage = this.handleMessage.bind(this), this.webSocket.onopen = () => {
|
|
144
167
|
console.log("connected"), setTimeout(() => {
|
|
145
168
|
this.messageListeners.forEach(
|
|
146
|
-
(i) => i(JSON.stringify(
|
|
169
|
+
(i) => i(JSON.stringify(w.connected))
|
|
147
170
|
);
|
|
148
171
|
}, 100);
|
|
149
172
|
}, this.webSocket.onclose = () => {
|
|
@@ -156,39 +179,56 @@ const x = class x {
|
|
|
156
179
|
var n;
|
|
157
180
|
const i = t.data;
|
|
158
181
|
this.messageListeners.forEach((p) => p(i));
|
|
159
|
-
const s = JSON.parse(i), e = L(s
|
|
182
|
+
const s = JSON.parse(i), e = L(s, {
|
|
183
|
+
widgetNickName: this.widgetNickName
|
|
184
|
+
});
|
|
160
185
|
e && ((n = this.webSocket) == null || n.send(JSON.stringify(e)));
|
|
161
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* 注册消息监听器。
|
|
189
|
+
*
|
|
190
|
+
* 收到 WebSocket 消息后以字符串形式传递给监听器。
|
|
191
|
+
* 添加监听器时若连接已建立,会自动推送一条欢迎消息。
|
|
192
|
+
*
|
|
193
|
+
* @param listener - 消息回调,接收原始 JSON 字符串
|
|
194
|
+
* @see {@link https://dimsum.chat/zh/api/websocket-manager.html#websocketmanager-addmessagelistener}
|
|
195
|
+
*/
|
|
162
196
|
addMessageListener(t) {
|
|
163
197
|
this.messageListeners.push(t), setTimeout(() => {
|
|
164
|
-
t(JSON.stringify(
|
|
198
|
+
t(JSON.stringify(w.welcome));
|
|
165
199
|
}, 100);
|
|
166
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* 移除已注册的消息监听器。
|
|
203
|
+
*
|
|
204
|
+
* @param listener - 之前通过 addMessageListener 注册的回调
|
|
205
|
+
*/
|
|
167
206
|
removeMessageListener(t) {
|
|
168
207
|
const i = this.messageListeners.indexOf(t);
|
|
169
208
|
i !== -1 && this.messageListeners.splice(i, 1);
|
|
170
209
|
}
|
|
171
210
|
};
|
|
172
|
-
|
|
173
|
-
let
|
|
211
|
+
a(x, "instance");
|
|
212
|
+
let z = x;
|
|
174
213
|
function S() {
|
|
175
|
-
const
|
|
214
|
+
const b = new URL(window.location.href), t = b.protocol === "https:" ? "wss:" : "ws:", i = b.host;
|
|
176
215
|
return `${t}//${i}/websocket`;
|
|
177
216
|
}
|
|
178
|
-
function
|
|
217
|
+
function P(b) {
|
|
179
218
|
const t = new URL(window.location.href), i = t.protocol, s = t.host;
|
|
180
|
-
return `${i}//${s}/bface/${
|
|
219
|
+
return `${i}//${s}/bface/${b}`;
|
|
181
220
|
}
|
|
182
|
-
function U(
|
|
221
|
+
function U(b, t = {}) {
|
|
183
222
|
const {
|
|
184
|
-
customWsServer: i = S()
|
|
185
|
-
|
|
186
|
-
e.
|
|
187
|
-
|
|
188
|
-
|
|
223
|
+
customWsServer: i = S(),
|
|
224
|
+
widgetNickName: s = ""
|
|
225
|
+
} = t, e = _.getInstance(), n = z.getInstance();
|
|
226
|
+
n.widgetNickName = s, n.connect(i), n.addMessageListener((p) => {
|
|
227
|
+
const h = JSON.parse(p), m = e.passMessage(h), o = new C(m);
|
|
228
|
+
b(m, o);
|
|
189
229
|
});
|
|
190
230
|
}
|
|
191
|
-
const
|
|
231
|
+
const l = [
|
|
192
232
|
["[过年牛]", "https://p3-pc-sign.douyinpic.com/obj/tos-cn-i-tsj2vxp0zn/3bb984085d52480ca846fa8f9a1782f6?x-expires=1949886000&x-signature=d8vUokaGkWD%2B4sAHNTLJquCrHrs%3D"],
|
|
193
233
|
["[元宝]", "https://p3-pc-sign.douyinpic.com/obj/tos-cn-i-tsj2vxp0zn/5f8ac1b1ddd347c4be34b81b496fcc45?x-expires=2023614000&x-signature=UT%2F8fnFld4xuvjj2bttu6fh76lI%3D"],
|
|
194
234
|
["[鞭炮]", "https://p3-pc-sign.douyinpic.com/obj/tos-cn-i-tsj2vxp0zn/02f8ee9536de4c6595171584e2322f0f?x-expires=2023614000&x-signature=Aa8eXgZqb0bx0QNeLONQVgNUbLI%3D"],
|
|
@@ -449,7 +489,7 @@ const C = [
|
|
|
449
489
|
["[糖葫芦]", "https://p3-pc-sign.douyinpic.com/obj/tos-cn-i-tsj2vxp0zn/d4aa8a0ff46a445e861ad8fb78c07140?x-expires=2023614000&x-signature=FvN4ytTGjC7Mww8KX4BRIg9wcTE%3D"],
|
|
450
490
|
["[虎头]", "https://p3-pc-sign.douyinpic.com/obj/tos-cn-i-tsj2vxp0zn/7569ffeaa3894b8b8ea843c0e5a05f63?x-expires=2023614000&x-signature=m%2Bi3d034xBQkuBqx4xrvzru5q6A%3D"],
|
|
451
491
|
["[iloveyou]", "https://p3-pc-sign.douyinpic.com/obj/tos-cn-i-tsj2vxp0zn/798bcfd9811f4fcd97df92af06c87a0e?x-expires=2023614000&x-signature=DuK8xhX7glgLx44H53PrhM32D44%3D"]
|
|
452
|
-
],
|
|
492
|
+
], j = [
|
|
453
493
|
["[dog]", "http://i0.hdslb.com/bfs/live/4428c84e694fbf4e0ef6c06e958d9352c3582740.png"],
|
|
454
494
|
["[花]", "http://i0.hdslb.com/bfs/live/7dd2ef03e13998575e4d8a803c6e12909f94e72b.png"],
|
|
455
495
|
["[妙]", "http://i0.hdslb.com/bfs/live/08f735d950a0fba267dda140673c9ab2edf6410d.png"],
|
|
@@ -532,7 +572,7 @@ const C = [
|
|
|
532
572
|
["[抱拳]", "http://i0.hdslb.com/bfs/live/3f170894dd08827ee293afcb5a3d2b60aecdb5b1.png"],
|
|
533
573
|
["[给力]", "http://i0.hdslb.com/bfs/live/d1ba5f4c54332a21ed2ca0dcecaedd2add587839.png"],
|
|
534
574
|
["[耶]", "http://i0.hdslb.com/bfs/live/eb2d84ba623e2335a48f73fb5bef87bcf53c1239.png"]
|
|
535
|
-
],
|
|
575
|
+
], v = [
|
|
536
576
|
["[666]", "https://ali2.a.yximgs.com/bs2/emotion/1704763447505third_party_s1296657489.png"],
|
|
537
577
|
["[奸笑]", "https://ali2.a.yximgs.com/bs2/emotion/1704776059816third_party_s1296748052.png"],
|
|
538
578
|
["[捂脸]", "https://bd.a.yximgs.com/bs2/emotion/1704776021202third_party_s1296747457.png"],
|
|
@@ -740,11 +780,13 @@ const C = [
|
|
|
740
780
|
["[抱拳]", "https://bd.a.yximgs.com/bs2/emotion/1704790113221third_party_s1296853443.png"],
|
|
741
781
|
["[早上好]", "https://ali2.a.yximgs.com/bs2/emotion/1704790167344third_party_s1296853922.png"],
|
|
742
782
|
["[胡思乱想]", "https://ali2.a.yximgs.com/bs2/emotion/1704790657229third_party_s1296858542.png"]
|
|
743
|
-
],
|
|
783
|
+
], r = class r {
|
|
744
784
|
constructor(t) {
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
785
|
+
/** 原始消息类型。 */
|
|
786
|
+
a(this, "rawType");
|
|
787
|
+
/** 原始消息内容(字符串已自动反序列化为对象)。 */
|
|
788
|
+
a(this, "rawContent");
|
|
789
|
+
a(this, "_cachedValues", {});
|
|
748
790
|
this.rawType = t.type;
|
|
749
791
|
try {
|
|
750
792
|
typeof t.content == "string" ? this.rawContent = JSON.parse(t.content) : this.rawContent = t.content;
|
|
@@ -916,6 +958,7 @@ const C = [
|
|
|
916
958
|
if (this.platform === "chzzk" && "uid" in this.rawContent)
|
|
917
959
|
return this.rawContent.uid;
|
|
918
960
|
}
|
|
961
|
+
/** 粉丝团/守护团等级。 */
|
|
919
962
|
get clubLevel() {
|
|
920
963
|
if (this.platform === "bilibili" || this.platform === "openblive") {
|
|
921
964
|
if (this.rawType === "DANMU_MSG")
|
|
@@ -937,6 +980,7 @@ const C = [
|
|
|
937
980
|
if (this.platform === "douyin" && "user" in this.rawContent && this.rawContent.user.fansClub !== null)
|
|
938
981
|
return this.rawContent.user.fansClub.data.level;
|
|
939
982
|
}
|
|
983
|
+
/** 粉丝团/守护团名称。 */
|
|
940
984
|
get clubName() {
|
|
941
985
|
var t, i;
|
|
942
986
|
if (this.platform === "bilibili" || this.platform === "openblive") {
|
|
@@ -959,6 +1003,7 @@ const C = [
|
|
|
959
1003
|
if (this.platform === "douyin" && "user" in this.rawContent)
|
|
960
1004
|
return (i = (t = this.rawContent.user.fansClub) == null ? void 0 : t.data) == null ? void 0 : i.clubName;
|
|
961
1005
|
}
|
|
1006
|
+
/** AcFun 守护团所属主播的用户 ID。 */
|
|
962
1007
|
get acfunClubUid() {
|
|
963
1008
|
if (this.platform === "acfun") {
|
|
964
1009
|
let t;
|
|
@@ -978,6 +1023,13 @@ const C = [
|
|
|
978
1023
|
return "6" in t && t[6].uri.includes("subscribe_year") || "5" in t && t[5].uri.includes("subscribe_year") ? 2 : "3" in t || "5" in t ? 1 : 0;
|
|
979
1024
|
}
|
|
980
1025
|
}
|
|
1026
|
+
/**
|
|
1027
|
+
* 用户头像 URL。
|
|
1028
|
+
*
|
|
1029
|
+
* B 站头像存在跨域限制,建议配合 getBfaceURL() 使用。
|
|
1030
|
+
*
|
|
1031
|
+
* @see {@link https://dimsum.chat/zh/api/parser.html#parser-avatar}
|
|
1032
|
+
*/
|
|
981
1033
|
get avatar() {
|
|
982
1034
|
var t, i;
|
|
983
1035
|
if ((this.platform === "bilibili" || this.platform === "openblive") && "data" in this.rawContent) {
|
|
@@ -1005,6 +1057,13 @@ const C = [
|
|
|
1005
1057
|
if (this.platform === "kuaishou" && "user" in this.rawContent && "headUrl" in this.rawContent.user && this.rawContent.user.headUrl)
|
|
1006
1058
|
return this.rawContent.user.headUrl;
|
|
1007
1059
|
}
|
|
1060
|
+
/**
|
|
1061
|
+
* 弹幕聊天内容。
|
|
1062
|
+
*
|
|
1063
|
+
* 当 type 为 comment 或 superchat 时均有值。
|
|
1064
|
+
*
|
|
1065
|
+
* @see {@link https://dimsum.chat/zh/api/parser.html#parser-comment}
|
|
1066
|
+
*/
|
|
1008
1067
|
get comment() {
|
|
1009
1068
|
const t = {
|
|
1010
1069
|
acfun: () => this.rawContent.content,
|
|
@@ -1030,16 +1089,16 @@ const C = [
|
|
|
1030
1089
|
emotStyle: e = "",
|
|
1031
1090
|
emotClass: n = "",
|
|
1032
1091
|
acfunCustomStickers: p = [],
|
|
1033
|
-
acfunCustomHtmlBuilder:
|
|
1034
|
-
} = t,
|
|
1092
|
+
acfunCustomHtmlBuilder: h
|
|
1093
|
+
} = t, m = {
|
|
1035
1094
|
acfun: () => {
|
|
1036
1095
|
let o = g(this.rawContent.content);
|
|
1037
1096
|
if ("emotionUrl" in this.rawContent && this.rawContent.emotionUrl)
|
|
1038
1097
|
return `<img src="${this.rawContent.emotionUrl}" alt="" style="${i}" class="${s}">`;
|
|
1039
1098
|
let c;
|
|
1040
|
-
return p.forEach((
|
|
1041
|
-
o.includes(
|
|
1042
|
-
}), c != null ?
|
|
1099
|
+
return p.forEach((d) => {
|
|
1100
|
+
o.includes(d.keyWord) && (c = d.path);
|
|
1101
|
+
}), c != null ? h != null ? h(c, o) : `<div style="display:flex;">
|
|
1043
1102
|
<img src="${c}" alt="" style="${i}" class="${s}">
|
|
1044
1103
|
<div style="flex-grow:1;">${o}</div>
|
|
1045
1104
|
</div>` : g(this.rawContent.content);
|
|
@@ -1048,51 +1107,51 @@ const C = [
|
|
|
1048
1107
|
if (typeof this.rawContent.info[0][13] == "object")
|
|
1049
1108
|
return `<img src="${this.rawContent.info[0][13].url}" alt="" style="${i}" class="${s}">`;
|
|
1050
1109
|
const o = this.rawContent.info[0][15].extra, c = JSON.parse(o);
|
|
1051
|
-
let
|
|
1110
|
+
let d = g(c.content);
|
|
1052
1111
|
const u = c.emots;
|
|
1053
1112
|
for (let y in u) {
|
|
1054
1113
|
const F = new RegExp(`\\${y}`, "g");
|
|
1055
|
-
|
|
1114
|
+
d = d.replace(F, `<img src="${u[y].url}" alt="" style="${e}" class="${n}">`);
|
|
1056
1115
|
}
|
|
1057
|
-
return
|
|
1116
|
+
return d;
|
|
1058
1117
|
},
|
|
1059
1118
|
openblive: () => {
|
|
1060
1119
|
if (this.rawContent.data.emoji_img_url)
|
|
1061
1120
|
return `<img src="${this.rawContent.data.emoji_img_url}" alt="" style="${i}" class="${s}">`;
|
|
1062
1121
|
let o = g(this.rawContent.data.msg);
|
|
1063
|
-
return
|
|
1064
|
-
const
|
|
1065
|
-
o = o.replace(
|
|
1122
|
+
return j.forEach((c) => {
|
|
1123
|
+
const d = new RegExp(`\\${c[0]}`, "g");
|
|
1124
|
+
o = o.replace(d, `<img src="${c[1]}" alt="" style="${e}" class="${n}">`);
|
|
1066
1125
|
}), o;
|
|
1067
1126
|
},
|
|
1068
1127
|
douyin: () => {
|
|
1069
1128
|
let o = g(this.rawContent.content);
|
|
1070
|
-
return
|
|
1071
|
-
const
|
|
1072
|
-
o = o.replace(
|
|
1129
|
+
return l.forEach((c) => {
|
|
1130
|
+
const d = new RegExp(`\\${c[0]}`, "g");
|
|
1131
|
+
o = o.replace(d, `<img src="${c[1]}" alt="" style="${e}" class="${n}">`);
|
|
1073
1132
|
}), o;
|
|
1074
1133
|
},
|
|
1075
1134
|
kuaishou: () => {
|
|
1076
1135
|
let o = g(this.rawContent.content);
|
|
1077
|
-
return
|
|
1078
|
-
const
|
|
1079
|
-
o = o.replace(
|
|
1136
|
+
return v.forEach((c) => {
|
|
1137
|
+
const d = new RegExp(`\\${c[0]}`, "g");
|
|
1138
|
+
o = o.replace(d, `<img src="${c[1]}" alt="" style="${e}" class="${n}">`);
|
|
1080
1139
|
}), o;
|
|
1081
1140
|
},
|
|
1082
1141
|
chzzk: () => {
|
|
1083
1142
|
let o = g(this.rawContent.msg);
|
|
1084
1143
|
if (this.rawContent.extras) {
|
|
1085
|
-
const
|
|
1086
|
-
for (let u in
|
|
1144
|
+
const d = JSON.parse(this.rawContent.extras).emojis || {};
|
|
1145
|
+
for (let u in d) {
|
|
1087
1146
|
const y = new RegExp(`\\{:${u}:}`, "g");
|
|
1088
|
-
o = o.replace(y, `<img src="${
|
|
1147
|
+
o = o.replace(y, `<img src="${d[u]}" alt="" style="${e}" class="${n}">`);
|
|
1089
1148
|
}
|
|
1090
1149
|
return o;
|
|
1091
1150
|
}
|
|
1092
1151
|
}
|
|
1093
1152
|
};
|
|
1094
|
-
if (this.type === "comment" &&
|
|
1095
|
-
return
|
|
1153
|
+
if (this.type === "comment" && m[this.platform])
|
|
1154
|
+
return m[this.platform]();
|
|
1096
1155
|
}
|
|
1097
1156
|
/**
|
|
1098
1157
|
* Custom comment content builder.
|
|
@@ -1110,31 +1169,31 @@ const C = [
|
|
|
1110
1169
|
bilibili: () => {
|
|
1111
1170
|
let s, e = [];
|
|
1112
1171
|
typeof this.rawContent.info[0][13] == "object" && (s = this.rawContent.info[0][13].url);
|
|
1113
|
-
const n = this.rawContent.info[0][15].extra, p = JSON.parse(n),
|
|
1114
|
-
for (let o in
|
|
1115
|
-
e.push([o,
|
|
1116
|
-
return t(
|
|
1172
|
+
const n = this.rawContent.info[0][15].extra, p = JSON.parse(n), h = g(p.content), m = p.emots;
|
|
1173
|
+
for (let o in m)
|
|
1174
|
+
e.push([o, m[o].url]);
|
|
1175
|
+
return t(h, s, e);
|
|
1117
1176
|
},
|
|
1118
1177
|
openblive: () => {
|
|
1119
1178
|
let s;
|
|
1120
1179
|
this.rawContent.data.emoji_img_url && (s = this.rawContent.data.emoji_img_url);
|
|
1121
1180
|
const e = g(this.rawContent.data.msg);
|
|
1122
|
-
return t(e, s,
|
|
1181
|
+
return t(e, s, j);
|
|
1123
1182
|
},
|
|
1124
1183
|
douyin: () => {
|
|
1125
1184
|
const s = g(this.rawContent.content);
|
|
1126
|
-
return t(s, void 0,
|
|
1185
|
+
return t(s, void 0, l);
|
|
1127
1186
|
},
|
|
1128
1187
|
kuaishou: () => {
|
|
1129
1188
|
const s = g(this.rawContent.content);
|
|
1130
|
-
return t(s, void 0,
|
|
1189
|
+
return t(s, void 0, v);
|
|
1131
1190
|
},
|
|
1132
1191
|
chzzk: () => {
|
|
1133
1192
|
let s = g(this.rawContent.msg), e = [];
|
|
1134
1193
|
if (this.rawContent.extras) {
|
|
1135
1194
|
const p = JSON.parse(this.rawContent.extras).emojis || {};
|
|
1136
|
-
for (let
|
|
1137
|
-
e.push([`{:${
|
|
1195
|
+
for (let h in p)
|
|
1196
|
+
e.push([`{:${h}:}`, p[h]]);
|
|
1138
1197
|
}
|
|
1139
1198
|
return t(s, void 0, e);
|
|
1140
1199
|
}
|
|
@@ -1143,8 +1202,14 @@ const C = [
|
|
|
1143
1202
|
return i[this.platform]();
|
|
1144
1203
|
}
|
|
1145
1204
|
/**
|
|
1146
|
-
*
|
|
1147
|
-
*
|
|
1205
|
+
* 大航海等级。
|
|
1206
|
+
*
|
|
1207
|
+
* 0=无,3=舰长,2=提督,1=总督。
|
|
1208
|
+
* 当 type 为 guard 时,表示本次购买的大航海等级;
|
|
1209
|
+
* 其他消息类型中表示该用户当前的大航海等级。
|
|
1210
|
+
* Chzzk 平台的 Subscription 事件也支持此属性。
|
|
1211
|
+
*
|
|
1212
|
+
* @see {@link https://dimsum.chat/zh/api/parser.html#parser-guardlevel}
|
|
1148
1213
|
*/
|
|
1149
1214
|
get guardLevel() {
|
|
1150
1215
|
if (this.platform === "bilibili" || this.platform === "openblive") {
|
|
@@ -1162,6 +1227,13 @@ const C = [
|
|
|
1162
1227
|
return t && t <= 3 && t >= 1 ? 4 - t : 0;
|
|
1163
1228
|
}
|
|
1164
1229
|
}
|
|
1230
|
+
/**
|
|
1231
|
+
* 大航海购买数量。
|
|
1232
|
+
*
|
|
1233
|
+
* B 站表示购买月数,Chzzk 表示订阅月数。
|
|
1234
|
+
*
|
|
1235
|
+
* @see {@link https://dimsum.chat/zh/api/parser.html#parser-guardnum}
|
|
1236
|
+
*/
|
|
1165
1237
|
get guardNum() {
|
|
1166
1238
|
if (this.platform === "bilibili" || this.platform === "openblive") {
|
|
1167
1239
|
if (this.rawType === "GUARD_BUY")
|
|
@@ -1172,19 +1244,27 @@ const C = [
|
|
|
1172
1244
|
if (this.platform === "chzzk")
|
|
1173
1245
|
return this.chzzkTierMonth;
|
|
1174
1246
|
}
|
|
1247
|
+
/**
|
|
1248
|
+
* 大航海购买价格(CNY)。
|
|
1249
|
+
*
|
|
1250
|
+
* @see {@link https://dimsum.chat/zh/api/parser.html#parser-guardprice}
|
|
1251
|
+
*/
|
|
1175
1252
|
// 可能是单价(未确认),舰长价格198实际可能为138
|
|
1176
1253
|
get guardPrice() {
|
|
1177
1254
|
if ((this.platform === "bilibili" || this.platform === "openblive") && "data" in this.rawContent && "price" in this.rawContent.data)
|
|
1178
1255
|
return this.rawContent.data.price / 1e3;
|
|
1179
1256
|
}
|
|
1257
|
+
/** Chzzk 订阅等级(1-3)。 */
|
|
1180
1258
|
get chzzkTier() {
|
|
1181
1259
|
if (this.platform === "chzzk" && this.rawType === "ChzzkSubscriptionMessage" && this.rawContent.extras)
|
|
1182
1260
|
return JSON.parse(this.rawContent.extras).tierNo;
|
|
1183
1261
|
}
|
|
1262
|
+
/** Chzzk 订阅月数。 */
|
|
1184
1263
|
get chzzkTierMonth() {
|
|
1185
1264
|
if (this.platform === "chzzk" && this.rawType === "ChzzkSubscriptionMessage" && this.rawContent.extras)
|
|
1186
1265
|
return JSON.parse(this.rawContent.extras).month;
|
|
1187
1266
|
}
|
|
1267
|
+
/** 礼物名称。 */
|
|
1188
1268
|
get giftName() {
|
|
1189
1269
|
const t = {
|
|
1190
1270
|
acfun: () => this.rawContent.giftInfo.name,
|
|
@@ -1196,6 +1276,13 @@ const C = [
|
|
|
1196
1276
|
if (this.type === "gift" && t[this.platform])
|
|
1197
1277
|
return t[this.platform]();
|
|
1198
1278
|
}
|
|
1279
|
+
/**
|
|
1280
|
+
* 礼物数量。
|
|
1281
|
+
*
|
|
1282
|
+
* 抖音和快手已由 SDK 内部处理连击去重,每次返回增量值。
|
|
1283
|
+
*
|
|
1284
|
+
* @see {@link https://dimsum.chat/zh/api/parser.html#parser-giftnum}
|
|
1285
|
+
*/
|
|
1199
1286
|
get giftNum() {
|
|
1200
1287
|
const t = {
|
|
1201
1288
|
acfun: () => this.rawContent.gift.batchSize,
|
|
@@ -1203,21 +1290,28 @@ const C = [
|
|
|
1203
1290
|
openblive: () => this.rawContent.data.gift_num,
|
|
1204
1291
|
douyin: () => {
|
|
1205
1292
|
if (this.rawContent.sendType === 4) {
|
|
1206
|
-
const s = this.rawContent.comboCount, e = this.rawContent.groupId, n = this.rawContent.giftId, p = this.uid,
|
|
1207
|
-
let
|
|
1208
|
-
return
|
|
1293
|
+
const s = this.rawContent.comboCount, e = this.rawContent.groupId, n = this.rawContent.giftId, p = this.uid, h = `${e}_${p}_${n}`;
|
|
1294
|
+
let m = 0;
|
|
1295
|
+
return r.douyinGiftGroup.has(h) && (m = r.douyinGiftGroup.get(h) ?? 0), r.douyinGiftGroup.set(h, s), r.douyinGiftGroup.size > 1024 && r.douyinGiftGroup.delete(r.douyinGiftGroup.keys().next().value ?? ""), s - m;
|
|
1209
1296
|
}
|
|
1210
1297
|
return this.rawContent.groupCount;
|
|
1211
1298
|
},
|
|
1212
1299
|
kuaishou: () => {
|
|
1213
1300
|
const s = this.rawContent.batchSize * this.rawContent.comboCount, e = this.rawContent.mergeKey;
|
|
1214
1301
|
let n = 0;
|
|
1215
|
-
return
|
|
1302
|
+
return r.kuaishouGiftGroup.has(e) && (n = r.kuaishouGiftGroup.get(e) ?? 0), r.kuaishouGiftGroup.set(e, s), r.kuaishouGiftGroup.size > 1024 && r.kuaishouGiftGroup.delete(r.kuaishouGiftGroup.keys().next().value ?? ""), s - n;
|
|
1216
1303
|
}
|
|
1217
1304
|
};
|
|
1218
1305
|
if (this.type === "gift" && t[this.platform])
|
|
1219
1306
|
return t[this.platform]();
|
|
1220
1307
|
}
|
|
1308
|
+
/**
|
|
1309
|
+
* 单个礼物价格(CNY)。
|
|
1310
|
+
*
|
|
1311
|
+
* 免费礼物(如 B 站银瓜子)返回 0。
|
|
1312
|
+
*
|
|
1313
|
+
* @see {@link https://dimsum.chat/zh/api/parser.html#parser-giftunitprice}
|
|
1314
|
+
*/
|
|
1221
1315
|
get giftUnitPrice() {
|
|
1222
1316
|
const t = {
|
|
1223
1317
|
acfun: () => this.rawContent.gift.giftId !== 1 ? this.rawContent.giftInfo.value / 10 : 0,
|
|
@@ -1229,10 +1323,18 @@ const C = [
|
|
|
1229
1323
|
if (this.type === "gift" && t[this.platform])
|
|
1230
1324
|
return t[this.platform]();
|
|
1231
1325
|
}
|
|
1326
|
+
/**
|
|
1327
|
+
* 礼物总价值(CNY)。
|
|
1328
|
+
*
|
|
1329
|
+
* 等价于 giftNum × giftUnitPrice。
|
|
1330
|
+
*
|
|
1331
|
+
* @see {@link https://dimsum.chat/zh/api/parser.html#parser-gifttotalprice}
|
|
1332
|
+
*/
|
|
1232
1333
|
get giftTotalPrice() {
|
|
1233
1334
|
if (this.giftNum !== void 0 && this.giftUnitPrice !== void 0)
|
|
1234
1335
|
return this.giftNum * this.giftUnitPrice;
|
|
1235
1336
|
}
|
|
1337
|
+
/** 礼物图片 URL。 */
|
|
1236
1338
|
get giftImage() {
|
|
1237
1339
|
return this.type !== "gift" ? void 0 : {
|
|
1238
1340
|
acfun: () => this.rawContent.giftInfo.pic,
|
|
@@ -1246,6 +1348,7 @@ const C = [
|
|
|
1246
1348
|
kuaishou: () => this.rawContent.giftInfo.picUrl[0].url
|
|
1247
1349
|
}[this.platform]();
|
|
1248
1350
|
}
|
|
1351
|
+
/** 超级聊天评论内容。 */
|
|
1249
1352
|
get superChatComment() {
|
|
1250
1353
|
const t = {
|
|
1251
1354
|
bilibili: () => this.rawContent.data.message,
|
|
@@ -1255,6 +1358,13 @@ const C = [
|
|
|
1255
1358
|
if (this.type === "superchat" && t[this.platform])
|
|
1256
1359
|
return t[this.platform]();
|
|
1257
1360
|
}
|
|
1361
|
+
/**
|
|
1362
|
+
* 超级聊天价格。
|
|
1363
|
+
*
|
|
1364
|
+
* B 站与 OpenBLive 为人民币(元),Chzzk 为韩元(KRW)。
|
|
1365
|
+
*
|
|
1366
|
+
* @see {@link https://dimsum.chat/zh/api/parser.html#parser-superchatprice}
|
|
1367
|
+
*/
|
|
1258
1368
|
get superChatPrice() {
|
|
1259
1369
|
const t = {
|
|
1260
1370
|
bilibili: () => this.rawContent.data.price,
|
|
@@ -1267,6 +1377,18 @@ const C = [
|
|
|
1267
1377
|
if (this.type === "superchat" && t[this.platform])
|
|
1268
1378
|
return t[this.platform]();
|
|
1269
1379
|
}
|
|
1380
|
+
/**
|
|
1381
|
+
* 广义价格,根据消息类型自动选择对应价格属性:
|
|
1382
|
+
*
|
|
1383
|
+
* | 消息类型 | 对应属性 |
|
|
1384
|
+
* |-----------|-----------------|
|
|
1385
|
+
* | gift | giftTotalPrice |
|
|
1386
|
+
* | superchat | superChatPrice |
|
|
1387
|
+
* | guard | guardPrice |
|
|
1388
|
+
* | 其它 | undefined |
|
|
1389
|
+
*
|
|
1390
|
+
* @see {@link https://dimsum.chat/zh/api/parser.html#parser-price}
|
|
1391
|
+
*/
|
|
1270
1392
|
get price() {
|
|
1271
1393
|
if (this.type === "gift")
|
|
1272
1394
|
return this.giftTotalPrice;
|
|
@@ -1275,6 +1397,15 @@ const C = [
|
|
|
1275
1397
|
if (this.type === "guard")
|
|
1276
1398
|
return this.guardPrice;
|
|
1277
1399
|
}
|
|
1400
|
+
/**
|
|
1401
|
+
* 获取用户的抽象化分级,用于渲染用户等级标识。
|
|
1402
|
+
*
|
|
1403
|
+
* 不同平台的映射规则见官网文档。
|
|
1404
|
+
*
|
|
1405
|
+
* @param options - 各平台分段阈值配置,见 {@link abstractLevelOptions}
|
|
1406
|
+
* @returns 0-3 等级,undefined 表示不支持
|
|
1407
|
+
* @see {@link https://dimsum.chat/zh/api/parser.html#parser-getabstractlevel}
|
|
1408
|
+
*/
|
|
1278
1409
|
getAbstractLevel(t = {}) {
|
|
1279
1410
|
const {
|
|
1280
1411
|
douyinSteps: i = [7, 11, 15],
|
|
@@ -1284,25 +1415,43 @@ const C = [
|
|
|
1284
1415
|
} = t, p = (o) => {
|
|
1285
1416
|
if (this.clubLevel === void 0)
|
|
1286
1417
|
return 0;
|
|
1287
|
-
const c = o.findIndex((
|
|
1418
|
+
const c = o.findIndex((d) => this.clubLevel <= d);
|
|
1288
1419
|
return c !== -1 ? c : o.length;
|
|
1289
|
-
},
|
|
1420
|
+
}, h = () => this.guardLevel && this.guardLevel > 0 ? 4 - this.guardLevel : 0, m = {
|
|
1290
1421
|
douyin: () => p(i),
|
|
1291
1422
|
kuaishou: () => p(s),
|
|
1292
1423
|
acfun: () => n > 0 && this.acfunClubUid !== n ? 0 : p(e),
|
|
1293
|
-
bilibili: () =>
|
|
1294
|
-
openblive: () =>
|
|
1424
|
+
bilibili: () => h(),
|
|
1425
|
+
openblive: () => h(),
|
|
1295
1426
|
chzzk: () => this.chzzkTier ?? 0
|
|
1296
1427
|
};
|
|
1297
|
-
if (
|
|
1298
|
-
return
|
|
1428
|
+
if (m[this.platform])
|
|
1429
|
+
return m[this.platform]();
|
|
1299
1430
|
}
|
|
1300
1431
|
};
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1432
|
+
/**
|
|
1433
|
+
* Douyin emoji mappings. Accessible directly without going through CommentBuilder.
|
|
1434
|
+
*
|
|
1435
|
+
* @example
|
|
1436
|
+
* Parser.DouyinEmots.forEach(([emot, url]) => console.log(emot, url));
|
|
1437
|
+
*/
|
|
1438
|
+
a(r, "DouyinEmots", l), /**
|
|
1439
|
+
* Bilibili emoji mappings (also used by OpenBLive).
|
|
1440
|
+
*
|
|
1441
|
+
* @example
|
|
1442
|
+
* Parser.BilibiliEmots.forEach(([emot, url]) => console.log(emot, url));
|
|
1443
|
+
*/
|
|
1444
|
+
a(r, "BilibiliEmots", j), /**
|
|
1445
|
+
* Kuaishou emoji mappings.
|
|
1446
|
+
*
|
|
1447
|
+
* @example
|
|
1448
|
+
* Parser.KuaishouEmots.forEach(([emot, url]) => console.log(emot, url));
|
|
1449
|
+
*/
|
|
1450
|
+
a(r, "KuaishouEmots", v), // groupId_userId_giftId : comboCount
|
|
1451
|
+
a(r, "douyinGiftGroup", /* @__PURE__ */ new Map()), a(r, "kuaishouGiftGroup", /* @__PURE__ */ new Map());
|
|
1452
|
+
let C = r;
|
|
1453
|
+
function g(b) {
|
|
1454
|
+
return b.replace(/[&<>"']/g, function(t) {
|
|
1306
1455
|
switch (t) {
|
|
1307
1456
|
case "&":
|
|
1308
1457
|
return "&";
|
|
@@ -1320,9 +1469,9 @@ function g(r) {
|
|
|
1320
1469
|
});
|
|
1321
1470
|
}
|
|
1322
1471
|
export {
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1472
|
+
C as Parser,
|
|
1473
|
+
z as WebSocketManager,
|
|
1474
|
+
P as getBfaceURL,
|
|
1326
1475
|
S as getWebSocketURL,
|
|
1327
1476
|
U as onMessage
|
|
1328
1477
|
};
|