onebots 0.4.23 → 0.4.26

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 (77) hide show
  1. package/README.md +25 -3
  2. package/lib/adapter.d.ts +55 -0
  3. package/lib/adapter.js +60 -0
  4. package/lib/adapters/icqq/index.d.ts +36 -0
  5. package/lib/adapters/icqq/index.js +300 -0
  6. package/lib/adapters/qq/bot.d.ts +22 -0
  7. package/lib/adapters/qq/bot.js +20 -0
  8. package/lib/adapters/qq/constans.d.ts +69 -0
  9. package/lib/adapters/qq/constans.js +128 -0
  10. package/lib/adapters/qq/elements.d.ts +125 -0
  11. package/lib/adapters/qq/elements.js +8 -0
  12. package/lib/adapters/qq/entries/channel.d.ts +17 -0
  13. package/lib/adapters/qq/entries/channel.js +2 -0
  14. package/lib/adapters/qq/entries/friend.d.ts +8 -0
  15. package/lib/adapters/qq/entries/friend.js +2 -0
  16. package/lib/adapters/qq/entries/group.d.ts +6 -0
  17. package/lib/adapters/qq/entries/group.js +2 -0
  18. package/lib/adapters/qq/entries/groupMember.d.ts +7 -0
  19. package/lib/adapters/qq/entries/groupMember.js +2 -0
  20. package/lib/adapters/qq/entries/guild.d.ts +21 -0
  21. package/lib/adapters/qq/entries/guild.js +2 -0
  22. package/lib/adapters/qq/entries/guildMember.d.ts +9 -0
  23. package/lib/adapters/qq/entries/guildMember.js +2 -0
  24. package/lib/adapters/qq/entries/user.d.ts +9 -0
  25. package/lib/adapters/qq/entries/user.js +2 -0
  26. package/lib/adapters/qq/event.d.ts +28 -0
  27. package/lib/adapters/qq/event.js +24 -0
  28. package/lib/adapters/qq/index.d.ts +35 -0
  29. package/lib/adapters/qq/index.js +172 -0
  30. package/lib/adapters/qq/message.d.ts +84 -0
  31. package/lib/adapters/qq/message.js +272 -0
  32. package/lib/adapters/qq/qqBot.d.ts +122 -0
  33. package/lib/adapters/qq/qqBot.js +440 -0
  34. package/lib/adapters/qq/sessionManager.d.ts +33 -0
  35. package/lib/adapters/qq/sessionManager.js +257 -0
  36. package/lib/adapters/qq/types.d.ts +45 -0
  37. package/lib/adapters/qq/types.js +2 -0
  38. package/lib/adapters/qq/utils.d.ts +12 -0
  39. package/lib/adapters/qq/utils.js +86 -0
  40. package/lib/bin.js +17 -2
  41. package/lib/config.sample.yaml +23 -5
  42. package/lib/onebot.d.ts +32 -24
  43. package/lib/onebot.js +51 -188
  44. package/lib/server/app.d.ts +22 -12
  45. package/lib/server/app.js +97 -71
  46. package/lib/service/V11/action/common.d.ts +9 -11
  47. package/lib/service/V11/action/common.js +27 -64
  48. package/lib/service/V11/action/friend.d.ts +5 -13
  49. package/lib/service/V11/action/friend.js +6 -16
  50. package/lib/service/V11/action/group.d.ts +19 -22
  51. package/lib/service/V11/action/group.js +20 -30
  52. package/lib/service/V11/action/index.d.ts +1 -1
  53. package/lib/service/V11/db_entities.d.ts +1 -1
  54. package/lib/service/V11/db_entities.js +1 -1
  55. package/lib/service/V11/db_sqlite.d.ts +1 -1
  56. package/lib/service/V11/index.d.ts +47 -16
  57. package/lib/service/V11/index.js +143 -164
  58. package/lib/service/V12/action/common.d.ts +3 -67
  59. package/lib/service/V12/action/common.js +9 -63
  60. package/lib/service/V12/action/friend.d.ts +4 -10
  61. package/lib/service/V12/action/friend.js +4 -12
  62. package/lib/service/V12/action/group.d.ts +19 -21
  63. package/lib/service/V12/action/group.js +19 -27
  64. package/lib/service/V12/action/guild.d.ts +40 -13
  65. package/lib/service/V12/action/guild.js +99 -11
  66. package/lib/service/V12/action/index.d.ts +1 -1
  67. package/lib/service/V12/index.d.ts +37 -13
  68. package/lib/service/V12/index.js +44 -72
  69. package/lib/service.d.ts +7 -2
  70. package/lib/service.js +32 -30
  71. package/lib/utils.d.ts +7 -4
  72. package/lib/utils.js +33 -28
  73. package/package.json +5 -4
  74. package/lib/service/V12/utils.d.ts +0 -8
  75. package/lib/service/V12/utils.js +0 -47
  76. /package/lib/{service/V11 → adapters/icqq}/utils.d.ts +0 -0
  77. /package/lib/{service/V11 → adapters/icqq}/utils.js +0 -0
package/lib/utils.js CHANGED
@@ -22,10 +22,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getProperties = exports.protectedFields = exports.uuid = exports.toBool = exports.remove = exports.toHump = exports.Mixin = exports.toLine = exports.omit = exports.pick = exports.deepClone = exports.transformObj = exports.deepMerge = exports.version = void 0;
29
+ exports.getProperties = exports.protectedFields = exports.uuid = exports.toBool = exports.remove = exports.toHump = exports.Mixin = exports.toLine = exports.randomId = exports.omit = exports.pick = exports.deepClone = exports.transformObj = exports.deepMerge = exports.version = void 0;
27
30
  const crypto = __importStar(require("crypto"));
28
- const packageJson = require("../package.json");
31
+ const seed_random_1 = __importDefault(require("seed-random"));
32
+ const packageJson = require('../package.json');
29
33
  exports.version = packageJson.version;
30
34
  // 合并对象/数组
31
35
  function deepMerge(base, ...from) {
@@ -34,7 +38,7 @@ function deepMerge(base, ...from) {
34
38
  if (from.length === 0) {
35
39
  return base;
36
40
  }
37
- if (typeof base !== "object") {
41
+ if (typeof base !== 'object') {
38
42
  return base;
39
43
  }
40
44
  if (Array.isArray(base)) {
@@ -43,7 +47,7 @@ function deepMerge(base, ...from) {
43
47
  for (const item of from) {
44
48
  for (const key in item) {
45
49
  if (base.hasOwnProperty(key)) {
46
- if (typeof base[key] === "object") {
50
+ if (typeof base[key] === 'object') {
47
51
  base[key] = deepMerge(base[key], item[key]);
48
52
  }
49
53
  else {
@@ -63,7 +67,7 @@ function transformObj(obj, callback) {
63
67
  return obj;
64
68
  if (Array.isArray(obj))
65
69
  return obj.map(item => transformObj(item, callback));
66
- if (typeof obj !== "object")
70
+ if (typeof obj !== 'object')
67
71
  return obj;
68
72
  return Object.fromEntries(Object.keys(obj).map(key => {
69
73
  return [key, callback(key, obj[key])];
@@ -72,13 +76,13 @@ function transformObj(obj, callback) {
72
76
  exports.transformObj = transformObj;
73
77
  // 深拷贝
74
78
  function deepClone(obj) {
75
- if (typeof obj !== "object")
79
+ if (typeof obj !== 'object')
76
80
  return obj;
77
81
  if (!obj)
78
82
  return obj;
79
83
  //判断拷贝的obj是对象还是数组
80
84
  if (Array.isArray(obj))
81
- return obj.map(item => deepClone(item));
85
+ return obj.map((item) => deepClone(item));
82
86
  const objClone = {};
83
87
  for (const key in obj) {
84
88
  if (obj.hasOwnProperty(key)) {
@@ -114,6 +118,19 @@ function omit(source, keys) {
114
118
  return result;
115
119
  }
116
120
  exports.omit = omit;
121
+ function randomId(seed, ...args) {
122
+ let [min = 0, max = 1] = args;
123
+ let formatter = (n) => n;
124
+ if (args.length === 1) {
125
+ const len = Math.min(Number.MAX_SAFE_INTEGER.toString().length, args[0]);
126
+ min = 10 ** (len - 1);
127
+ max = Math.min(Number.MAX_SAFE_INTEGER, 10 ** len - 1);
128
+ formatter = (n) => Math.floor(n);
129
+ }
130
+ const rand = (0, seed_random_1.default)(seed);
131
+ return formatter(rand() * (max - min) + min);
132
+ }
133
+ exports.randomId = randomId;
117
134
  /**
118
135
  * 将驼峰命名替换为下划线分割命名
119
136
  * @param name
@@ -127,7 +144,7 @@ exports.toLine = toLine;
127
144
  function Mixin(base, ...classes) {
128
145
  classes.forEach(ctr => {
129
146
  Object.getOwnPropertyNames(ctr.prototype).forEach(name => {
130
- if (name === "constructor")
147
+ if (name === 'constructor')
131
148
  return;
132
149
  base.prototype[name] = ctr.prototype[name];
133
150
  });
@@ -136,7 +153,7 @@ function Mixin(base, ...classes) {
136
153
  }
137
154
  exports.Mixin = Mixin;
138
155
  function toHump(action) {
139
- return action.replace(/_[\w]/g, s => {
156
+ return action.replace(/_[\w]/g, (s) => {
140
157
  return s[1].toUpperCase();
141
158
  });
142
159
  }
@@ -155,38 +172,26 @@ function toBool(v) {
155
172
  exports.toBool = toBool;
156
173
  function uuid() {
157
174
  let hex = crypto.randomBytes(16).toString("hex");
158
- return (hex.substr(0, 8) +
159
- "-" +
160
- hex.substr(8, 4) +
161
- "-" +
162
- hex.substr(12, 4) +
163
- "-" +
164
- hex.substr(16, 4) +
165
- "-" +
166
- hex.substr(20));
175
+ return hex.substr(0, 8) + "-" + hex.substr(8, 4) + "-" + hex.substr(12, 4) + "-" + hex.substr(16, 4) + "-" + hex.substr(20);
167
176
  }
168
177
  exports.uuid = uuid;
169
178
  function protectedFields(source, ...keys) {
170
- const protocolValue = value => {
171
- if (value && typeof value === "object")
179
+ const protocolValue = (value) => {
180
+ if (value && typeof value === 'object')
172
181
  return Object.fromEntries(Object.entries(value).map(([key, value]) => {
173
182
  return [key, protocolValue(value)];
174
183
  }));
175
- return `${value}`
176
- .split("")
177
- .map(() => "*")
178
- .join("");
184
+ return `${value}`.split('').map(() => '*').join('');
179
185
  };
180
- if (!source || typeof source !== "object")
181
- throw new Error("source must is object");
186
+ if (!source || typeof source !== 'object')
187
+ throw new Error('source must is object');
182
188
  return Object.fromEntries(Object.entries(source).map(([key, value]) => {
183
189
  return [key, keys.includes(key) ? protocolValue(value) : value];
184
190
  }));
185
191
  }
186
192
  exports.protectedFields = protectedFields;
187
193
  function getProperties(obj) {
188
- if (obj.__proto__ === null) {
189
- //说明该对象已经是最顶层的对象
194
+ if (obj.__proto__ === null) { //说明该对象已经是最顶层的对象
190
195
  return [];
191
196
  }
192
197
  return Object.getOwnPropertyNames(obj).concat(getProperties(obj.__proto__));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.4.23",
3
+ "version": "0.4.26",
4
4
  "description": "基于icqq的多例oneBot实现",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -12,9 +12,9 @@
12
12
  "scripts": {
13
13
  "start": "node .",
14
14
  "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json && cp -r src/config.sample.yaml lib/config.sample.yaml",
15
- "dev": "ts-node-dev -r tsconfig-paths/register ./src/bin.ts -c config.yaml",
15
+ "dev": "ts-node-dev -r tsconfig-paths/register ./src/bin.ts -c config.yaml -r qq -r icqq",
16
16
  "pub": "npm publish --access public",
17
- "lint": "prettier --check ./**/*.{ts,js,vue}",
17
+ "lint": "prettier --check ./**/*.{ts,js}",
18
18
  "lint:fix": "prettier --write ./**/*.{ts,js,md}",
19
19
  "test": "ts-node-dev -r tsconfig-paths/register ./src/test.ts",
20
20
  "docs:dev": "vitepress dev docs --port 8989",
@@ -42,9 +42,9 @@
42
42
  "@types/koa-bodyparser": "^4.3.7",
43
43
  "@types/node": "latest",
44
44
  "@types/ws": "^8.5.3",
45
+ "prettier": "^3.0.0",
45
46
  "ts-node-dev": "latest",
46
47
  "tsc-alias": "latest",
47
- "prettier": "^3.0.0",
48
48
  "tsconfig-paths": "latest",
49
49
  "typescript": "latest",
50
50
  "vitepress": "^1.0.0-alpha.72"
@@ -68,6 +68,7 @@
68
68
  "log4js": "^6.5.2",
69
69
  "mime-types": "^2.1.35",
70
70
  "reflect-metadata": "^0.1.13",
71
+ "seed-random": "^2.2.0",
71
72
  "sqlite3": "^5.1.6",
72
73
  "typeorm": "^0.3.17",
73
74
  "ws": "^8.8.0"
@@ -1,8 +0,0 @@
1
- import { MessageElem } from "icqq";
2
- import { V12 } from "../../service/V12";
3
- export declare function processMessage(this: V12, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<{
4
- element: MessageElem[];
5
- music?: V12.SegmentElem<'music'>;
6
- share?: V12.SegmentElem<'share'>;
7
- quote?: V12.SegmentElem<'reply'>;
8
- }>;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.processMessage = void 0;
4
- const V12_1 = require("../../service/V12");
5
- const utils_1 = require("../../utils");
6
- async function processMessage(message, source) {
7
- let segments = [].concat(message).map(m => {
8
- if (typeof m === 'string')
9
- return { type: 'text', data: { text: m } };
10
- return m;
11
- });
12
- let quote = segments.find(e => e.type === 'reply');
13
- if (quote)
14
- (0, utils_1.remove)(segments, quote);
15
- let music = segments.find(e => e.type === 'music');
16
- if (music)
17
- (0, utils_1.remove)(segments, music);
18
- let share = segments.find(e => e.type === 'share');
19
- if (share)
20
- (0, utils_1.remove)(segments, share);
21
- segments = segments.filter(n => [
22
- 'face', 'text', 'image',
23
- 'rpx', 'dice', 'poke', 'mention', 'mention_all',
24
- 'voice', 'file', 'record',
25
- 'forward', 'node',
26
- 'music', 'share', 'xml', 'json', 'location', // 分享类
27
- ].includes(n.type));
28
- for (const seg of segments) {
29
- if (['image', 'video', 'audio'].includes(seg.type)) {
30
- const { file_id } = seg.data;
31
- const fileInfo = this.getFile(file_id);
32
- if (fileInfo)
33
- seg.data['file_id'] = fileInfo.url || fileInfo.path || `base64://${fileInfo.data}`;
34
- if (seg.data['file_id']?.startsWith('base64://'))
35
- seg.data['file_id'] = Buffer.from(seg.data['file_id'].slice(9), 'base64');
36
- }
37
- else if (['mention', 'mention_all'].includes(seg.type)) {
38
- seg.data['qq'] = seg.data['user_id'];
39
- }
40
- else if (seg.type === 'node') {
41
- seg.data['message'] = (await processMessage.call(this, seg.data['message'])).element;
42
- }
43
- }
44
- const element = V12_1.V12.fromSegment(segments);
45
- return { element, quote: quote || source, share, music };
46
- }
47
- exports.processMessage = processMessage;
File without changes
File without changes