fishpi 0.0.3 → 0.0.7

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 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,52 +1,56 @@
1
- # 摸鱼派 API Package
2
- 摸鱼派社区 (https://fishpi.cn/) 的 API Package,可以快速开发出一款应用支援社区功能。
3
-
4
- ## 支援
5
- - 用户信息;
6
- - 聊天室;
7
- - 文件上传;
8
- - 通知信息;
9
-
10
- ## 安装
11
-
12
- ```bash
13
- npm install fishpi
14
- ```
15
-
16
- ## 用例
17
-
18
- ```ts
19
- import FishPi from 'fishpi';
20
-
21
- // 登录获取 apiKey
22
- let apiKey = '';
23
- let fish = new FishPi();
24
- let rsp = await fish.login({
25
- username: 'username',
26
- passwd: 'password123456'
27
- });
28
- if (rsp.code == 0) apiKey = rsp.Key;
29
-
30
- // 通过 apiKey 获取登录用户信息
31
- let fish = new FishPi(apiKey);
32
- console.dir(await fish.info());
33
-
34
- // 获取用户自定义表情包
35
- let emojis = await fish.emoji.get();
36
- // 获取默认表情包
37
- let defaultEmoji = fish.emoji.default;
38
-
39
- // 监听聊天室消息
40
- fish.chatroom.addListener((ev:any) => console.dir(ev));
41
- // 向聊天室发送信息(需要登录)
42
- await fish.chatroom.send('Hello World!');
43
- // 向聊天室发送红包
44
- await fish.chatroom.redpacket.send({
45
- type: 'random';
46
- money: 32;
47
- count: 2;
48
- msg: '摸鱼者,事竟成!';
49
- recivers: [];
50
- })
51
-
52
- ```
1
+ # 摸鱼派 API Package
2
+ 摸鱼派社区 (https://fishpi.cn/) 的 API Package,可以快速开发出一款应用支援社区功能。
3
+
4
+ ## 支援
5
+ - 用户信息;
6
+ - 聊天室;
7
+ - 话题编辑;
8
+ - 红包收发;
9
+ - 自定义表情包;
10
+ - 文件上传;
11
+ - 通知信息;
12
+ - 清风明月;
13
+
14
+ ## 安装
15
+
16
+ ```bash
17
+ npm install fishpi
18
+ ```
19
+
20
+ ## 用例
21
+
22
+ ```ts
23
+ import FishPi from 'fishpi';
24
+
25
+ // 登录获取 apiKey
26
+ let apiKey = '';
27
+ let fish = new FishPi();
28
+ let rsp = await fish.login({
29
+ username: 'username',
30
+ passwd: 'password123456'
31
+ });
32
+ if (rsp.code == 0) apiKey = rsp.Key;
33
+
34
+ // 通过 apiKey 获取登录用户信息
35
+ let fish = new FishPi(apiKey);
36
+ console.dir(await fish.account.info());
37
+
38
+ // 获取用户自定义表情包
39
+ let emojis = await fish.emoji.get();
40
+ // 获取默认表情包
41
+ let defaultEmoji = fish.emoji.default;
42
+
43
+ // 监听聊天室消息
44
+ fish.chatroom.addListener((ev:any) => console.dir(ev));
45
+ // 向聊天室发送信息(需要登录)
46
+ await fish.chatroom.send('Hello World!');
47
+ // 向聊天室发送红包
48
+ await fish.chatroom.redpacket.send({
49
+ type: 'random';
50
+ money: 32;
51
+ count: 2;
52
+ msg: '摸鱼者,事竟成!';
53
+ recivers: [];
54
+ })
55
+
56
+ ```
@@ -0,0 +1,60 @@
1
+ import { ApiResponse, ArticlePost, ArticleListType, ArticleDetail, VoteStatus } from './typing';
2
+ declare class Article {
3
+ private _apiKey;
4
+ constructor(token?: string);
5
+ /**
6
+ * 重新设置请求 Token
7
+ * @param apiKey 接口 API Key
8
+ */
9
+ setToken(token: string): void;
10
+ /**
11
+ * 发布文章
12
+ * @param data 文章信息
13
+ * @returns 发布成功返回文章Id (articleId)
14
+ */
15
+ post(data: ArticlePost): Promise<{
16
+ code: number;
17
+ msg?: string;
18
+ articleId?: string;
19
+ }>;
20
+ /**
21
+ * 更新文章
22
+ * @param id 文章 Id
23
+ * @param data 文章信息
24
+ * @returns 更新成功返回文章Id (articleId)
25
+ */
26
+ update(id: string, data: ArticlePost): Promise<{
27
+ code: number;
28
+ msg?: string;
29
+ articleId?: string;
30
+ }>;
31
+ /**
32
+ * 查询文章列表
33
+ * @param type 查询类型
34
+ * @param tag 指定查询标签,可选
35
+ * @returns 文章列表
36
+ */
37
+ list(type: ArticleListType, tag?: string): Promise<ApiResponse<{
38
+ articles: Array<ArticleDetail>;
39
+ }>>;
40
+ /**
41
+ * 获取文章详情
42
+ * @param id 文章id
43
+ * @returns 文章详情
44
+ */
45
+ detail(id: string): Promise<ApiResponse<{
46
+ article: ArticleDetail;
47
+ }>>;
48
+ /**
49
+ * 点赞/取消点赞文章
50
+ * @param id 文章id
51
+ * @returns 文章点赞状态
52
+ */
53
+ vote(id: string): Promise<{
54
+ code: number;
55
+ msg?: string;
56
+ type?: VoteStatus;
57
+ }>;
58
+ thank(id: string): Promise<ApiResponse<undefined>>;
59
+ }
60
+ export default Article;
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ var utils_1 = require("./utils");
51
+ var Article = /** @class */ (function () {
52
+ function Article(token) {
53
+ if (token === void 0) { token = ''; }
54
+ this._apiKey = '';
55
+ if (!token) {
56
+ return;
57
+ }
58
+ this._apiKey = token;
59
+ }
60
+ /**
61
+ * 重新设置请求 Token
62
+ * @param apiKey 接口 API Key
63
+ */
64
+ Article.prototype.setToken = function (token) {
65
+ this._apiKey = token;
66
+ };
67
+ /**
68
+ * 发布文章
69
+ * @param data 文章信息
70
+ * @returns 发布成功返回文章Id (articleId)
71
+ */
72
+ Article.prototype.post = function (data) {
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ var rsp, e_1;
75
+ return __generator(this, function (_a) {
76
+ switch (_a.label) {
77
+ case 0:
78
+ _a.trys.push([0, 2, , 3]);
79
+ return [4 /*yield*/, (0, utils_1.request)({
80
+ url: "article",
81
+ method: 'post',
82
+ data: __assign(__assign({}, data), { apiKey: this._apiKey }),
83
+ })];
84
+ case 1:
85
+ rsp = _a.sent();
86
+ if (rsp.status === 401) {
87
+ return [2 /*return*/, { code: -1, msg: '登录已失效,请重新登录!' }];
88
+ }
89
+ return [2 /*return*/, rsp.data];
90
+ case 2:
91
+ e_1 = _a.sent();
92
+ throw e_1;
93
+ case 3: return [2 /*return*/];
94
+ }
95
+ });
96
+ });
97
+ };
98
+ /**
99
+ * 更新文章
100
+ * @param id 文章 Id
101
+ * @param data 文章信息
102
+ * @returns 更新成功返回文章Id (articleId)
103
+ */
104
+ Article.prototype.update = function (id, data) {
105
+ return __awaiter(this, void 0, void 0, function () {
106
+ var rsp, e_2;
107
+ return __generator(this, function (_a) {
108
+ switch (_a.label) {
109
+ case 0:
110
+ _a.trys.push([0, 2, , 3]);
111
+ return [4 /*yield*/, (0, utils_1.request)({
112
+ url: "article/".concat(id),
113
+ method: 'put',
114
+ data: __assign(__assign({}, data), { apiKey: this._apiKey }),
115
+ })];
116
+ case 1:
117
+ rsp = _a.sent();
118
+ if (rsp.status === 401) {
119
+ return [2 /*return*/, { code: -1, msg: '登录已失效,请重新登录!' }];
120
+ }
121
+ return [2 /*return*/, rsp.data];
122
+ case 2:
123
+ e_2 = _a.sent();
124
+ throw e_2;
125
+ case 3: return [2 /*return*/];
126
+ }
127
+ });
128
+ });
129
+ };
130
+ /**
131
+ * 查询文章列表
132
+ * @param type 查询类型
133
+ * @param tag 指定查询标签,可选
134
+ * @returns 文章列表
135
+ */
136
+ Article.prototype.list = function (type, tag) {
137
+ return __awaiter(this, void 0, void 0, function () {
138
+ var rsp, e_3;
139
+ return __generator(this, function (_a) {
140
+ switch (_a.label) {
141
+ case 0:
142
+ _a.trys.push([0, 2, , 3]);
143
+ return [4 /*yield*/, (0, utils_1.request)({
144
+ url: "articles/".concat(tag !== undefined ? "tag/".concat(tag) : 'recent').concat(type, "?apiKey=").concat(this._apiKey),
145
+ })];
146
+ case 1:
147
+ rsp = _a.sent();
148
+ return [2 /*return*/, rsp.data];
149
+ case 2:
150
+ e_3 = _a.sent();
151
+ throw e_3;
152
+ case 3: return [2 /*return*/];
153
+ }
154
+ });
155
+ });
156
+ };
157
+ /**
158
+ * 获取文章详情
159
+ * @param id 文章id
160
+ * @returns 文章详情
161
+ */
162
+ Article.prototype.detail = function (id) {
163
+ return __awaiter(this, void 0, void 0, function () {
164
+ var rsp, i, i, e_4;
165
+ return __generator(this, function (_a) {
166
+ switch (_a.label) {
167
+ case 0:
168
+ _a.trys.push([0, 2, , 3]);
169
+ return [4 /*yield*/, (0, utils_1.request)({
170
+ url: "article/".concat(id, "?apiKey=").concat(this._apiKey),
171
+ })];
172
+ case 1:
173
+ rsp = _a.sent();
174
+ rsp.data.articleAuthor.sysMetal = (0, utils_1.analyzeMetalAttr)(rsp.data.articleAuthor.sysMetal);
175
+ for (i = 0; i < rsp.data.articleComments.length; i++) {
176
+ rsp.data.articleComments[i].sysMetal = (0, utils_1.analyzeMetalAttr)(rsp.data.articleComments[i].sysMetal);
177
+ }
178
+ for (i = 0; i < rsp.data.articleNiceComments.length; i++) {
179
+ rsp.data.articleNiceComments[i].sysMetal = (0, utils_1.analyzeMetalAttr)(rsp.data.articleNiceComments[i].sysMetal);
180
+ }
181
+ return [2 /*return*/, rsp.data];
182
+ case 2:
183
+ e_4 = _a.sent();
184
+ throw e_4;
185
+ case 3: return [2 /*return*/];
186
+ }
187
+ });
188
+ });
189
+ };
190
+ /**
191
+ * 点赞/取消点赞文章
192
+ * @param id 文章id
193
+ * @returns 文章点赞状态
194
+ */
195
+ Article.prototype.vote = function (id) {
196
+ return __awaiter(this, void 0, void 0, function () {
197
+ var rsp, e_5;
198
+ return __generator(this, function (_a) {
199
+ switch (_a.label) {
200
+ case 0:
201
+ _a.trys.push([0, 2, , 3]);
202
+ return [4 /*yield*/, (0, utils_1.request)({
203
+ url: "/vote/up/article",
204
+ method: 'post',
205
+ data: {
206
+ dataId: id,
207
+ apiKey: this._apiKey
208
+ },
209
+ })];
210
+ case 1:
211
+ rsp = _a.sent();
212
+ if (rsp.status === 401) {
213
+ return [2 /*return*/, { code: -1, msg: '登录已失效,请重新登录!' }];
214
+ }
215
+ return [2 /*return*/, rsp.data];
216
+ case 2:
217
+ e_5 = _a.sent();
218
+ throw e_5;
219
+ case 3: return [2 /*return*/];
220
+ }
221
+ });
222
+ });
223
+ };
224
+ Article.prototype.thank = function (id) {
225
+ return __awaiter(this, void 0, void 0, function () {
226
+ var rsp, e_6;
227
+ return __generator(this, function (_a) {
228
+ switch (_a.label) {
229
+ case 0:
230
+ _a.trys.push([0, 2, , 3]);
231
+ return [4 /*yield*/, (0, utils_1.request)({
232
+ url: "/article/thank?articleId=".concat(id),
233
+ method: 'post',
234
+ data: {
235
+ apiKey: this._apiKey
236
+ },
237
+ })];
238
+ case 1:
239
+ rsp = _a.sent();
240
+ if (rsp.status === 401) {
241
+ return [2 /*return*/, { code: -1, msg: '登录已失效,请重新登录!' }];
242
+ }
243
+ return [2 /*return*/, rsp.data];
244
+ case 2:
245
+ e_6 = _a.sent();
246
+ throw e_6;
247
+ case 3: return [2 /*return*/];
248
+ }
249
+ });
250
+ });
251
+ };
252
+ return Article;
253
+ }());
254
+ exports.default = Article;
@@ -0,0 +1,20 @@
1
+ import { ApiResponse, BreezemoonContent } from './typing';
2
+ declare class Breezemoon {
3
+ private _apiKey;
4
+ constructor(token?: string);
5
+ /**
6
+ * 重新设置请求 Token
7
+ * @param apiKey 接口 API Key
8
+ */
9
+ setToken(token: string): void;
10
+ /**
11
+ * 查询聊天室历史消息
12
+ * @param page 消息页码
13
+ */
14
+ list(page?: number, size?: number): Promise<{
15
+ code: number;
16
+ breezemoons: Array<BreezemoonContent>;
17
+ }>;
18
+ send(content: string): Promise<ApiResponse<undefined>>;
19
+ }
20
+ export default Breezemoon;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var utils_1 = require("./utils");
40
+ var Breezemoon = /** @class */ (function () {
41
+ function Breezemoon(token) {
42
+ if (token === void 0) { token = ''; }
43
+ this._apiKey = '';
44
+ if (!token) {
45
+ return;
46
+ }
47
+ this._apiKey = token;
48
+ }
49
+ /**
50
+ * 重新设置请求 Token
51
+ * @param apiKey 接口 API Key
52
+ */
53
+ Breezemoon.prototype.setToken = function (token) {
54
+ this._apiKey = token;
55
+ };
56
+ /**
57
+ * 查询聊天室历史消息
58
+ * @param page 消息页码
59
+ */
60
+ Breezemoon.prototype.list = function (page, size) {
61
+ if (page === void 0) { page = 1; }
62
+ if (size === void 0) { size = 20; }
63
+ return __awaiter(this, void 0, void 0, function () {
64
+ var rsp, e_1;
65
+ return __generator(this, function (_a) {
66
+ switch (_a.label) {
67
+ case 0:
68
+ _a.trys.push([0, 2, , 3]);
69
+ return [4 /*yield*/, (0, utils_1.request)({
70
+ url: "api/breezemoons?p=".concat(page, "&size=").concat(size)
71
+ })];
72
+ case 1:
73
+ rsp = _a.sent();
74
+ if (rsp.code != 0) {
75
+ throw new Error(rsp.msg);
76
+ }
77
+ return [2 /*return*/, rsp.data];
78
+ case 2:
79
+ e_1 = _a.sent();
80
+ throw e_1;
81
+ case 3: return [2 /*return*/];
82
+ }
83
+ });
84
+ });
85
+ };
86
+ Breezemoon.prototype.send = function (content) {
87
+ return __awaiter(this, void 0, void 0, function () {
88
+ var rsp, e_2;
89
+ return __generator(this, function (_a) {
90
+ switch (_a.label) {
91
+ case 0:
92
+ _a.trys.push([0, 2, , 3]);
93
+ return [4 /*yield*/, (0, utils_1.request)({
94
+ url: "breezemoon",
95
+ method: 'post',
96
+ data: {
97
+ apiKey: this._apiKey,
98
+ breezemoonContent: content
99
+ },
100
+ })];
101
+ case 1:
102
+ rsp = _a.sent();
103
+ return [2 /*return*/, rsp.data];
104
+ case 2:
105
+ e_2 = _a.sent();
106
+ throw e_2;
107
+ case 3: return [2 /*return*/];
108
+ }
109
+ });
110
+ });
111
+ };
112
+ return Breezemoon;
113
+ }());
114
+ exports.default = Breezemoon;
@@ -0,0 +1,66 @@
1
+ import ReconnectingWebSocket from 'reconnecting-websocket';
2
+ import { ApiResponse, ChatData } from './typing';
3
+ declare class Chat {
4
+ private _apiKey;
5
+ private _rwss;
6
+ private _wsCallbacks;
7
+ constructor(token?: string);
8
+ /**
9
+ * 重新设置请求 Token
10
+ * @param apiKey 接口 API Key
11
+ */
12
+ setToken(apiKey: string): void;
13
+ /**
14
+ * 获取有私聊用户列表第一条消息
15
+ * @returns 私聊消息列表
16
+ */
17
+ list(): Promise<ApiResponse<Array<ChatData>>>;
18
+ /**
19
+ * 获取用户私聊历史消息
20
+ * @param param 消息参数
21
+ * @returns 私聊消息列表
22
+ */
23
+ get(param: {
24
+ user: string;
25
+ page: 1;
26
+ size: 20;
27
+ autoRead: true;
28
+ }): Promise<ApiResponse<Array<ChatData>>>;
29
+ /**
30
+ * 标记用户消息已读
31
+ * @param user 用户名
32
+ * @returns 执行结果
33
+ */
34
+ markRead(user: string): Promise<ApiResponse<undefined>>;
35
+ /**
36
+ * 获取未读消息
37
+ * @returns 未读消息列表
38
+ */
39
+ unread(): Promise<ApiResponse<ChatData>>;
40
+ /**
41
+ * 移除聊天室消息监听函数
42
+ * @param user 指定用户消息监听函数,空为新信息监听
43
+ * @param wsCallback 要移除的函数,若为空,则清空消息监听
44
+ */
45
+ removeListener(user: string | undefined, wsCallback: Function): void;
46
+ /**
47
+ * 添加聊天室消息监听函数
48
+ * @param wsCallback 消息监听函数
49
+ * @param user 指定为用户消息监听函数,空为新信息监听
50
+ */
51
+ addListener(wsCallback: Function, user?: string): Promise<void>;
52
+ /**
53
+ * 连接用户私聊频道
54
+ * @param user 私聊用户名
55
+ * @returns Websocket 连接对象
56
+ */
57
+ connect(user: string): Promise<ReconnectingWebSocket>;
58
+ /**
59
+ *
60
+ * @param user 私聊用户名
61
+ * @param content 私聊内容
62
+ * @returns Websocket 连接对象
63
+ */
64
+ send(user: string, content: string): Promise<ReconnectingWebSocket>;
65
+ }
66
+ export default Chat;