@alemonjs/kook 0.2.2 → 0.2.3
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/lib/index.js +285 -284
- package/lib/sdk/core/config.js +40 -39
- package/lib/sdk/core/utils/from.js +32 -25
- package/lib/sdk/platform/kook/sdk/api.js +265 -262
- package/lib/sdk/platform/kook/sdk/config.js +4 -4
- package/lib/sdk/platform/kook/sdk/conversation.js +116 -108
- package/lib/sdk/platform/kook/sdk/message.js +16 -16
- package/lib/sdk/platform/kook/sdk/typings.js +164 -164
- package/lib/sdk/platform/kook/sdk/wss.js +145 -138
- package/package.json +14 -6
- package/lib/index.d.ts +0 -9
- package/lib/sdk/platform/kook/sdk/api.d.ts +0 -288
- package/lib/sdk/platform/kook/sdk/message/INTERACTION.d.ts +0 -8
- package/lib/sdk/platform/kook/sdk/message/MEMBER_ADD.d.ts +0 -10
- package/lib/sdk/platform/kook/sdk/message/MEMBER_REMOVE.d.ts +0 -10
- package/lib/sdk/platform/kook/sdk/message/MESSAGES_DIRECT.d.ts +0 -10
- package/lib/sdk/platform/kook/sdk/message/MESSAGES_PUBLIC.d.ts +0 -10
- package/lib/sdk/platform/kook/sdk/message/REACTIONS.d.ts +0 -10
- package/lib/sdk/platform/kook/sdk/message.d.ts +0 -18
- package/lib/sdk/platform/kook/sdk/typings.d.ts +0 -221
- package/lib/sdk/platform/kook/sdk/wss.d.ts +0 -26
- package/lib/sdk/platform/kook/sdk/wss.types.d.ts +0 -12
package/lib/index.js
CHANGED
|
@@ -1,291 +1,292 @@
|
|
|
1
|
-
import { defineBot, getConfigValue, useUserHashKey, OnProcessor } from 'alemonjs'
|
|
2
|
-
import 'fs'
|
|
3
|
-
import 'axios'
|
|
4
|
-
import 'path'
|
|
5
|
-
import 'qrcode'
|
|
6
|
-
import 'public-ip'
|
|
7
|
-
import 'stream'
|
|
8
|
-
import 'file-type'
|
|
9
|
-
import 'form-data'
|
|
10
|
-
import './sdk/platform/kook/sdk/typings.js'
|
|
11
|
-
import { KOOKClient } from './sdk/platform/kook/sdk/wss.js'
|
|
1
|
+
import { defineBot, getConfigValue, useUserHashKey, OnProcessor } from 'alemonjs';
|
|
2
|
+
import 'fs';
|
|
3
|
+
import 'axios';
|
|
4
|
+
import 'path';
|
|
5
|
+
import 'qrcode';
|
|
6
|
+
import 'public-ip';
|
|
7
|
+
import 'stream';
|
|
8
|
+
import 'file-type';
|
|
9
|
+
import 'form-data';
|
|
10
|
+
import './sdk/platform/kook/sdk/typings.js';
|
|
11
|
+
import { KOOKClient } from './sdk/platform/kook/sdk/wss.js';
|
|
12
12
|
|
|
13
|
-
const platform = 'kook'
|
|
14
|
-
const client = new Proxy(
|
|
15
|
-
{},
|
|
16
|
-
{
|
|
13
|
+
const platform = 'kook';
|
|
14
|
+
const client = new Proxy({}, {
|
|
17
15
|
get: (_, prop) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
if (prop in global.client) {
|
|
17
|
+
const original = global.client[prop];
|
|
18
|
+
// 防止函数内this丢失
|
|
19
|
+
return typeof original === 'function' ? original.bind(global.client) : original;
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
)
|
|
23
|
+
});
|
|
25
24
|
var index = defineBot(() => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
25
|
+
const value = getConfigValue();
|
|
26
|
+
const config = value[platform];
|
|
27
|
+
// 创建客户端
|
|
28
|
+
const client = new KOOKClient({
|
|
29
|
+
token: config.token
|
|
30
|
+
});
|
|
31
|
+
// 连接
|
|
32
|
+
client.connect();
|
|
33
|
+
client.on('MESSAGES_DIRECT', async (event) => {
|
|
34
|
+
// 过滤机器人
|
|
35
|
+
if (event.extra?.author?.bot)
|
|
36
|
+
return false;
|
|
37
|
+
// 主人
|
|
38
|
+
const master_key = config?.master_key ?? [];
|
|
39
|
+
const isMaster = master_key.includes(event.author_id);
|
|
40
|
+
// 头像
|
|
41
|
+
const avatar = event.extra.author.avatar;
|
|
42
|
+
// 获取消息
|
|
43
|
+
let msg = event.content;
|
|
44
|
+
const url = avatar.substring(0, avatar.indexOf('?'));
|
|
45
|
+
const UserAvatar = {
|
|
46
|
+
toBuffer: async () => {
|
|
47
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
48
|
+
return Buffer.from(arrayBuffer);
|
|
49
|
+
},
|
|
50
|
+
toBase64: async () => {
|
|
51
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
52
|
+
return Buffer.from(arrayBuffer).toString('base64');
|
|
53
|
+
},
|
|
54
|
+
toURL: async () => {
|
|
55
|
+
return url;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const UserId = event.author_id;
|
|
59
|
+
const UserKey = useUserHashKey({
|
|
60
|
+
Platform: platform,
|
|
61
|
+
UserId
|
|
62
|
+
});
|
|
63
|
+
// 定义消
|
|
64
|
+
const e = {
|
|
65
|
+
// 事件类型
|
|
66
|
+
Platform: platform,
|
|
67
|
+
// 用户Id
|
|
68
|
+
UserId: UserId,
|
|
69
|
+
UserKey,
|
|
70
|
+
UserName: event.extra.author.username,
|
|
71
|
+
UserAvatar: UserAvatar,
|
|
72
|
+
IsMaster: isMaster,
|
|
73
|
+
IsBot: false,
|
|
74
|
+
// message
|
|
75
|
+
MessageId: event.msg_id,
|
|
76
|
+
MessageText: msg,
|
|
77
|
+
OpenId: '',
|
|
78
|
+
CreateAt: Date.now(),
|
|
79
|
+
//
|
|
80
|
+
tag: 'MESSAGES_PUBLIC',
|
|
81
|
+
value: null
|
|
82
|
+
};
|
|
83
|
+
// 当访问的时候获取
|
|
84
|
+
Object.defineProperty(e, 'value', {
|
|
85
|
+
get() {
|
|
86
|
+
return event;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
// 处理消息
|
|
90
|
+
OnProcessor(e, 'private.message.create');
|
|
91
|
+
});
|
|
92
|
+
// 监听消息
|
|
93
|
+
client.on('MESSAGES_PUBLIC', async (event) => {
|
|
94
|
+
// 过滤机器人
|
|
95
|
+
if (event.extra?.author?.bot)
|
|
96
|
+
return false;
|
|
97
|
+
// 创建私聊标记
|
|
98
|
+
const data = await client.userChatCreate(event.extra.author.id).then(res => res?.data);
|
|
99
|
+
// 主人
|
|
100
|
+
const master_key = config?.master_key ?? [];
|
|
101
|
+
const isMaster = master_key.includes(event.author_id);
|
|
102
|
+
// 头像
|
|
103
|
+
const avatar = event.extra.author.avatar;
|
|
104
|
+
// 获取消息
|
|
105
|
+
let msg = event.content;
|
|
106
|
+
/**
|
|
107
|
+
* 艾特类型所得到的
|
|
108
|
+
* 包括机器人在内
|
|
109
|
+
*/
|
|
110
|
+
const mention_role_part = event.extra.kmarkdown?.mention_role_part ?? [];
|
|
111
|
+
for (const item of mention_role_part) {
|
|
112
|
+
msg = msg.replace(`(rol)${item.role_id}(rol)`, '').trim();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 艾特用户所得到的
|
|
116
|
+
*/
|
|
117
|
+
const mention_part = event.extra.kmarkdown?.mention_part ?? [];
|
|
118
|
+
for (const item of mention_part) {
|
|
119
|
+
msg = msg.replace(`(met)${item.id}(met)`, '').trim();
|
|
120
|
+
}
|
|
121
|
+
const url = avatar.substring(0, avatar.indexOf('?'));
|
|
122
|
+
const UserAvatar = {
|
|
123
|
+
toBuffer: async () => {
|
|
124
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
125
|
+
return Buffer.from(arrayBuffer);
|
|
126
|
+
},
|
|
127
|
+
toBase64: async () => {
|
|
128
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
129
|
+
return Buffer.from(arrayBuffer).toString('base64');
|
|
130
|
+
},
|
|
131
|
+
toURL: async () => {
|
|
132
|
+
return url;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const UserId = event.author_id;
|
|
136
|
+
const UserKey = useUserHashKey({
|
|
137
|
+
Platform: platform,
|
|
138
|
+
UserId
|
|
139
|
+
});
|
|
140
|
+
// 定义消
|
|
141
|
+
const e = {
|
|
142
|
+
// 事件类型
|
|
143
|
+
Platform: platform,
|
|
144
|
+
//
|
|
145
|
+
GuildId: event.extra.guild_id,
|
|
146
|
+
ChannelId: event.target_id,
|
|
147
|
+
// 用户Id
|
|
148
|
+
UserId: UserId,
|
|
149
|
+
UserKey,
|
|
150
|
+
UserName: event.extra.author.username,
|
|
151
|
+
UserAvatar: UserAvatar,
|
|
152
|
+
IsMaster: isMaster,
|
|
153
|
+
IsBot: false,
|
|
154
|
+
// message
|
|
155
|
+
MessageId: event.msg_id,
|
|
156
|
+
MessageText: msg,
|
|
157
|
+
OpenId: data?.code,
|
|
158
|
+
CreateAt: Date.now(),
|
|
159
|
+
//
|
|
160
|
+
tag: 'MESSAGES_PUBLIC',
|
|
161
|
+
value: null
|
|
162
|
+
};
|
|
163
|
+
// 当访问的时候获取
|
|
164
|
+
Object.defineProperty(e, 'value', {
|
|
165
|
+
get() {
|
|
166
|
+
return event;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
// 处理消息
|
|
170
|
+
OnProcessor(e, 'message.create');
|
|
171
|
+
});
|
|
172
|
+
// 发送错误时
|
|
173
|
+
client.on('ERROR', msg => {
|
|
174
|
+
console.error(msg);
|
|
175
|
+
});
|
|
176
|
+
// 客户端全局化。
|
|
177
|
+
global.client = client;
|
|
178
|
+
return {
|
|
179
|
+
api: {
|
|
180
|
+
use: {
|
|
181
|
+
send: (event, val) => {
|
|
182
|
+
if (val.length < 0)
|
|
183
|
+
return Promise.all([]);
|
|
184
|
+
const content = val
|
|
185
|
+
.filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
|
|
186
|
+
.map(item => {
|
|
187
|
+
if (item.type == 'Link') {
|
|
188
|
+
return `[${item.options?.title ?? item.value}](${item.value})`;
|
|
189
|
+
}
|
|
190
|
+
else if (item.type == 'Mention') {
|
|
191
|
+
if (item.value == 'everyone' ||
|
|
192
|
+
item.value == 'all' ||
|
|
193
|
+
item.value == '' ||
|
|
194
|
+
typeof item.value != 'string') {
|
|
195
|
+
return `(met)all(met)`;
|
|
196
|
+
}
|
|
197
|
+
if (item.options?.belong == 'user') {
|
|
198
|
+
return `(met)${item.value}(met)`;
|
|
199
|
+
}
|
|
200
|
+
else if (item.options?.belong == 'channel') {
|
|
201
|
+
return `(chn)${item.value}(chn)`;
|
|
202
|
+
}
|
|
203
|
+
return '';
|
|
204
|
+
}
|
|
205
|
+
else if (item.type == 'Text') {
|
|
206
|
+
if (item.options?.style == 'block') {
|
|
207
|
+
return `\`${item.value}\``;
|
|
208
|
+
}
|
|
209
|
+
else if (item.options?.style == 'italic') {
|
|
210
|
+
return `*${item.value}*`;
|
|
211
|
+
}
|
|
212
|
+
else if (item.options?.style == 'bold') {
|
|
213
|
+
return `**${item.value}**`;
|
|
214
|
+
}
|
|
215
|
+
else if (item.options?.style == 'strikethrough') {
|
|
216
|
+
return `~~${item.value}~~`;
|
|
217
|
+
}
|
|
218
|
+
else if (item.options?.style == 'boldItalic') {
|
|
219
|
+
return `***${item.value}***`;
|
|
220
|
+
}
|
|
221
|
+
return item.value;
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
.join('');
|
|
225
|
+
if (content) {
|
|
226
|
+
return Promise.all([content].map(item => client.createMessage({
|
|
227
|
+
type: 9,
|
|
228
|
+
target_id: event.ChannelId,
|
|
229
|
+
content: item
|
|
230
|
+
})));
|
|
231
|
+
}
|
|
232
|
+
const images = val.filter(item => item.type == 'Image').map(item => item.value);
|
|
233
|
+
if (images) {
|
|
234
|
+
return Promise.all(images.map(async (item) => {
|
|
235
|
+
// 上传图片
|
|
236
|
+
const res = await client.postImage(item);
|
|
237
|
+
if (!res)
|
|
238
|
+
return Promise.resolve();
|
|
239
|
+
// 发送消息
|
|
240
|
+
return await client.createMessage({
|
|
241
|
+
type: 2,
|
|
242
|
+
target_id: event.ChannelId,
|
|
243
|
+
content: res.data.url
|
|
244
|
+
});
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
return Promise.all([]);
|
|
248
|
+
},
|
|
249
|
+
mention: async (e) => {
|
|
250
|
+
const event = e.value;
|
|
251
|
+
const MessageMention = [];
|
|
252
|
+
/**
|
|
253
|
+
* 艾特类型所得到的,包括机器人在内
|
|
254
|
+
*/
|
|
255
|
+
const mention_role_part = event.extra.kmarkdown?.mention_role_part ?? [];
|
|
256
|
+
for (const item of mention_role_part) {
|
|
257
|
+
MessageMention.push({
|
|
258
|
+
UserId: item.role_id,
|
|
259
|
+
UserName: item.name,
|
|
260
|
+
UserKey: useUserHashKey({
|
|
261
|
+
Platform: platform,
|
|
262
|
+
UserId: item.role_id
|
|
263
|
+
}),
|
|
264
|
+
IsMaster: false,
|
|
265
|
+
IsBot: true
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* 艾特用户所得到的
|
|
270
|
+
*/
|
|
271
|
+
const mention_part = event.extra.kmarkdown?.mention_part ?? [];
|
|
272
|
+
for (const item of mention_part) {
|
|
273
|
+
MessageMention.push({
|
|
274
|
+
// avatar: item.avatar,
|
|
275
|
+
UserId: item.id,
|
|
276
|
+
UserName: item.username,
|
|
277
|
+
UserKey: useUserHashKey({
|
|
278
|
+
Platform: platform,
|
|
279
|
+
UserId: item.role_id
|
|
280
|
+
}),
|
|
281
|
+
IsMaster: false,
|
|
282
|
+
IsBot: false
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
return MessageMention;
|
|
214
286
|
}
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
})
|
|
218
|
-
.join('')
|
|
219
|
-
if (content) {
|
|
220
|
-
return Promise.all(
|
|
221
|
-
[content].map(item =>
|
|
222
|
-
client.createMessage({
|
|
223
|
-
type: 9,
|
|
224
|
-
target_id: event.ChannelId,
|
|
225
|
-
content: item
|
|
226
|
-
})
|
|
227
|
-
)
|
|
228
|
-
)
|
|
229
|
-
}
|
|
230
|
-
const images = val.filter(item => item.type == 'Image').map(item => item.value)
|
|
231
|
-
if (images) {
|
|
232
|
-
return Promise.all(
|
|
233
|
-
images.map(async item => {
|
|
234
|
-
// 上传图片
|
|
235
|
-
const res = await client.postImage(item)
|
|
236
|
-
if (!res) return Promise.resolve()
|
|
237
|
-
// 发送消息
|
|
238
|
-
return await client.createMessage({
|
|
239
|
-
type: 2,
|
|
240
|
-
target_id: event.ChannelId,
|
|
241
|
-
content: res.data.url
|
|
242
|
-
})
|
|
243
|
-
})
|
|
244
|
-
)
|
|
245
|
-
}
|
|
246
|
-
return Promise.all([])
|
|
247
|
-
},
|
|
248
|
-
mention: async e => {
|
|
249
|
-
const event = e.value
|
|
250
|
-
const MessageMention = []
|
|
251
|
-
/**
|
|
252
|
-
* 艾特类型所得到的,包括机器人在内
|
|
253
|
-
*/
|
|
254
|
-
const mention_role_part = event.extra.kmarkdown?.mention_role_part ?? []
|
|
255
|
-
for (const item of mention_role_part) {
|
|
256
|
-
MessageMention.push({
|
|
257
|
-
UserId: item.role_id,
|
|
258
|
-
UserName: item.name,
|
|
259
|
-
UserKey: useUserHashKey({
|
|
260
|
-
Platform: platform,
|
|
261
|
-
UserId: item.role_id
|
|
262
|
-
}),
|
|
263
|
-
IsMaster: false,
|
|
264
|
-
IsBot: true
|
|
265
|
-
})
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* 艾特用户所得到的
|
|
269
|
-
*/
|
|
270
|
-
const mention_part = event.extra.kmarkdown?.mention_part ?? []
|
|
271
|
-
for (const item of mention_part) {
|
|
272
|
-
MessageMention.push({
|
|
273
|
-
// avatar: item.avatar,
|
|
274
|
-
UserId: item.id,
|
|
275
|
-
UserName: item.username,
|
|
276
|
-
UserKey: useUserHashKey({
|
|
277
|
-
Platform: platform,
|
|
278
|
-
UserId: item.role_id
|
|
279
|
-
}),
|
|
280
|
-
IsMaster: false,
|
|
281
|
-
IsBot: false
|
|
282
|
-
})
|
|
283
|
-
}
|
|
284
|
-
return MessageMention
|
|
287
|
+
}
|
|
285
288
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
})
|
|
289
|
+
};
|
|
290
|
+
});
|
|
290
291
|
|
|
291
|
-
export { client, index as default, platform }
|
|
292
|
+
export { client, index as default, platform };
|
package/lib/sdk/core/config.js
CHANGED
|
@@ -2,44 +2,45 @@
|
|
|
2
2
|
* 基础配置结构
|
|
3
3
|
*/
|
|
4
4
|
class BaseConfig {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
5
|
+
#data = null;
|
|
6
|
+
constructor(val) {
|
|
7
|
+
this.#data = val;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 设置配置
|
|
11
|
+
* @param key
|
|
12
|
+
* @param val
|
|
13
|
+
*/
|
|
14
|
+
set(key, val) {
|
|
15
|
+
if (val !== undefined)
|
|
16
|
+
this.#data[key] = val;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param key
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
has(key) {
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(this.#data, key)) ;
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 读取配置
|
|
30
|
+
* @param key
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
all() {
|
|
34
|
+
return this.#data;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 读取配置
|
|
38
|
+
* @param key
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
get(key) {
|
|
42
|
+
return this.#data[key];
|
|
43
|
+
}
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
export { BaseConfig }
|
|
46
|
+
export { BaseConfig };
|