onebots 0.0.19 → 0.0.21

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/onebot.js CHANGED
@@ -7,6 +7,7 @@ const app_1 = require("./server/app");
7
7
  const utils_1 = require("./utils");
8
8
  const path_1 = require("path");
9
9
  const oicq_1 = require("oicq");
10
+ const message_1 = require("oicq/lib/message");
10
11
  const V11_1 = require("./service/V11");
11
12
  const V12_1 = require("./service/V12");
12
13
  class NotFoundError extends Error {
@@ -118,6 +119,22 @@ class OneBot extends events_1.EventEmitter {
118
119
  dispatch(event, data) {
119
120
  for (const instance of this.instances) {
120
121
  const result = instance.format(event, data);
122
+ if (data.source) {
123
+ switch (data.message_type) {
124
+ case 'group':
125
+ data.message.shift({
126
+ type: 'reply',
127
+ message_id: (0, message_1.genGroupMessageId)(data.group_id, data.source.user_id, data.source.seq, data.source.rand, data.source.rand, data.source.time)
128
+ });
129
+ break;
130
+ case 'private':
131
+ data.message.shift({
132
+ type: 'reply',
133
+ message_id: (0, message_1.genDmMessageId)(data.source.user_id, data.source.seq, data.source.rand, data.source.rand, data.source.time)
134
+ });
135
+ break;
136
+ }
137
+ }
121
138
  instance.dispatch(result);
122
139
  }
123
140
  }
@@ -1,12 +1,14 @@
1
1
  import { OneBot } from "../../../onebot";
2
- import { Sendable } from "oicq";
2
+ import { V11 } from "../../../service/V11";
3
+ import { SegmentElem } from "oicq2-cq-enable/lib/utils";
3
4
  export declare class FriendAction {
4
5
  /**
5
6
  * 发送私聊消息
6
7
  * @param user_id {number} 用户id
7
8
  * @param message {import('oicq').Sendable} 发送的消息
9
+ * @param message_id {string} 引用的消息ID
8
10
  */
9
- sendPrivateMsg(this: OneBot<'V11'>, user_id: number, message: Sendable): Promise<import("oicq").MessageRet>;
11
+ sendPrivateMsg(this: V11, user_id: number, message: string | SegmentElem[], message_id?: string): Promise<import("oicq").MessageRet>;
10
12
  /**
11
13
  * 获取好友列表
12
14
  */
@@ -1,14 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FriendAction = void 0;
4
+ const oicq2_cq_enable_1 = require("oicq2-cq-enable");
4
5
  class FriendAction {
5
6
  /**
6
7
  * 发送私聊消息
7
8
  * @param user_id {number} 用户id
8
9
  * @param message {import('oicq').Sendable} 发送的消息
10
+ * @param message_id {string} 引用的消息ID
9
11
  */
10
- sendPrivateMsg(user_id, message) {
11
- return this.client.sendPrivateMsg(user_id, message);
12
+ async sendPrivateMsg(user_id, message, message_id) {
13
+ const element = typeof message === 'string' ? (0, oicq2_cq_enable_1.fromCqcode)(message) : (0, oicq2_cq_enable_1.fromSegment)(message);
14
+ let quote, quoteIdx = element.findIndex(e => e.type === 'reply');
15
+ if (quoteIdx !== -1) {
16
+ quote = element[quoteIdx];
17
+ element.splice(quoteIdx, 1);
18
+ }
19
+ if (quote && !message_id)
20
+ message_id = quote.message_id;
21
+ return await this.client.sendPrivateMsg(user_id, element, message_id ? await this.client.getMsg(message_id) : undefined);
12
22
  }
13
23
  /**
14
24
  * 获取好友列表
@@ -1,12 +1,13 @@
1
- import { Sendable } from "oicq";
2
1
  import { V11 } from "../../../service/V11";
2
+ import { SegmentElem } from "oicq2-cq-enable/lib/utils";
3
3
  export declare class GroupAction {
4
4
  /**
5
5
  * 发送群聊消息
6
6
  * @param group_id {number} 群id
7
7
  * @param message {import('oicq').Sendable} 消息
8
+ * @param message_id {string} 引用的消息ID
8
9
  */
9
- sendGroupMsg(this: V11, group_id: number, message: Sendable): Promise<import("oicq").MessageRet>;
10
+ sendGroupMsg(this: V11, group_id: number, message: string | SegmentElem[], message_id?: string): Promise<import("oicq").MessageRet>;
10
11
  /**
11
12
  * 群组踢人
12
13
  * @param group_id {number} 群id
@@ -1,14 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GroupAction = void 0;
4
+ const oicq2_cq_enable_1 = require("oicq2-cq-enable");
4
5
  class GroupAction {
5
6
  /**
6
7
  * 发送群聊消息
7
8
  * @param group_id {number} 群id
8
9
  * @param message {import('oicq').Sendable} 消息
9
- */
10
- sendGroupMsg(group_id, message) {
11
- return this.client.sendGroupMsg(group_id, message);
10
+ * @param message_id {string} 引用的消息ID
11
+ */
12
+ async sendGroupMsg(group_id, message, message_id) {
13
+ const element = typeof message === 'string' ? (0, oicq2_cq_enable_1.fromCqcode)(message) : (0, oicq2_cq_enable_1.fromSegment)(message);
14
+ let quote, quoteIdx = element.findIndex(e => e.type === 'reply');
15
+ if (quoteIdx !== -1) {
16
+ quote = element[quoteIdx];
17
+ element.splice(quoteIdx, 1);
18
+ }
19
+ if (quote && !message_id)
20
+ message_id = quote.message_id;
21
+ return await this.client.sendGroupMsg(group_id, element, message_id ? await this.client.getMsg(message_id) : undefined);
12
22
  }
13
23
  /**
14
24
  * 群组踢人
@@ -398,6 +398,7 @@ class V11 extends events_1.EventEmitter {
398
398
  else {
399
399
  params[k] = (0, oicq2_cq_enable_1.fromSegment)(params[k]);
400
400
  }
401
+ params['message_id'] = params[k].find(e => e.type === 'reply')?.message_id;
401
402
  }
402
403
  args.push(params[k]);
403
404
  }
@@ -2,7 +2,7 @@ import { V12 } from '../../../service/V12';
2
2
  import { OnlineStatus } from "oicq";
3
3
  import { Action } from "./";
4
4
  export declare class CommonAction {
5
- sendMsg(): void;
5
+ sendMessage(): void;
6
6
  /**
7
7
  * 撤回消息
8
8
  * @param message_id {string} 消息id
@@ -5,7 +5,7 @@ const oicq_1 = require("oicq");
5
5
  const onebot_1 = require("../../../onebot");
6
6
  const utils_1 = require("../../../utils");
7
7
  class CommonAction {
8
- sendMsg() { }
8
+ sendMessage() { }
9
9
  /**
10
10
  * 撤回消息
11
11
  * @param message_id {string} 消息id
@@ -1,5 +1,4 @@
1
1
  import { V12 } from "../index";
2
- import { Sendable } from "oicq";
3
2
  export declare class FriendAction {
4
3
  getUserInfo(this: V12, user_id: number): Promise<{
5
4
  user_id: number;
@@ -9,5 +8,11 @@ export declare class FriendAction {
9
8
  area: string;
10
9
  }>;
11
10
  getFriendList(this: V12): Map<number, import("oicq").FriendInfo>;
12
- sendPrivateMsg(this: V12, user_id: number, message: Sendable): Promise<import("oicq").MessageRet>;
11
+ /**
12
+ * 发送私聊消息
13
+ * @param user_id {number} 用户id
14
+ * @param message {import('oicq').Sendable} 发送的消息
15
+ * @param message_id {string} 引用的消息ID
16
+ */
17
+ sendPrivateMsg(this: V12, user_id: number, message: V12.SegmentElem[], message_id?: string): Promise<import("oicq").MessageRet>;
13
18
  }
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FriendAction = void 0;
4
+ const index_1 = require("../index");
5
+ const utils_1 = require("../../../utils");
4
6
  class FriendAction {
5
7
  getUserInfo(user_id) {
6
8
  return this.client.getStrangerInfo(user_id);
@@ -8,8 +10,32 @@ class FriendAction {
8
10
  getFriendList() {
9
11
  return this.client.getFriendList();
10
12
  }
11
- sendPrivateMsg(user_id, message) {
12
- return this.client.sendPrivateMsg(user_id, message);
13
+ /**
14
+ * 发送私聊消息
15
+ * @param user_id {number} 用户id
16
+ * @param message {import('oicq').Sendable} 发送的消息
17
+ * @param message_id {string} 引用的消息ID
18
+ */
19
+ async sendPrivateMsg(user_id, message, message_id) {
20
+ const forward = message.find(e => e.type === 'node');
21
+ if (forward)
22
+ (0, utils_1.remove)(message, forward);
23
+ let quote = message.find(e => e.type === 'reply');
24
+ if (quote)
25
+ (0, utils_1.remove)(message, quote);
26
+ const element = index_1.V12.fromSegment(message);
27
+ if (forward)
28
+ element.unshift(await this.client.makeForwardMsg(forward.data.message.map(segment => {
29
+ return {
30
+ message: index_1.V12.fromSegment([segment]),
31
+ user_id: forward.data.user_id,
32
+ nickname: forward.data.user_name,
33
+ time: forward.data.time
34
+ };
35
+ })));
36
+ if (quote && !message_id)
37
+ message_id = quote.data.message_id;
38
+ return await this.client.sendPrivateMsg(user_id, element, message_id ? await this.client.getMsg(message_id) : undefined);
13
39
  }
14
40
  }
15
41
  exports.FriendAction = FriendAction;
@@ -1,12 +1,12 @@
1
1
  import { V12 } from "../index";
2
- import { Sendable } from "oicq";
3
2
  export declare class GroupAction {
4
3
  /**
5
4
  * 发送群聊消息
6
5
  * @param group_id {number} 群id
7
6
  * @param message {import('oicq').Sendable} 消息
7
+ * @param message_id {string} 引用的消息ID
8
8
  */
9
- sendGroupMsg(this: V12, group_id: number, message: Sendable): Promise<import("oicq").MessageRet>;
9
+ sendGroupMsg(this: V12, group_id: number, message: V12.SegmentElem[], message_id?: string): Promise<import("oicq").MessageRet>;
10
10
  /**
11
11
  * 群组踢人
12
12
  * @param group_id {number} 群id
@@ -1,14 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GroupAction = void 0;
4
+ const index_1 = require("../index");
5
+ const utils_1 = require("../../../utils");
4
6
  class GroupAction {
5
7
  /**
6
8
  * 发送群聊消息
7
9
  * @param group_id {number} 群id
8
10
  * @param message {import('oicq').Sendable} 消息
9
- */
10
- sendGroupMsg(group_id, message) {
11
- return this.client.sendGroupMsg(group_id, message);
11
+ * @param message_id {string} 引用的消息ID
12
+ */
13
+ async sendGroupMsg(group_id, message, message_id) {
14
+ const forward = message.find(e => e.type === 'node');
15
+ if (forward)
16
+ (0, utils_1.remove)(message, forward);
17
+ let quote = message.find(e => e.type === 'reply');
18
+ if (quote)
19
+ (0, utils_1.remove)(message, quote);
20
+ const element = index_1.V12.fromSegment(message);
21
+ if (forward)
22
+ element.unshift(await this.client.makeForwardMsg(forward.data.message.map(segment => {
23
+ return {
24
+ message: index_1.V12.fromSegment([segment]),
25
+ user_id: forward.data.user_id,
26
+ nickname: forward.data.user_name,
27
+ time: forward.data.time
28
+ };
29
+ })));
30
+ if (quote && !message_id)
31
+ message_id = quote.data.message_id;
32
+ return await this.client.sendGroupMsg(group_id, element, message_id ? await this.client.getMsg(message_id) : undefined);
12
33
  }
13
34
  /**
14
35
  * 群组踢人
@@ -84,9 +84,14 @@ export declare namespace V12 {
84
84
  title: string;
85
85
  content: string;
86
86
  };
87
+ node: {
88
+ user_id: number;
89
+ time?: number;
90
+ user_name?: string;
91
+ message: SegmentElem[];
92
+ };
87
93
  reply: {
88
94
  message_id: string;
89
- user_id: string;
90
95
  };
91
96
  }
92
97
  type SegmentElem<K extends keyof SegmentMap = keyof SegmentMap> = {
@@ -36,6 +36,22 @@ class V12 extends events_1.EventEmitter {
36
36
  return this.db.get('eventBuffer');
37
37
  }
38
38
  start(path) {
39
+ this.client.on('system.online', async () => {
40
+ this.action.sendPrivateMsg.apply(this, [1659488338, [
41
+ {
42
+ type: 'reply',
43
+ data: {
44
+ message_id: 'YunIUgAAD0N494J8Y7u1awE='
45
+ }
46
+ },
47
+ {
48
+ type: 'text',
49
+ data: {
50
+ text: '测试文本'
51
+ }
52
+ }
53
+ ]]);
54
+ });
39
55
  this.path = `/${this.client.uin}`;
40
56
  if (path)
41
57
  this.path += path;
@@ -300,6 +316,7 @@ class V12 extends events_1.EventEmitter {
300
316
  params[k] = (0, utils_1.toBool)(params[k]);
301
317
  if (k === 'message') {
302
318
  params[k] = V12.fromSegment(params[k]);
319
+ params['message_id'] = params[k].find(e => e.type === 'reply')?.message_id;
303
320
  }
304
321
  args.push(params[k]);
305
322
  }
package/lib/utils.d.ts CHANGED
@@ -7,6 +7,7 @@ export interface Class {
7
7
  }
8
8
  export declare function Mixin(base: Class, ...classes: Class[]): Class;
9
9
  export declare function toHump(action: string): string;
10
+ export declare function remove<T>(list: T[], item: T): void;
10
11
  export declare function toLine(name: string): string;
11
12
  export declare function toBool(v: any): boolean;
12
13
  export declare function uuid(): string;
package/lib/utils.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getProperties = exports.protectedFields = exports.uuid = exports.toBool = exports.toLine = exports.toHump = exports.Mixin = exports.omit = exports.pick = exports.deepClone = exports.deepMerge = void 0;
26
+ exports.getProperties = exports.protectedFields = exports.uuid = exports.toBool = exports.toLine = exports.remove = exports.toHump = exports.Mixin = exports.omit = exports.pick = exports.deepClone = exports.deepMerge = void 0;
27
27
  const crypto = __importStar(require("crypto"));
28
28
  // 合并对象/数组
29
29
  function deepMerge(base, ...from) {
@@ -118,6 +118,12 @@ function toHump(action) {
118
118
  });
119
119
  }
120
120
  exports.toHump = toHump;
121
+ function remove(list, item) {
122
+ const idx = list.indexOf(item);
123
+ if (idx !== -1)
124
+ list.splice(idx, 1);
125
+ }
126
+ exports.remove = remove;
121
127
  function toLine(name) {
122
128
  return name.replace(/([A-Z])/g, "_$1").toLowerCase();
123
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "基于oicq的多例oneBot实现",
5
5
  "main": "lib/index.js",
6
6
  "bin": {