buzzk 1.7.2 โ 1.8.1
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 +34 -0
- package/lib/chat.js +84 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,6 +17,12 @@
|
|
|
17
17
|
|
|
18
18
|
## ๐ ์
๋ฐ์ดํธ ๋ด์ญ
|
|
19
19
|
|
|
20
|
+
- onDonation ํจ์ ์ถ๊ฐ
|
|
21
|
+
|
|
22
|
+
- ๋ณธ์ธ ์ธ์ฆ ์ฑํ
์ง์ ์ถ๊ฐ
|
|
23
|
+
|
|
24
|
+
>
|
|
25
|
+
|
|
20
26
|
- ์ฑํ
๋ฐ์ดํฐ์ hasMod ํญ๋ชฉ ์ถ๊ฐ
|
|
21
27
|
|
|
22
28
|
>
|
|
@@ -310,6 +316,34 @@ dotenv์ ํจ๊ป ์ฌ์ฉํ๋ ๊ฒ์ ๋งค์ฐ ๊ถ์ฅํฉ๋๋ค.
|
|
|
310
316
|
- 3
|
|
311
317
|
- ...
|
|
312
318
|
|
|
319
|
+
</details>
|
|
320
|
+
|
|
321
|
+
chat.onDonation((data) => { //๋๋ค์ด์
์ด ์์ ๋
|
|
322
|
+
console.log(data);
|
|
323
|
+
|
|
324
|
+
for (let o in data) {
|
|
325
|
+
console.log(data[o].amount); //๋ฉ์ธ์ง๋ง ์ ๋ถ ๊บผ๋ด๊ธฐ
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
<details>
|
|
330
|
+
<summary>callback</summary>
|
|
331
|
+
|
|
332
|
+
- Return
|
|
333
|
+
- 0
|
|
334
|
+
- amount //ํ์ ๊ธ์ก
|
|
335
|
+
- author
|
|
336
|
+
- id
|
|
337
|
+
- name
|
|
338
|
+
- imageURL
|
|
339
|
+
- hasMod //๊ด๋ฆฌ ๊ถํ์ ๊ฐ์ก๋์ง (false / true)
|
|
340
|
+
- message
|
|
341
|
+
- time
|
|
342
|
+
- 1
|
|
343
|
+
- 2
|
|
344
|
+
- 3
|
|
345
|
+
- ...
|
|
346
|
+
|
|
313
347
|
</details>
|
|
314
348
|
|
|
315
349
|
chat.onDisconnect(() => { //์ฑํ
์ฐฝ ์ฐ๊ฒฐ์ด ๋๊ฒผ์ ๋
|
package/lib/chat.js
CHANGED
|
@@ -12,6 +12,7 @@ class chzzkChat {
|
|
|
12
12
|
#ws; //Chat Web Socket
|
|
13
13
|
#ssID; //kr-ss?.chat.naver.com/chat
|
|
14
14
|
#accTkn; //Account Access Token
|
|
15
|
+
#extTkn //for RealName Auth
|
|
15
16
|
#svcid; //game
|
|
16
17
|
#uid;
|
|
17
18
|
#sid;
|
|
@@ -44,6 +45,7 @@ class chzzkChat {
|
|
|
44
45
|
let accRes = await reqGame("nng_main/v1/chats/access-token?channelId=" + this.#chatID + "&chatType=STREAMING");
|
|
45
46
|
if (accRes.code != 200) return resolve(null);
|
|
46
47
|
this.#accTkn = accRes.content.accessToken;
|
|
48
|
+
this.#extTkn = accRes.content.extraToken;
|
|
47
49
|
//Get accTkn
|
|
48
50
|
|
|
49
51
|
//Load Balancing
|
|
@@ -138,7 +140,8 @@ class chzzkChat {
|
|
|
138
140
|
"chatType":"STREAMING",
|
|
139
141
|
"osType":"PC",
|
|
140
142
|
"streamingChannelId": this.channelID,
|
|
141
|
-
"emojis":""
|
|
143
|
+
"emojis":"",
|
|
144
|
+
"extraToken": this.#extTkn
|
|
142
145
|
}
|
|
143
146
|
|
|
144
147
|
//WS Send
|
|
@@ -193,7 +196,10 @@ class chzzkChat {
|
|
|
193
196
|
onMessage(callback) {
|
|
194
197
|
if (!this.#ws) return callback(null);
|
|
195
198
|
|
|
196
|
-
this.#callbacks[Object.keys(this.#callbacks).length] =
|
|
199
|
+
this.#callbacks[Object.keys(this.#callbacks).length] = {
|
|
200
|
+
type: "message",
|
|
201
|
+
callback: callback
|
|
202
|
+
};
|
|
197
203
|
this.#onMessageHandler(callback);
|
|
198
204
|
}
|
|
199
205
|
|
|
@@ -259,6 +265,80 @@ class chzzkChat {
|
|
|
259
265
|
});
|
|
260
266
|
}
|
|
261
267
|
|
|
268
|
+
onDonation(callback) {
|
|
269
|
+
if (!this.#ws) return callback(null);
|
|
270
|
+
|
|
271
|
+
this.#callbacks[Object.keys(this.#callbacks).length] = {
|
|
272
|
+
type: "donation",
|
|
273
|
+
callback: callback
|
|
274
|
+
};
|
|
275
|
+
this.#onDonationHandler(callback);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
#onDonationHandler (callback) {
|
|
279
|
+
if (!this.#ws) return callback(null);
|
|
280
|
+
|
|
281
|
+
this.#ws.on("message", async (data) => {
|
|
282
|
+
try {
|
|
283
|
+
data = await JSON.parse(data);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
catch (error) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (data.cmd == 93102) {
|
|
291
|
+
|
|
292
|
+
data = data.bdy;
|
|
293
|
+
let msgList = new Map();
|
|
294
|
+
|
|
295
|
+
for (let o in data) {
|
|
296
|
+
if (data[o].profile) {
|
|
297
|
+
try {
|
|
298
|
+
data[o].profile = await JSON.parse(data[o].profile);
|
|
299
|
+
data[o].extras = await JSON.parse(data[o].extras);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
catch (error) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
data[o].profile = {
|
|
308
|
+
nickname: null,
|
|
309
|
+
profileImageUrl: null,
|
|
310
|
+
userRoleCode: null
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
try {
|
|
315
|
+
let modVal = false;
|
|
316
|
+
if (data[o].profile.userRoleCode === "streamer" || data[o].profile.userRoleCode === "streaming_channel_manager" || data[o].profile.userRoleCode === "streaming_chat_manager") modVal = true;
|
|
317
|
+
|
|
318
|
+
msgList[Object.keys(msgList).length] = {
|
|
319
|
+
amount: data[o].extras.payAmount,
|
|
320
|
+
author: {
|
|
321
|
+
id: data[o].uid,
|
|
322
|
+
name: data[o].profile.nickname,
|
|
323
|
+
imageURL: data[o].profile.profileImageUrl,
|
|
324
|
+
hasMod: modVal
|
|
325
|
+
},
|
|
326
|
+
message: data[o].msg,
|
|
327
|
+
time: data[o].msgTime
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
catch(error) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
callback(msgList);
|
|
337
|
+
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
|
|
262
342
|
/**
|
|
263
343
|
* @param {function} callback
|
|
264
344
|
*/
|
|
@@ -406,7 +486,8 @@ class chzzkChat {
|
|
|
406
486
|
await this.disconnect();
|
|
407
487
|
await this.connect();
|
|
408
488
|
for (let o in this.#callbacks) {
|
|
409
|
-
this.#onMessageHandler(this.#callbacks[o]);
|
|
489
|
+
if (this.#callbacks[o].type === "message") this.#onMessageHandler(this.#callbacks[o].callback);
|
|
490
|
+
else if (this.#callbacks[o].type === "donation") this.#onDonationHandler(this.#callbacks[o].callback);
|
|
410
491
|
}
|
|
411
492
|
return;
|
|
412
493
|
//Reconnect
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "buzzk",
|
|
3
3
|
"displayName": "BUZZK",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.8.1",
|
|
5
5
|
"description": "๋ฟ์ง์ง (BUZZK) - ์น์ง์ง(CHZZK) ์ฑ๋ด์ ๋์ฑ ์ฝ๊ฒ ๊ฐ๋ฐํ ์ ์๋๋ก ๋๋ ๋น๊ณต์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ.",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"type": "commonjs",
|