onebots 0.4.47 → 0.4.49

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.
Files changed (42) hide show
  1. package/dist/assets/{index-yG7HG4Oa.css → index-2tNhvoZy.css} +1 -1
  2. package/dist/assets/index-_Kz1yWe8.js +19 -0
  3. package/dist/index.html +2 -2
  4. package/lib/adapter.js +6 -8
  5. package/lib/adapters/dingtalk/index.d.ts +4 -4
  6. package/lib/adapters/dingtalk/index.js +56 -49
  7. package/lib/adapters/dingtalk/utils.js +5 -20
  8. package/lib/adapters/icqq/index.d.ts +5 -3
  9. package/lib/adapters/icqq/index.js +134 -101
  10. package/lib/adapters/icqq/utils.js +2 -2
  11. package/lib/adapters/qq/index.d.ts +4 -4
  12. package/lib/adapters/qq/index.js +63 -52
  13. package/lib/adapters/qq/utils.js +5 -20
  14. package/lib/adapters/wechat/index.d.ts +3 -3
  15. package/lib/adapters/wechat/index.js +63 -52
  16. package/lib/adapters/wechat/utils.js +5 -20
  17. package/lib/bin.js +6 -6
  18. package/lib/db.js +10 -10
  19. package/lib/onebot.d.ts +12 -12
  20. package/lib/onebot.js +25 -16
  21. package/lib/server/app.d.ts +2 -2
  22. package/lib/server/app.js +71 -70
  23. package/lib/server/router.d.ts +1 -1
  24. package/lib/server/router.js +5 -5
  25. package/lib/service/V11/action/common.d.ts +1 -0
  26. package/lib/service/V11/action/common.js +24 -24
  27. package/lib/service/V11/action/friend.js +16 -8
  28. package/lib/service/V11/action/group.js +52 -22
  29. package/lib/service/V11/index.js +86 -50
  30. package/lib/service/V12/action/common.d.ts +3 -3
  31. package/lib/service/V12/action/common.js +33 -31
  32. package/lib/service/V12/action/friend.js +8 -4
  33. package/lib/service/V12/action/group.js +50 -20
  34. package/lib/service/V12/action/guild.js +110 -35
  35. package/lib/service/V12/index.d.ts +18 -18
  36. package/lib/service/V12/index.js +189 -147
  37. package/lib/service/shareMusicCustom.js +14 -9
  38. package/lib/service.js +29 -27
  39. package/lib/utils.d.ts +1 -1
  40. package/lib/utils.js +44 -32
  41. package/package.json +1 -1
  42. package/dist/assets/index-YN4djyjB.js +0 -19
@@ -14,12 +14,12 @@ async function buildMusic(target, bu, music) {
14
14
  const { appid, package_name, sign, getMusicInfo } = message_1.musicFactory[music.platform];
15
15
  let style = 4;
16
16
  try {
17
- let { singer = null, title = null, jumpUrl = null, musicUrl = null, preview = null } = music.id ? await getMusicInfo(music.id) : {};
18
- singer = music['content'] || music.singer || singer; // 自定义参数优先级高于默认值(gocq的参数名与icqq有区别,做下兼容)
17
+ let { singer = null, title = null, jumpUrl = null, musicUrl = null, preview = null, } = music.id ? await getMusicInfo(music.id) : {};
18
+ singer = music["content"] || music.singer || singer; // 自定义参数优先级高于默认值(gocq的参数名与icqq有区别,做下兼容)
19
19
  title = music.title || title;
20
- jumpUrl = music.jumpUrl || music['url'] || jumpUrl;
21
- musicUrl = music['voice'] || music['url'] || music.musicUrl || musicUrl;
22
- preview = music['image'] || music.preview || preview;
20
+ jumpUrl = music.jumpUrl || music["url"] || jumpUrl;
21
+ musicUrl = music["voice"] || music["url"] || music.musicUrl || musicUrl;
22
+ preview = music["image"] || music.preview || preview;
23
23
  if (!musicUrl)
24
24
  style = 0;
25
25
  return {
@@ -30,9 +30,9 @@ async function buildMusic(target, bu, music) {
30
30
  1: 1,
31
31
  2: "0.0.0",
32
32
  3: package_name,
33
- 4: sign
33
+ 4: sign,
34
34
  },
35
- 10: typeof bu === 'string' ? 3 : bu,
35
+ 10: typeof bu === "string" ? 3 : bu,
36
36
  11: target,
37
37
  12: {
38
38
  10: title,
@@ -42,11 +42,16 @@ async function buildMusic(target, bu, music) {
42
42
  14: preview,
43
43
  16: musicUrl,
44
44
  },
45
- 19: typeof bu === 'string' ? Number(bu) : undefined
45
+ 19: typeof bu === "string" ? Number(bu) : undefined,
46
46
  };
47
47
  }
48
48
  catch (e) {
49
- throw new Error("unknown music id: " + music.id + ", in platform: " + music.platform + ", with title: " + process_1.title);
49
+ throw new Error("unknown music id: " +
50
+ music.id +
51
+ ", in platform: " +
52
+ music.platform +
53
+ ", with title: " +
54
+ process_1.title);
50
55
  }
51
56
  }
52
57
  exports.buildMusic = buildMusic;
package/lib/service.js CHANGED
@@ -18,59 +18,61 @@ exports.Service = Service;
18
18
  function createFilterFunction(filters) {
19
19
  const isLogicKey = (key) => {
20
20
  return [
21
- '$and',
22
- '$or',
23
- '$not',
24
- '$nor',
25
- '$regexp',
26
- '$like',
27
- '$gt',
28
- '$gte',
29
- '$lt',
30
- '$lte',
31
- '$between',
21
+ "$and",
22
+ "$or",
23
+ "$not",
24
+ "$nor",
25
+ "$regexp",
26
+ "$like",
27
+ "$gt",
28
+ "$gte",
29
+ "$lt",
30
+ "$lte",
31
+ "$between",
32
32
  ].includes(key);
33
33
  };
34
34
  const filterFn = (event, key, value) => {
35
35
  // 如果 key 为 $and、$or、$not、$nor 则递归调用
36
- if (key === "$and" || key === "$or" || key === "$not" || key === '$nor') {
37
- if (!value || typeof value !== 'object')
36
+ if (key === "$and" || key === "$or" || key === "$not" || key === "$nor") {
37
+ if (!value || typeof value !== "object")
38
38
  throw new Error("invalid filter");
39
39
  switch (key) {
40
40
  case "$and":
41
- return Array.isArray(value) ? value.every((item) => filterFn(event, key, item)) :
42
- Object.entries(value).every(([key, value]) => filterFn(event, key, value));
41
+ return Array.isArray(value)
42
+ ? value.every(item => filterFn(event, key, item))
43
+ : Object.entries(value).every(([key, value]) => filterFn(event, key, value));
43
44
  case "$or":
44
- return Array.isArray(value) ? value.some((item) => filterFn(event, key, item)) :
45
- Object.entries(value).some(([key, value]) => filterFn(event, key, value));
45
+ return Array.isArray(value)
46
+ ? value.some(item => filterFn(event, key, item))
47
+ : Object.entries(value).some(([key, value]) => filterFn(event, key, value));
46
48
  case "$nor":
47
- return !filterFn(event, '$or', value);
49
+ return !filterFn(event, "$or", value);
48
50
  case "$not":
49
- return !filterFn(event, '$and', value);
51
+ return !filterFn(event, "$and", value);
50
52
  }
51
53
  }
52
54
  if (typeof value === "boolean" && typeof event[key] !== "boolean") {
53
55
  return value;
54
56
  }
55
57
  if (typeof value !== "object") {
56
- if (key === '$regex' && typeof value === 'string')
58
+ if (key === "$regex" && typeof value === "string")
57
59
  return new RegExp(value).test(String(event));
58
- if (key === '$like' && typeof value === 'string')
60
+ if (key === "$like" && typeof value === "string")
59
61
  return String(event).includes(value);
60
- if (key === '$gt' && typeof value === 'number')
62
+ if (key === "$gt" && typeof value === "number")
61
63
  return Number(event) > value;
62
- if (key === '$gte' && typeof value === 'number')
64
+ if (key === "$gte" && typeof value === "number")
63
65
  return Number(event) >= value;
64
- if (key === '$lt' && typeof value === 'number')
66
+ if (key === "$lt" && typeof value === "number")
65
67
  return Number(event) < value;
66
- if (key === '$lte' && typeof value === 'number')
68
+ if (key === "$lte" && typeof value === "number")
67
69
  return Number(event) <= value;
68
70
  return value === event[key];
69
71
  }
70
- if (key === '$between' &&
72
+ if (key === "$between" &&
71
73
  Array.isArray(value) &&
72
74
  value.length === 2 &&
73
- value.every((item) => typeof item === 'number')) {
75
+ value.every(item => typeof item === "number")) {
74
76
  const [start, end] = value;
75
77
  return event >= start && event <= end;
76
78
  }
package/lib/utils.d.ts CHANGED
@@ -25,7 +25,7 @@ export declare function toBool(v: any): boolean;
25
25
  export declare function uuid(): string;
26
26
  export declare function randomInt(max: number): number;
27
27
  export declare function randomInt(min: number, max: number): number;
28
- export declare function protectedFields<T>(source: T, ...keys: ((keyof T) | string)[]): T;
28
+ export declare function protectedFields<T>(source: T, ...keys: (keyof T | string)[]): T;
29
29
  export declare function getProperties(obj: any): any;
30
30
  export declare function setValueToObj(obj: Dict, keys: string[], value: any): boolean;
31
31
  export declare function setValueToObj(obj: Dict, key: string, value: any): boolean;
package/lib/utils.js CHANGED
@@ -27,24 +27,24 @@ exports.stringifyObj = exports.parseObjFromStr = exports.getDataKeyOfObj = expor
27
27
  const crypto = __importStar(require("crypto"));
28
28
  const fs = __importStar(require("fs"));
29
29
  const readline = __importStar(require("readline"));
30
- const packageJson = require('../package.json');
30
+ const packageJson = require("../package.json");
31
31
  exports.version = packageJson.version;
32
32
  function readLine(maxLen, ...params) {
33
33
  return new Promise((resolve, reject) => {
34
34
  const result = [];
35
35
  const rl = readline.createInterface({
36
36
  input: fs.createReadStream(...params),
37
- crlfDelay: Infinity
37
+ crlfDelay: Infinity,
38
38
  });
39
- rl.on('line', (line) => {
39
+ rl.on("line", line => {
40
40
  result.push(line);
41
41
  if (result.length > maxLen)
42
42
  result.shift();
43
43
  });
44
- rl.on('close', () => {
45
- resolve(result.join('\n'));
44
+ rl.on("close", () => {
45
+ resolve(result.join("\n"));
46
46
  });
47
- rl.on('error', reject);
47
+ rl.on("error", reject);
48
48
  });
49
49
  }
50
50
  exports.readLine = readLine;
@@ -55,7 +55,7 @@ function deepMerge(base, ...from) {
55
55
  if (from.length === 0) {
56
56
  return base;
57
57
  }
58
- if (typeof base !== 'object') {
58
+ if (typeof base !== "object") {
59
59
  return base;
60
60
  }
61
61
  if (Array.isArray(base)) {
@@ -64,7 +64,7 @@ function deepMerge(base, ...from) {
64
64
  for (const item of from) {
65
65
  for (const key in item) {
66
66
  if (base.hasOwnProperty(key)) {
67
- if (typeof base[key] === 'object') {
67
+ if (typeof base[key] === "object") {
68
68
  base[key] = deepMerge(base[key], item[key]);
69
69
  }
70
70
  else {
@@ -84,7 +84,7 @@ function transformObj(obj, callback) {
84
84
  return obj;
85
85
  if (Array.isArray(obj))
86
86
  return obj.map(item => transformObj(item, callback));
87
- if (typeof obj !== 'object')
87
+ if (typeof obj !== "object")
88
88
  return obj;
89
89
  return Object.fromEntries(Object.keys(obj).map(key => {
90
90
  return [key, callback(key, obj[key])];
@@ -93,13 +93,13 @@ function transformObj(obj, callback) {
93
93
  exports.transformObj = transformObj;
94
94
  // 深拷贝
95
95
  function deepClone(obj) {
96
- if (typeof obj !== 'object')
96
+ if (typeof obj !== "object")
97
97
  return obj;
98
98
  if (!obj)
99
99
  return obj;
100
100
  //判断拷贝的obj是对象还是数组
101
101
  if (Array.isArray(obj))
102
- return obj.map((item) => deepClone(item));
102
+ return obj.map(item => deepClone(item));
103
103
  const objClone = {};
104
104
  for (const key in obj) {
105
105
  if (obj.hasOwnProperty(key)) {
@@ -148,7 +148,7 @@ exports.toLine = toLine;
148
148
  function Mixin(base, ...classes) {
149
149
  classes.forEach(ctr => {
150
150
  Object.getOwnPropertyNames(ctr.prototype).forEach(name => {
151
- if (name === 'constructor')
151
+ if (name === "constructor")
152
152
  return;
153
153
  base.prototype[name] = ctr.prototype[name];
154
154
  });
@@ -157,7 +157,7 @@ function Mixin(base, ...classes) {
157
157
  }
158
158
  exports.Mixin = Mixin;
159
159
  function toHump(action) {
160
- return action.replace(/_[\w]/g, (s) => {
160
+ return action.replace(/_[\w]/g, s => {
161
161
  return s[1].toUpperCase();
162
162
  });
163
163
  }
@@ -176,40 +176,52 @@ function toBool(v) {
176
176
  exports.toBool = toBool;
177
177
  function uuid() {
178
178
  let hex = crypto.randomBytes(16).toString("hex");
179
- return hex.substr(0, 8) + "-" + hex.substr(8, 4) + "-" + hex.substr(12, 4) + "-" + hex.substr(16, 4) + "-" + hex.substr(20);
179
+ return (hex.substr(0, 8) +
180
+ "-" +
181
+ hex.substr(8, 4) +
182
+ "-" +
183
+ hex.substr(12, 4) +
184
+ "-" +
185
+ hex.substr(16, 4) +
186
+ "-" +
187
+ hex.substr(20));
180
188
  }
181
189
  exports.uuid = uuid;
182
190
  function randomInt(...args) {
183
191
  let min = args[0] || 0, max = args[1];
184
192
  if (args.length === 1)
185
- max = min, min = 0;
193
+ (max = min), (min = 0);
186
194
  return Math.floor(Math.random() * (max - min) + min);
187
195
  }
188
196
  exports.randomInt = randomInt;
189
197
  function protectedFields(source, ...keys) {
190
- const protocolValue = (value) => {
191
- if (value && typeof value === 'object')
198
+ const protocolValue = value => {
199
+ if (value && typeof value === "object")
192
200
  return Object.fromEntries(Object.entries(value).map(([key, value]) => {
193
201
  return [key, protocolValue(value)];
194
202
  }));
195
- return `${value}`.split('').map(() => '*').join('');
203
+ return `${value}`
204
+ .split("")
205
+ .map(() => "*")
206
+ .join("");
196
207
  };
197
- if (!source || typeof source !== 'object')
198
- throw new Error('source must is object');
208
+ if (!source || typeof source !== "object")
209
+ throw new Error("source must is object");
199
210
  return Object.fromEntries(Object.entries(source).map(([key, value]) => {
200
211
  return [key, keys.includes(key) ? protocolValue(value) : value];
201
212
  }));
202
213
  }
203
214
  exports.protectedFields = protectedFields;
204
215
  function getProperties(obj) {
205
- if (obj.__proto__ === null) { //说明该对象已经是最顶层的对象
216
+ if (obj.__proto__ === null) {
217
+ //说明该对象已经是最顶层的对象
206
218
  return [];
207
219
  }
208
220
  return Object.getOwnPropertyNames(obj).concat(getProperties(obj.__proto__));
209
221
  }
210
222
  exports.getProperties = getProperties;
211
223
  function setValueToObj(obj, key, value) {
212
- const keys = Array.isArray(key) ? key : key.split('.').filter(Boolean);
224
+ const keys = Array.isArray(key) ? key : key.split(".").filter(Boolean);
213
225
  const lastKey = keys.pop();
214
226
  if (!lastKey)
215
227
  throw new SyntaxError(`key is empty`);
@@ -223,7 +235,7 @@ function setValueToObj(obj, key, value) {
223
235
  }
224
236
  exports.setValueToObj = setValueToObj;
225
237
  function getValueOfObj(obj, key) {
226
- const keys = Array.isArray(key) ? key : key.split('.').filter(Boolean);
238
+ const keys = Array.isArray(key) ? key : key.split(".").filter(Boolean);
227
239
  const lastKey = keys.pop();
228
240
  if (!lastKey)
229
241
  throw new SyntaxError(`key is empty`);
@@ -240,8 +252,8 @@ function getDataKeyOfObj(data, obj) {
240
252
  const _get = (data, obj, prefix) => {
241
253
  for (const [key, value] of Object.entries(obj)) {
242
254
  if (value === data)
243
- return [...prefix, key].join('.');
244
- if (!value || typeof value !== 'object')
255
+ return [...prefix, key].join(".");
256
+ if (!value || typeof value !== "object")
245
257
  continue;
246
258
  const result = _get(data, value, prefix);
247
259
  if (result)
@@ -256,9 +268,9 @@ function parseObjFromStr(str) {
256
268
  const format = (data, keys) => {
257
269
  if (!data)
258
270
  return;
259
- if (typeof data !== 'object' && typeof data !== 'string')
271
+ if (typeof data !== "object" && typeof data !== "string")
260
272
  return;
261
- if (typeof data === 'object')
273
+ if (typeof data === "object")
262
274
  return Object.entries(data).map(([k, v]) => format(v, [...keys, k]));
263
275
  if (/\[Function:.+]/.test(data))
264
276
  return setValueToObj(result, [...keys], new Function(`return (${data.slice(10, -1)})`)());
@@ -270,19 +282,19 @@ function parseObjFromStr(str) {
270
282
  }
271
283
  exports.parseObjFromStr = parseObjFromStr;
272
284
  function stringifyObj(value) {
273
- if (!value || typeof value !== 'object')
285
+ if (!value || typeof value !== "object")
274
286
  return value;
275
287
  if (Array.isArray(value))
276
288
  return `[${value.map(stringifyObj).join()}]`;
277
289
  let result = { ...value }, cache = new WeakMap();
278
290
  const _stringify = (obj, prefix) => {
279
291
  for (const key of Reflect.ownKeys(obj)) {
280
- if (typeof key === 'symbol')
292
+ if (typeof key === "symbol")
281
293
  continue;
282
294
  const val = Reflect.get(obj, key);
283
- if (!val || typeof val !== 'object') {
284
- if (typeof val === 'function') {
285
- setValueToObj(result, [...prefix, String(key)], `[Function:${(val + '').replace(/\n/g, '')}]`);
295
+ if (!val || typeof val !== "object") {
296
+ if (typeof val === "function") {
297
+ setValueToObj(result, [...prefix, String(key)], `[Function:${(val + "").replace(/\n/g, "")}]`);
286
298
  continue;
287
299
  }
288
300
  setValueToObj(result, [...prefix, String(key)], val);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.4.47",
3
+ "version": "0.4.49",
4
4
  "description": "基于icqq的多例oneBot实现",
5
5
  "engines": {
6
6
  "node": ">=16"