onebots 0.0.20 → 0.0.22

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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FriendAction = void 0;
4
4
  const index_1 = require("../index");
5
+ const utils_1 = require("../../../utils");
5
6
  class FriendAction {
6
7
  getUserInfo(user_id) {
7
8
  return this.client.getStrangerInfo(user_id);
@@ -16,14 +17,24 @@ class FriendAction {
16
17
  * @param message_id {string} 引用的消息ID
17
18
  */
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);
19
26
  const element = index_1.V12.fromSegment(message);
20
- let quote, quoteIdx = element.findIndex(e => e.type === 'reply');
21
- if (quoteIdx !== -1) {
22
- quote = element[quoteIdx];
23
- element.splice(quoteIdx, 1);
24
- }
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
+ })));
25
36
  if (quote && !message_id)
26
- message_id = quote.message_id;
37
+ message_id = quote.data.message_id;
27
38
  return await this.client.sendPrivateMsg(user_id, element, message_id ? await this.client.getMsg(message_id) : undefined);
28
39
  }
29
40
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GroupAction = void 0;
4
4
  const index_1 = require("../index");
5
+ const utils_1 = require("../../../utils");
5
6
  class GroupAction {
6
7
  /**
7
8
  * 发送群聊消息
@@ -10,14 +11,24 @@ class GroupAction {
10
11
  * @param message_id {string} 引用的消息ID
11
12
  */
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);
13
20
  const element = index_1.V12.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
- }
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
+ })));
19
30
  if (quote && !message_id)
20
- message_id = quote.message_id;
31
+ message_id = quote.data.message_id;
21
32
  return await this.client.sendGroupMsg(group_id, element, message_id ? await this.client.getMsg(message_id) : undefined);
22
33
  }
23
34
  /**
@@ -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> = {
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.20",
3
+ "version": "0.0.22",
4
4
  "description": "基于oicq的多例oneBot实现",
5
5
  "main": "lib/index.js",
6
6
  "bin": {