fishpi 0.0.54 → 0.0.55
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/LICENSE +21 -21
- package/README.md +105 -105
- package/lib/chatroom.js +17 -19
- package/lib/finger.js +0 -2
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Ryan Sonshine
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Ryan Sonshine
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
# 摸鱼派 API Package
|
|
2
|
-
摸鱼派社区 (https://fishpi.cn/) 的 API Package,可以快速开发出一款应用支援社区功能。
|
|
3
|
-
|
|
4
|
-
## 支援
|
|
5
|
-
- 用户信息;
|
|
6
|
-
- 聊天室;
|
|
7
|
-
- 话题编辑;
|
|
8
|
-
- 红包收发;
|
|
9
|
-
- 自定义表情包;
|
|
10
|
-
- 文件上传;
|
|
11
|
-
- 通知信息;
|
|
12
|
-
- 清风明月;
|
|
13
|
-
- 文章读写;
|
|
14
|
-
- 评论点赞;
|
|
15
|
-
- 私聊功能;
|
|
16
|
-
|
|
17
|
-
## 安装
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npm install fishpi
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## 用例
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
import FishPi from 'fishpi';
|
|
27
|
-
|
|
28
|
-
// 登录获取 apiKey
|
|
29
|
-
let apiKey = '';
|
|
30
|
-
let fish = new FishPi();
|
|
31
|
-
let rsp = await fish.login({
|
|
32
|
-
username: 'username',
|
|
33
|
-
passwd: 'password123456'
|
|
34
|
-
});
|
|
35
|
-
if (rsp.code == 0) apiKey = rsp.Key;
|
|
36
|
-
|
|
37
|
-
// 通过 apiKey 获取登录用户信息
|
|
38
|
-
let fish = new FishPi(apiKey);
|
|
39
|
-
console.dir(await fish.account.info());
|
|
40
|
-
|
|
41
|
-
// 获取用户自定义表情包
|
|
42
|
-
let emojis = await fish.emoji.get();
|
|
43
|
-
// 获取默认表情包
|
|
44
|
-
let defaultEmoji = fish.emoji.default;
|
|
45
|
-
|
|
46
|
-
// 监听聊天室消息
|
|
47
|
-
fish.chatroom.addListener(({ msg }) => console.dir(msg));
|
|
48
|
-
// 向聊天室发送信息(需要登录)
|
|
49
|
-
await fish.chatroom.send('Hello World!');
|
|
50
|
-
// 向聊天室发送红包
|
|
51
|
-
await fish.chatroom.redpacket.send({
|
|
52
|
-
type: 'random';
|
|
53
|
-
money: 32;
|
|
54
|
-
count: 2;
|
|
55
|
-
msg: '摸鱼者,事竟成!';
|
|
56
|
-
recivers: [];
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
// 私聊历史获取
|
|
60
|
-
let chatHistory = await fish.chat.get({ user: 'username', autoRead: false })
|
|
61
|
-
// 监听私聊新消息
|
|
62
|
-
fishpi.chat.addListener(async ({ msg }: { msg: NoticeMsg }) => {
|
|
63
|
-
switch (msg.command) {
|
|
64
|
-
// 私聊未读数更新
|
|
65
|
-
case 'chatUnreadCountRefresh':
|
|
66
|
-
if(msg.count! > 0) {
|
|
67
|
-
let unreadMsgs = await fishpi.chat.unread();
|
|
68
|
-
}
|
|
69
|
-
break;
|
|
70
|
-
// 新私聊消息
|
|
71
|
-
case 'newIdleChatMessage':
|
|
72
|
-
// msg 就是新的私聊消息
|
|
73
|
-
console.log(msg.senderUserName, '说:', msg.preview);
|
|
74
|
-
break;
|
|
75
|
-
// 有新的消息通知
|
|
76
|
-
case 'refreshNotification':
|
|
77
|
-
console.log('你有新消息【', await fishpi.notice.count(), '】')
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
// 监听指定用户的私聊消息
|
|
82
|
-
fishpi.chat.addListener(({ msg }: { msg: ChatData }) => {
|
|
83
|
-
console.log(msg.senderUserName, '[', msg.time, ']:', msg.content);
|
|
84
|
-
}, 'username');
|
|
85
|
-
// 给指定用户发私聊消息
|
|
86
|
-
fishpi.chat.send('username', 'Hi~');
|
|
87
|
-
|
|
88
|
-
// 金手指
|
|
89
|
-
import { Finger, FingerTo } from 'fishpi';
|
|
90
|
-
|
|
91
|
-
// 一次性金手指
|
|
92
|
-
await FingerTo('GoldenFingerKey').queryLatestLoginIP('username')
|
|
93
|
-
|
|
94
|
-
// 金手指实例
|
|
95
|
-
const finger = new Finger(apiKey);
|
|
96
|
-
await finger.queryLatestLoginIP('username');
|
|
97
|
-
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
## 注意事项
|
|
101
|
-
|
|
102
|
-
API 库使用 `fetch` 做 API 请求,浏览器环境可以直接使用。在 Node 环境需要安装 `node-fetch` 2.x 版本的库。执行如下代码设置 `fetch` 函数:
|
|
103
|
-
```typescript
|
|
104
|
-
import fetch from 'node-fetch'
|
|
105
|
-
globalThis.fetch = fetch as any;
|
|
1
|
+
# 摸鱼派 API Package
|
|
2
|
+
摸鱼派社区 (https://fishpi.cn/) 的 API Package,可以快速开发出一款应用支援社区功能。
|
|
3
|
+
|
|
4
|
+
## 支援
|
|
5
|
+
- 用户信息;
|
|
6
|
+
- 聊天室;
|
|
7
|
+
- 话题编辑;
|
|
8
|
+
- 红包收发;
|
|
9
|
+
- 自定义表情包;
|
|
10
|
+
- 文件上传;
|
|
11
|
+
- 通知信息;
|
|
12
|
+
- 清风明月;
|
|
13
|
+
- 文章读写;
|
|
14
|
+
- 评论点赞;
|
|
15
|
+
- 私聊功能;
|
|
16
|
+
|
|
17
|
+
## 安装
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install fishpi
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 用例
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import FishPi from 'fishpi';
|
|
27
|
+
|
|
28
|
+
// 登录获取 apiKey
|
|
29
|
+
let apiKey = '';
|
|
30
|
+
let fish = new FishPi();
|
|
31
|
+
let rsp = await fish.login({
|
|
32
|
+
username: 'username',
|
|
33
|
+
passwd: 'password123456'
|
|
34
|
+
});
|
|
35
|
+
if (rsp.code == 0) apiKey = rsp.Key;
|
|
36
|
+
|
|
37
|
+
// 通过 apiKey 获取登录用户信息
|
|
38
|
+
let fish = new FishPi(apiKey);
|
|
39
|
+
console.dir(await fish.account.info());
|
|
40
|
+
|
|
41
|
+
// 获取用户自定义表情包
|
|
42
|
+
let emojis = await fish.emoji.get();
|
|
43
|
+
// 获取默认表情包
|
|
44
|
+
let defaultEmoji = fish.emoji.default;
|
|
45
|
+
|
|
46
|
+
// 监听聊天室消息
|
|
47
|
+
fish.chatroom.addListener(({ msg }) => console.dir(msg));
|
|
48
|
+
// 向聊天室发送信息(需要登录)
|
|
49
|
+
await fish.chatroom.send('Hello World!');
|
|
50
|
+
// 向聊天室发送红包
|
|
51
|
+
await fish.chatroom.redpacket.send({
|
|
52
|
+
type: 'random';
|
|
53
|
+
money: 32;
|
|
54
|
+
count: 2;
|
|
55
|
+
msg: '摸鱼者,事竟成!';
|
|
56
|
+
recivers: [];
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
// 私聊历史获取
|
|
60
|
+
let chatHistory = await fish.chat.get({ user: 'username', autoRead: false })
|
|
61
|
+
// 监听私聊新消息
|
|
62
|
+
fishpi.chat.addListener(async ({ msg }: { msg: NoticeMsg }) => {
|
|
63
|
+
switch (msg.command) {
|
|
64
|
+
// 私聊未读数更新
|
|
65
|
+
case 'chatUnreadCountRefresh':
|
|
66
|
+
if(msg.count! > 0) {
|
|
67
|
+
let unreadMsgs = await fishpi.chat.unread();
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
70
|
+
// 新私聊消息
|
|
71
|
+
case 'newIdleChatMessage':
|
|
72
|
+
// msg 就是新的私聊消息
|
|
73
|
+
console.log(msg.senderUserName, '说:', msg.preview);
|
|
74
|
+
break;
|
|
75
|
+
// 有新的消息通知
|
|
76
|
+
case 'refreshNotification':
|
|
77
|
+
console.log('你有新消息【', await fishpi.notice.count(), '】')
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
// 监听指定用户的私聊消息
|
|
82
|
+
fishpi.chat.addListener(({ msg }: { msg: ChatData }) => {
|
|
83
|
+
console.log(msg.senderUserName, '[', msg.time, ']:', msg.content);
|
|
84
|
+
}, 'username');
|
|
85
|
+
// 给指定用户发私聊消息
|
|
86
|
+
fishpi.chat.send('username', 'Hi~');
|
|
87
|
+
|
|
88
|
+
// 金手指
|
|
89
|
+
import { Finger, FingerTo } from 'fishpi';
|
|
90
|
+
|
|
91
|
+
// 一次性金手指
|
|
92
|
+
await FingerTo('GoldenFingerKey').queryLatestLoginIP('username')
|
|
93
|
+
|
|
94
|
+
// 金手指实例
|
|
95
|
+
const finger = new Finger(apiKey);
|
|
96
|
+
await finger.queryLatestLoginIP('username');
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 注意事项
|
|
101
|
+
|
|
102
|
+
API 库使用 `fetch` 做 API 请求,浏览器环境可以直接使用。在 Node 环境需要安装 `node-fetch` 2.x 版本的库。执行如下代码设置 `fetch` 函数:
|
|
103
|
+
```typescript
|
|
104
|
+
import fetch from 'node-fetch'
|
|
105
|
+
globalThis.fetch = fetch as any;
|
|
106
106
|
```
|
package/lib/chatroom.js
CHANGED
|
@@ -142,7 +142,7 @@ var ChatRoom = /** @class */ (function () {
|
|
|
142
142
|
if (page === void 0) { page = 1; }
|
|
143
143
|
if (type === void 0) { type = typing_1.ChatContentType.HTML; }
|
|
144
144
|
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
-
var
|
|
145
|
+
var rsp, redpacket_1, e_1;
|
|
146
146
|
return __generator(this, function (_a) {
|
|
147
147
|
switch (_a.label) {
|
|
148
148
|
case 0:
|
|
@@ -151,26 +151,24 @@ var ChatRoom = /** @class */ (function () {
|
|
|
151
151
|
url: "chat-room/more?page=".concat(page, "&type=").concat(type, "&apiKey=").concat(this._apiKey)
|
|
152
152
|
})];
|
|
153
153
|
case 1:
|
|
154
|
-
|
|
155
|
-
if (
|
|
156
|
-
throw new Error(
|
|
154
|
+
rsp = _a.sent();
|
|
155
|
+
if (rsp.code != 0) {
|
|
156
|
+
throw new Error(rsp.msg);
|
|
157
157
|
}
|
|
158
|
-
if (!
|
|
159
|
-
return [2 /*return*/,
|
|
160
|
-
|
|
158
|
+
if (!rsp.data)
|
|
159
|
+
return [2 /*return*/, rsp];
|
|
160
|
+
rsp.data.forEach(function (d, i, data) {
|
|
161
161
|
try {
|
|
162
162
|
data[i].via = (0, utils_1.clientToVia)(data[i].client);
|
|
163
163
|
data[i].sysMetal = (0, utils_1.toMetal)(data[i].sysMetal);
|
|
164
164
|
redpacket_1 = JSON.parse(d.content);
|
|
165
|
-
if (redpacket_1.msgType !== 'redPacket')
|
|
166
|
-
return rsp_1;
|
|
167
165
|
if (redpacket_1.recivers)
|
|
168
166
|
redpacket_1.recivers = JSON.parse(redpacket_1.recivers);
|
|
169
167
|
data[i].content = redpacket_1;
|
|
170
168
|
}
|
|
171
169
|
catch (e) { }
|
|
172
170
|
});
|
|
173
|
-
return [2 /*return*/,
|
|
171
|
+
return [2 /*return*/, rsp];
|
|
174
172
|
case 2:
|
|
175
173
|
e_1 = _a.sent();
|
|
176
174
|
throw e_1;
|
|
@@ -181,7 +179,7 @@ var ChatRoom = /** @class */ (function () {
|
|
|
181
179
|
};
|
|
182
180
|
ChatRoom.prototype.get = function (data) {
|
|
183
181
|
return __awaiter(this, void 0, void 0, function () {
|
|
184
|
-
var
|
|
182
|
+
var rsp_1, redpacket_2, e_2;
|
|
185
183
|
return __generator(this, function (_a) {
|
|
186
184
|
switch (_a.label) {
|
|
187
185
|
case 0:
|
|
@@ -190,26 +188,26 @@ var ChatRoom = /** @class */ (function () {
|
|
|
190
188
|
url: "chat-room/getMessage?oId=".concat(data.oId, "&mode=").concat(data.mode, "&size=").concat(data.size, "&type=").concat(data.type, "&apiKey=").concat(this._apiKey)
|
|
191
189
|
})];
|
|
192
190
|
case 1:
|
|
193
|
-
|
|
194
|
-
if (
|
|
195
|
-
throw new Error(
|
|
191
|
+
rsp_1 = _a.sent();
|
|
192
|
+
if (rsp_1.code != 0) {
|
|
193
|
+
throw new Error(rsp_1.msg);
|
|
196
194
|
}
|
|
197
|
-
if (!
|
|
198
|
-
return [2 /*return*/,
|
|
199
|
-
|
|
195
|
+
if (!rsp_1.data)
|
|
196
|
+
return [2 /*return*/, rsp_1];
|
|
197
|
+
rsp_1.data.forEach(function (d, i, data) {
|
|
200
198
|
try {
|
|
201
199
|
data[i].via = (0, utils_1.clientToVia)(data[i].client);
|
|
202
200
|
data[i].sysMetal = (0, utils_1.toMetal)(data[i].sysMetal);
|
|
203
201
|
redpacket_2 = JSON.parse(d.content);
|
|
204
202
|
if (redpacket_2.msgType !== 'redPacket')
|
|
205
|
-
return
|
|
203
|
+
return rsp_1;
|
|
206
204
|
if (redpacket_2.recivers)
|
|
207
205
|
redpacket_2.recivers = JSON.parse(redpacket_2.recivers);
|
|
208
206
|
data[i].content = redpacket_2;
|
|
209
207
|
}
|
|
210
208
|
catch (e) { }
|
|
211
209
|
});
|
|
212
|
-
return [2 /*return*/,
|
|
210
|
+
return [2 /*return*/, rsp_1];
|
|
213
211
|
case 2:
|
|
214
212
|
e_2 = _a.sent();
|
|
215
213
|
throw e_2;
|
package/lib/finger.js
CHANGED