onebots 0.4.72 → 0.4.73

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/adapter.js CHANGED
@@ -24,13 +24,13 @@ class Adapter extends events_1.EventEmitter {
24
24
  this.oneBots = new Map();
25
25
  _Adapter_logger.set(this, void 0);
26
26
  this.on("message.receive", (uin, ...args) => {
27
- this.oneBots.get(uin)?.emit("message.receive", ...args);
27
+ this.getOneBot(uin).emit("message.receive", ...args);
28
28
  });
29
29
  this.on("notice.receive", (uin, ...args) => {
30
- this.oneBots.get(uin)?.emit("notice.receive", ...args);
30
+ this.getOneBot(uin).emit("notice.receive", ...args);
31
31
  });
32
32
  this.on("request.receive", (uin, ...args) => {
33
- this.oneBots.get(uin)?.emit("request.receive", ...args);
33
+ this.getOneBot(uin).emit("request.receive", ...args);
34
34
  });
35
35
  }
36
36
  materialize(content) {
@@ -83,36 +83,49 @@ class QQAdapter extends adapter_1.Adapter {
83
83
  return oneBot;
84
84
  }
85
85
  async sendGroupMessage(uin, version, args) {
86
- const [group_id, message, source] = args;
86
+ let [group_id, message, source] = args;
87
+ if (version === "V11") {
88
+ const [sub_type] = group_id.split(":");
89
+ if (sub_type === "guild")
90
+ return await this.sendGuildMessage(uin, version, [
91
+ group_id.slice(6),
92
+ message,
93
+ source,
94
+ ]);
95
+ }
87
96
  const bot = this.getOneBot(uin);
88
97
  let quote;
89
98
  if (source)
90
99
  quote = { id: source };
91
100
  const result = await bot.internal.sendGroupMessage(group_id, message, quote);
92
- if (result.msg === "success") {
93
- return {
94
- message_id: version === "V11"
95
- ? bot.V11.transformToInt("message_id", `group:${group_id}${result.msg_id}`)
96
- : `group:${group_id}${result.msg_id}`,
97
- };
98
- }
99
- throw new Error(result.msg);
101
+ return {
102
+ message_id: version === "V11"
103
+ ? bot.V11.transformToInt("message_id", `group:${group_id}${result.id}`)
104
+ : `group:${group_id}${result.id}`,
105
+ };
100
106
  }
101
107
  async sendPrivateMessage(uin, version, args) {
102
- const [user_id, message, source] = args;
108
+ let [user_id, message, source] = args;
109
+ if (version === "V11") {
110
+ const [sub_type, real_user_id = sub_type] = user_id.split(":");
111
+ if (sub_type === "direct")
112
+ return await this.sendDirectMessage(uin, version, [
113
+ user_id.slice(7),
114
+ message,
115
+ source,
116
+ ]);
117
+ user_id = real_user_id;
118
+ }
103
119
  const bot = this.getOneBot(uin);
104
120
  let quote;
105
121
  if (source)
106
122
  quote = { id: source };
107
123
  const result = await bot.internal.sendPrivateMessage(user_id, message, quote);
108
- if (result.msg === "success") {
109
- return {
110
- message_id: version === "V11"
111
- ? bot.V11.transformToInt("message_id", `private:${user_id}${result.msg_id}`)
112
- : `private:${user_id}${result.msg_id}`,
113
- };
114
- }
115
- throw new Error(result.msg);
124
+ return {
125
+ message_id: version === "V11"
126
+ ? bot.V11.transformToInt("message_id", `private:${user_id}${result.id}`)
127
+ : `private:${user_id}${result.id}`,
128
+ };
116
129
  }
117
130
  async sendGuildMessage(uin, version, args) {
118
131
  const [channel_id, message, source] = args;
@@ -121,14 +134,11 @@ class QQAdapter extends adapter_1.Adapter {
121
134
  if (source)
122
135
  quote = { id: source };
123
136
  const result = await bot.internal.sendGuildMessage(channel_id, message, quote);
124
- if (result.msg === "success") {
125
- return {
126
- message_id: version === "V11"
127
- ? bot.V11.transformToInt("message_id", `guild:${channel_id}${result.msg_id}`)
128
- : `guild:${channel_id}${result.msg_id}`,
129
- };
130
- }
131
- throw new Error(result.msg);
137
+ return {
138
+ message_id: version === "V11"
139
+ ? bot.V11.transformToInt("message_id", `guild:${channel_id}${result.id}`)
140
+ : `guild:${channel_id}${result.id}`,
141
+ };
132
142
  }
133
143
  async sendDirectMessage(uin, version, args) {
134
144
  const [guild_id, message, source] = args;
@@ -137,14 +147,11 @@ class QQAdapter extends adapter_1.Adapter {
137
147
  if (source)
138
148
  quote = { id: source };
139
149
  const result = await bot.internal.sendDirectMessage(guild_id, message, quote);
140
- if (result.msg === "success") {
141
- return {
142
- message_id: version === "V11"
143
- ? bot.V11.transformToInt("message_id", `direct:${guild_id}${result.msg_id}`)
144
- : `direct:${guild_id}${result.msg_id}`,
145
- };
146
- }
147
- throw new Error(result.msg);
150
+ return {
151
+ message_id: version === "V11"
152
+ ? bot.V11.transformToInt("message_id", `direct:${guild_id}${result.id}`)
153
+ : `direct:${guild_id}${result.id}`,
154
+ };
148
155
  }
149
156
  deleteMessage(uin, message_id) {
150
157
  const [from_type, from_id, ...msg_idArr] = message_id.split(":");
@@ -181,6 +188,12 @@ class QQAdapter extends adapter_1.Adapter {
181
188
  .map(segment => {
182
189
  if (version === "V12" && ["image", "video", "audio"].includes(segment.type))
183
190
  return onebot.V12.transformMedia(segment);
191
+ if (segment.type === "reply") {
192
+ if (version === "V11")
193
+ segment.data.id = onebot.V11.getStrByInt("message_id", segment.data.id);
194
+ const [_1, _2, ...others] = (segment.data.id || "").split(":");
195
+ segment.data.id = others.join(":");
196
+ }
184
197
  return segment;
185
198
  })
186
199
  .map(item => {
@@ -227,8 +240,21 @@ class QQAdapter extends adapter_1.Adapter {
227
240
  },
228
241
  user_id: data.user_id || data.sender?.user_id,
229
242
  };
230
- if (data.message_id) {
231
- data.message_id = `${data.message_type}:${data.channel_id || data.guild_id || data.group_id || data.user_id}:${data.message_id}`;
243
+ if (result.message_id) {
244
+ if (result.message_type === "private") {
245
+ result.message_id = `${result.sub_type}:${result.guild_id || result.group_id || result.user_id}:${result.message_id}`;
246
+ result.user_id = `${result.sub_type}:${result.guild_id || result.group_id || result.user_id}`;
247
+ if (result.sender)
248
+ result.sender.user_id = result.user_id;
249
+ }
250
+ else if (result.message_type === "guild") {
251
+ result.message_type = "group";
252
+ result.message_id = `guild:${result.channel_id}:${result.message_id}`;
253
+ result.group_id = `guild:${result.channel_id}`;
254
+ }
255
+ else {
256
+ result.message_id = `${result.message_type}:${result.channel_id || result.guild_id || result.group_id || result.user_id}:${result.message_id}`;
257
+ }
232
258
  }
233
259
  delete result.bot;
234
260
  const oneBot = this.getOneBot(uin);
@@ -238,8 +264,8 @@ class QQAdapter extends adapter_1.Adapter {
238
264
  switch (version) {
239
265
  case "V11":
240
266
  oneBot.V11.transformStrToIntForObj(result, ["message_id", "user_id", "group_id"]);
241
- oneBot.V11.transformStrToIntForObj(result.sender, ["user_id "]);
242
- oneBot.V11.transformStrToIntForObj(result.self, ["user_id "]);
267
+ oneBot.V11.transformStrToIntForObj(result.sender, ["user_id"]);
268
+ oneBot.V11.transformStrToIntForObj(result.self, ["user_id"]);
243
269
  break;
244
270
  }
245
271
  return result;
package/lib/onebot.d.ts CHANGED
@@ -5,7 +5,6 @@ import { V12 } from "./service/V12";
5
5
  import { Adapter } from "./adapter";
6
6
  import { Service } from "./service";
7
7
  import { Logger } from "log4js";
8
- import { App } from "./server/app";
9
8
  export declare class NotFoundError extends Error {
10
9
  message: string;
11
10
  }
@@ -21,7 +20,7 @@ export declare class OneBot<T = any> extends EventEmitter {
21
20
  protected password: string;
22
21
  internal: T;
23
22
  instances: (V11 | V12)[];
24
- get app(): App;
23
+ get app(): import(".").App;
25
24
  get V11(): V11;
26
25
  get V12(): V12;
27
26
  get platform(): string;
package/lib/server/app.js CHANGED
@@ -318,18 +318,15 @@ function createOnebots(config = "config.yaml", cp = null) {
318
318
  }
319
319
  if (!(0, fs_1.existsSync)(App.configDir))
320
320
  (0, fs_1.mkdirSync)(App.configDir);
321
- if (!(0, fs_1.existsSync)(App.configPath)) {
322
- if (isStartWithConfigFile) {
323
- (0, fs_1.copyFileSync)(path.resolve(__dirname, "../config.sample.yaml"), App.configPath);
324
- console.log("未找到对应配置文件,已自动生成默认配置文件,请修改配置文件后重新启动");
325
- console.log(`配置文件在: ${App.configPath}`);
326
- process_1.default.exit();
327
- }
328
- else {
329
- (0, fs_1.writeFileSync)(App.configPath, js_yaml_1.default.dump(config));
330
- console.log(`已自动保存配置到:${App.configPath}`);
331
- console.log(`配置文件在: `);
332
- }
321
+ if (!(0, fs_1.existsSync)(App.configPath) && isStartWithConfigFile) {
322
+ (0, fs_1.copyFileSync)(path.resolve(__dirname, "../config.sample.yaml"), App.configPath);
323
+ console.log("未找到对应配置文件,已自动生成默认配置文件,请修改配置文件后重新启动");
324
+ console.log(`配置文件在: ${App.configPath}`);
325
+ process_1.default.exit();
326
+ }
327
+ if (!isStartWithConfigFile) {
328
+ (0, fs_1.writeFileSync)(App.configPath, js_yaml_1.default.dump(config));
329
+ console.log(`已自动保存配置到:${App.configPath}`);
333
330
  }
334
331
  if (!(0, fs_1.existsSync)(App.dataDir)) {
335
332
  (0, fs_1.mkdirSync)(App.dataDir);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.4.72",
3
+ "version": "0.4.73",
4
4
  "description": "基于icqq的多例oneBot实现",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -93,4 +93,4 @@
93
93
  "reflect-metadata": "^0.1.13",
94
94
  "ws": "^8.16.0"
95
95
  }
96
- }
96
+ }