fishpi 0.0.28 → 0.0.30

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
@@ -59,11 +59,11 @@ await fish.chatroom.redpacket.send({
59
59
  // 私聊历史获取
60
60
  let chatHistory = await fish.chat.get({ user: 'username', autoRead: false })
61
61
  // 监听私聊新消息
62
- fishpi.chat.addListener(({ msg: any }) => {
62
+ fishpi.chat.addListener(async ({ msg }: { msg: NoticeMsg }) => {
63
63
  switch (msg.command) {
64
64
  // 私聊未读数更新
65
65
  case 'chatUnreadCountRefresh':
66
- if(msg.count > 0) {
66
+ if(msg.count! > 0) {
67
67
  let unreadMsgs = await fishpi.chat.unread();
68
68
  }
69
69
  else this.users.forEach((u, i) => {
@@ -73,7 +73,7 @@ fishpi.chat.addListener(({ msg: any }) => {
73
73
  // 新私聊消息
74
74
  case 'newIdleChatMessage':
75
75
  // msg 就是新的私聊消息
76
- console.log(msg.senderUserName, '说:', notice.preview);
76
+ console.log(msg.senderUserName, '说:', msg.preview);
77
77
  break;
78
78
  // 有新的消息通知
79
79
  case 'refreshNotification':
@@ -82,7 +82,7 @@ fishpi.chat.addListener(({ msg: any }) => {
82
82
  }
83
83
  });
84
84
  // 监听指定用户的私聊消息
85
- fishpi.chat.addListener(({ msg: ChatData }) => {
85
+ fishpi.chat.addListener(({ msg }: { msg: ChatData }) => {
86
86
  console.log(msg.senderUserName, '[', msg.time, ']:', msg.content);
87
87
  }, 'username');
88
88
  // 给指定用户发私聊消息
package/lib/chatroom.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ApiResponse, ChatContentType, ChatMessageType, ChatRoomMessage, GestureType, Message, MuteItem, RedPacket, RedPacketInfo } from './typing';
1
+ import { ApiResponse, ChatContentType, ChatMessageType, ClientType, ChatRoomMessage, GestureType, Message, MuteItem, RedPacket, RedPacketInfo } from './typing';
2
2
  declare class ChatRoom {
3
3
  private _apiKey;
4
4
  private _discusse;
@@ -44,7 +44,7 @@ declare class ChatRoom {
44
44
  * 发送一条消息
45
45
  * @param msg 消息内容,支持 Markdown
46
46
  */
47
- send(msg: string): Promise<ApiResponse<undefined>>;
47
+ send(msg: string, clientType?: ClientType | string, version?: string): Promise<ApiResponse<undefined>>;
48
48
  /**
49
49
  * 发送一条弹幕
50
50
  * @param msg 消息内容,支持 Markdown
package/lib/chatroom.js CHANGED
@@ -133,6 +133,7 @@ var ChatRoom = /** @class */ (function () {
133
133
  return [2 /*return*/, rsp_1];
134
134
  rsp_1.data.forEach(function (d, i, data) {
135
135
  try {
136
+ data[i].via = (0, utils_1.clientToVia)(data[i].client);
136
137
  data[i].sysMetal = (0, utils_1.toMetal)(data[i].sysMetal);
137
138
  redpacket_1 = JSON.parse(d.content);
138
139
  if (redpacket_1.msgType !== 'redPacket')
@@ -171,6 +172,7 @@ var ChatRoom = /** @class */ (function () {
171
172
  return [2 /*return*/, rsp_2];
172
173
  rsp_2.data.forEach(function (d, i, data) {
173
174
  try {
175
+ data[i].via = (0, utils_1.clientToVia)(data[i].client);
174
176
  data[i].sysMetal = (0, utils_1.toMetal)(data[i].sysMetal);
175
177
  redpacket_2 = JSON.parse(d.content);
176
178
  if (redpacket_2.msgType !== 'redPacket')
@@ -223,7 +225,9 @@ var ChatRoom = /** @class */ (function () {
223
225
  * 发送一条消息
224
226
  * @param msg 消息内容,支持 Markdown
225
227
  */
226
- ChatRoom.prototype.send = function (msg) {
228
+ ChatRoom.prototype.send = function (msg, clientType, version) {
229
+ if (clientType === void 0) { clientType = typing_1.ClientType.Other; }
230
+ if (version === void 0) { version = 'Latest'; }
227
231
  return __awaiter(this, void 0, void 0, function () {
228
232
  var rsp, e_4;
229
233
  return __generator(this, function (_a) {
@@ -235,6 +239,7 @@ var ChatRoom = /** @class */ (function () {
235
239
  method: 'post',
236
240
  data: {
237
241
  content: msg,
242
+ client: "".concat(clientType, "/").concat(version),
238
243
  apiKey: this._apiKey
239
244
  },
240
245
  })];
@@ -482,7 +487,7 @@ var ChatRoom = /** @class */ (function () {
482
487
  }, 1000 * 60 * 3);
483
488
  };
484
489
  this._rws.onmessage = function (e) { return __awaiter(_this, void 0, void 0, function () {
485
- var msg, data, barragerContent, userAvatarURL, userAvatarURL20, userNickname, barragerColor, userName, userAvatarURL210, userAvatarURL48, oId, time, userName, userNickname, userAvatarURL, content, md, data_1, oId, count, got, whoGive, whoGot;
490
+ var msg, data, barragerContent, userAvatarURL, userAvatarURL20, userNickname, barragerColor, userName, userAvatarURL210, userAvatarURL48, oId, time, userName, userNickname, userAvatarURL, content, md, client, data_1, oId, count, got, whoGive, whoGot;
486
491
  return __generator(this, function (_a) {
487
492
  msg = JSON.parse(e.data);
488
493
  data = null;
@@ -507,7 +512,7 @@ var ChatRoom = /** @class */ (function () {
507
512
  break;
508
513
  }
509
514
  case 'msg': {
510
- oId = msg.oId, time = msg.time, userName = msg.userName, userNickname = msg.userNickname, userAvatarURL = msg.userAvatarURL, content = msg.content, md = msg.md;
515
+ oId = msg.oId, time = msg.time, userName = msg.userName, userNickname = msg.userNickname, userAvatarURL = msg.userAvatarURL, content = msg.content, md = msg.md, client = msg.client;
511
516
  try {
512
517
  data_1 = JSON.parse(content);
513
518
  if (data_1.msgType === 'redPacket') {
@@ -516,7 +521,7 @@ var ChatRoom = /** @class */ (function () {
516
521
  }
517
522
  }
518
523
  catch (e) { }
519
- data = { oId: oId, time: time, userName: userName, userNickname: userNickname, userAvatarURL: userAvatarURL, content: content, md: md };
524
+ data = { oId: oId, time: time, userName: userName, userNickname: userNickname, userAvatarURL: userAvatarURL, content: content, md: md, client: client, via: (0, utils_1.clientToVia)(client) };
520
525
  break;
521
526
  }
522
527
  case 'redPacketStatus': {
package/lib/index.js CHANGED
@@ -62,7 +62,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
62
62
  };
63
63
  Object.defineProperty(exports, "__esModule", { value: true });
64
64
  exports.FingerTo = void 0;
65
- var crypto = __importStar(require("crypto"));
66
65
  var utils_1 = require("./utils");
67
66
  var chatroom_1 = __importDefault(require("./chatroom"));
68
67
  var notice_1 = __importDefault(require("./notice"));
@@ -72,6 +71,7 @@ var article_1 = __importDefault(require("./article"));
72
71
  var chat_1 = __importDefault(require("./chat"));
73
72
  var breezemoon_1 = __importDefault(require("./breezemoon"));
74
73
  var finger_1 = require("./finger");
74
+ var js_md5_1 = __importDefault(require("js-md5"));
75
75
  var FishPi = /** @class */ (function () {
76
76
  /**
77
77
  * 构造一个 API 请求对象
@@ -145,18 +145,17 @@ var FishPi = /** @class */ (function () {
145
145
  */
146
146
  FishPi.prototype.login = function (data) {
147
147
  return __awaiter(this, void 0, void 0, function () {
148
- var md5, rsp, e_1;
148
+ var rsp, e_1;
149
149
  return __generator(this, function (_a) {
150
150
  switch (_a.label) {
151
151
  case 0:
152
152
  _a.trys.push([0, 2, , 3]);
153
- md5 = crypto.createHash('md5');
154
153
  return [4 /*yield*/, (0, utils_1.request)({
155
154
  url: 'api/getKey',
156
155
  method: 'post',
157
156
  data: {
158
157
  nameOrEmail: data.username,
159
- userPassword: md5.update(data.passwd).digest('hex'),
158
+ userPassword: (0, js_md5_1.default)(data.passwd),
160
159
  mfaCode: data.mfaCode
161
160
  },
162
161
  })];
package/lib/typing.d.ts CHANGED
@@ -539,6 +539,64 @@ export interface Metal extends MetalBase {
539
539
  * 徽章列表
540
540
  */
541
541
  export declare type MetalList = Array<Metal>;
542
+ export declare enum ClientType {
543
+ /**
544
+ * 网页端
545
+ */
546
+ Web = "Web",
547
+ /**
548
+ * PC 端
549
+ */
550
+ PC = "PC",
551
+ /**
552
+ * 移动端聊天室
553
+ */
554
+ Mobile = "Mobile",
555
+ /**
556
+ * Windows 客户端
557
+ */
558
+ Windows = "Windows",
559
+ /**
560
+ * macOS 客户端
561
+ */
562
+ macOS = "macOS",
563
+ /**
564
+ * iOS 客户端
565
+ */
566
+ iOS = "iOS",
567
+ /**
568
+ * Android 客户端
569
+ */
570
+ Android = "Android",
571
+ /**
572
+ * IDEA 插件
573
+ */
574
+ IDEA = "IDEA",
575
+ /**
576
+ * Chrome 插件
577
+ */
578
+ Chrome = "Chrome",
579
+ /**
580
+ * Edge 插件
581
+ */
582
+ Edge = "Edge",
583
+ /**
584
+ * VSCode 插件
585
+ */
586
+ VSCode = "VSCode",
587
+ /**
588
+ * Python 插件
589
+ */
590
+ Python = "Python",
591
+ /**
592
+ * Golang 插件
593
+ */
594
+ Golang = "Golang",
595
+ /**
596
+ * 其他插件
597
+ */
598
+ Other = "Other"
599
+ }
542
600
  /**
543
601
  * 聊天室消息
544
602
  */
@@ -563,6 +621,23 @@ export interface ChatRoomMessage {
563
621
  * 用户徽章
564
622
  */
565
623
  sysMetal: MetalList;
624
+ /**
625
+ * 消息来源
626
+ */
627
+ client: string;
628
+ /**
629
+ * 消息来源解析
630
+ */
631
+ via: {
632
+ /**
633
+ * 消息来源
634
+ */
635
+ client: ClientType | string;
636
+ /**
637
+ * 消息来源版本
638
+ */
639
+ version: string;
640
+ };
566
641
  /**
567
642
  * 消息内容
568
643
  */
@@ -715,6 +790,23 @@ export interface ChatMsg {
715
790
  * 消息内容 Markdown
716
791
  */
717
792
  md: string;
793
+ /**
794
+ * 消息来源
795
+ */
796
+ client: string;
797
+ /**
798
+ * 消息来源解析
799
+ */
800
+ via: {
801
+ /**
802
+ * 消息来源
803
+ */
804
+ client: ClientType | string;
805
+ /**
806
+ * 消息来源版本
807
+ */
808
+ version: string;
809
+ };
718
810
  }
719
811
  /**
720
812
  * @ 用户列表
package/lib/typing.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VoteStatus = exports.ArticleListType = exports.ArticleStatus = exports.YesNoStatus = exports.PublicStatus = exports.ArticleType = exports.ReportType = exports.ReportDataType = exports.NoticeType = exports.ChatRoomMessageType = exports.ChatMessageType = exports.ChatContentType = exports.MetalAttr = exports.RedPacketType = exports.GestureType = exports.UserAppRole = exports.DataType = void 0;
3
+ exports.VoteStatus = exports.ArticleListType = exports.ArticleStatus = exports.YesNoStatus = exports.PublicStatus = exports.ArticleType = exports.ReportType = exports.ReportDataType = exports.NoticeType = exports.ChatRoomMessageType = exports.ChatMessageType = exports.ChatContentType = exports.ClientType = exports.MetalAttr = exports.RedPacketType = exports.GestureType = exports.UserAppRole = exports.DataType = void 0;
4
4
  /**
5
5
  * 数据类型
6
6
  */
@@ -215,6 +215,65 @@ var MetalAttr = /** @class */ (function () {
215
215
  return MetalAttr;
216
216
  }());
217
217
  exports.MetalAttr = MetalAttr;
218
+ var ClientType;
219
+ (function (ClientType) {
220
+ /**
221
+ * 网页端
222
+ */
223
+ ClientType["Web"] = "Web";
224
+ /**
225
+ * PC 端
226
+ */
227
+ ClientType["PC"] = "PC";
228
+ /**
229
+ * 移动端聊天室
230
+ */
231
+ ClientType["Mobile"] = "Mobile";
232
+ /**
233
+ * Windows 客户端
234
+ */
235
+ ClientType["Windows"] = "Windows";
236
+ /**
237
+ * macOS 客户端
238
+ */
239
+ ClientType["macOS"] = "macOS";
240
+ /**
241
+ * iOS 客户端
242
+ */
243
+ ClientType["iOS"] = "iOS";
244
+ /**
245
+ * Android 客户端
246
+ */
247
+ ClientType["Android"] = "Android";
248
+ /**
249
+ * IDEA 插件
250
+ */
251
+ ClientType["IDEA"] = "IDEA";
252
+ /**
253
+ * Chrome 插件
254
+ */
255
+ ClientType["Chrome"] = "Chrome";
256
+ /**
257
+ * Edge 插件
258
+ */
259
+ ClientType["Edge"] = "Edge";
260
+ /**
261
+ * VSCode 插件
262
+ */
263
+ ClientType["VSCode"] = "VSCode";
264
+ /**
265
+ * Python 插件
266
+ */
267
+ ClientType["Python"] = "Python";
268
+ /**
269
+ * Golang 插件
270
+ */
271
+ ClientType["Golang"] = "Golang";
272
+ /**
273
+ * 其他插件
274
+ */
275
+ ClientType["Other"] = "Other";
276
+ })(ClientType = exports.ClientType || (exports.ClientType = {}));
218
277
  /**
219
278
  * 历史消息类型
220
279
  */
package/lib/utils.d.ts CHANGED
@@ -4,5 +4,9 @@ declare function setDomain(d: string): void;
4
4
  declare function request(opt: any): Promise<any>;
5
5
  declare function analyzeMetalAttr(m: any): Metal;
6
6
  declare function toMetal(sysMetal: string): MetalList;
7
+ declare function clientToVia(client: string): {
8
+ client: string;
9
+ version: string;
10
+ } | undefined;
7
11
  declare const isBrowse: boolean;
8
- export { request, domain, toMetal, analyzeMetalAttr, isBrowse, setDomain };
12
+ export { request, domain, toMetal, analyzeMetalAttr, isBrowse, setDomain, clientToVia };
package/lib/utils.js CHANGED
@@ -55,7 +55,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
55
55
  }
56
56
  };
57
57
  Object.defineProperty(exports, "__esModule", { value: true });
58
- exports.setDomain = exports.isBrowse = exports.analyzeMetalAttr = exports.toMetal = exports.domain = exports.request = void 0;
58
+ exports.clientToVia = exports.setDomain = exports.isBrowse = exports.analyzeMetalAttr = exports.toMetal = exports.domain = exports.request = void 0;
59
59
  var domain = 'fishpi.cn';
60
60
  exports.domain = domain;
61
61
  function setDomain(d) {
@@ -144,5 +144,12 @@ function toMetal(sysMetal) {
144
144
  }
145
145
  }
146
146
  exports.toMetal = toMetal;
147
+ function clientToVia(client) {
148
+ if (!client)
149
+ return;
150
+ var via = client.split('/');
151
+ return { client: via[0], version: via[1] };
152
+ }
153
+ exports.clientToVia = clientToVia;
147
154
  var isBrowse = typeof window !== 'undefined';
148
155
  exports.isBrowse = isBrowse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fishpi",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "description": "A Package to use API of fishpi.",
5
5
  "main": "./lib/index.js",
6
6
  "files": [
@@ -32,7 +32,9 @@
32
32
  },
33
33
  "homepage": "https://github.com/imlinhanchao/fishpi-api-package#readme",
34
34
  "dependencies": {
35
+ "@types/js-md5": "^0.7.0",
35
36
  "form-data": "^4.0.0",
37
+ "js-md5": "^0.7.3",
36
38
  "reconnecting-websocket": "^4.4.0",
37
39
  "ws": "^8.4.2"
38
40
  },