onebots 0.1.11 → 0.1.13

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.
@@ -11,8 +11,8 @@ export declare class FriendAction {
11
11
  /**
12
12
  * 发送私聊消息
13
13
  * @param user_id {number} 用户id
14
- * @param message {import('icqq/lib/service').Sendable} 消息
15
- * @param message_id {string} 引用的消息ID
14
+ * @param message {import('onebots/lib/service/v12').Sendable} 消息
15
+ * @param quote {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
16
16
  */
17
- sendPrivateMsg(this: V12, user_id: number, message: V12.Sendable, message_id?: string): Promise<import("icqq").MessageRet>;
17
+ sendPrivateMsg(this: V12, user_id: number, message: V12.Sendable, quote?: V12.SegmentElem<'reply'>): Promise<import("icqq").MessageRet>;
18
18
  }
@@ -12,11 +12,11 @@ class FriendAction {
12
12
  /**
13
13
  * 发送私聊消息
14
14
  * @param user_id {number} 用户id
15
- * @param message {import('icqq/lib/service').Sendable} 消息
16
- * @param message_id {string} 引用的消息ID
15
+ * @param message {import('onebots/lib/service/v12').Sendable} 消息
16
+ * @param quote {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
17
17
  */
18
- async sendPrivateMsg(user_id, message, message_id) {
19
- let { element, quote_id } = await utils_1.processMessage.apply(this.client, [message, message_id]);
18
+ async sendPrivateMsg(user_id, message, quote) {
19
+ let { element, quote_id } = await utils_1.processMessage.apply(this.client, [message, quote]);
20
20
  element = await utils_1.processMusic.apply(this.client, ['friend', user_id, element]);
21
21
  if (!element.length)
22
22
  return;
@@ -4,9 +4,9 @@ export declare class GroupAction {
4
4
  * 发送群聊消息
5
5
  * @param group_id {number} 群id
6
6
  * @param message {import('icqq/lib/service').Sendable} 消息
7
- * @param message_id {string} 引用的消息ID
7
+ * @param quote {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
8
8
  */
9
- sendGroupMsg(this: V12, group_id: number, message: V12.Sendable, message_id?: string): Promise<import("icqq").MessageRet>;
9
+ sendGroupMsg(this: V12, group_id: number, message: V12.Sendable, quote?: V12.SegmentElem<'reply'>): Promise<import("icqq").MessageRet>;
10
10
  /**
11
11
  * 群组踢人
12
12
  * @param group_id {number} 群id
@@ -7,10 +7,10 @@ class GroupAction {
7
7
  * 发送群聊消息
8
8
  * @param group_id {number} 群id
9
9
  * @param message {import('icqq/lib/service').Sendable} 消息
10
- * @param message_id {string} 引用的消息ID
10
+ * @param quote {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
11
11
  */
12
- async sendGroupMsg(group_id, message, message_id) {
13
- let { element, quote_id } = await utils_1.processMessage.apply(this.client, [message, message_id]);
12
+ async sendGroupMsg(group_id, message, quote) {
13
+ let { element, quote_id } = await utils_1.processMessage.apply(this.client, [message, quote]);
14
14
  element = await utils_1.processMusic.apply(this.client, ['group', group_id, element]);
15
15
  if (!element.length)
16
16
  return;
@@ -1,7 +1,7 @@
1
1
  import { Client, MessageElem } from "icqq";
2
2
  import { V12 } from "../../../service/V12";
3
- export declare function processMusic(this: Client, target_type: 'group' | 'friend', target_id: number, element: any): Promise<any>;
4
- export declare function processMessage(this: Client, message: V12.Sendable, quote_id?: string): Promise<{
3
+ export declare function processMusic(this: Client, target_type: 'group' | 'friend', target_id: number, element: any[]): Promise<any[]>;
4
+ export declare function processMessage(this: Client, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<{
5
5
  element: MessageElem[];
6
- quote_id?: string;
6
+ quote: V12.SegmentElem<'reply'>;
7
7
  }>;
@@ -14,7 +14,7 @@ async function processMusic(target_type, target_id, element) {
14
14
  return element;
15
15
  }
16
16
  exports.processMusic = processMusic;
17
- async function processMessage(message, quote_id) {
17
+ async function processMessage(message, source) {
18
18
  let segments = [].concat(message).map(m => {
19
19
  if (typeof m === 'string')
20
20
  return { type: 'text', data: { text: m } };
@@ -26,8 +26,13 @@ async function processMessage(message, quote_id) {
26
26
  let quote = segments.find(e => e.type === 'reply');
27
27
  if (quote)
28
28
  (0, utils_1.remove)(segments, quote);
29
- // 直接发node?不允许,你用forward作为载体吧
30
- segments = segments.filter(n => n.type !== 'node');
29
+ segments = segments.filter(n => [
30
+ 'face', 'text', 'image',
31
+ 'rpx', 'dice', 'poke', 'mention', 'mention_all',
32
+ 'voice', 'file', 'audio',
33
+ 'forward', 'node',
34
+ 'music', 'share', 'xml', 'json', 'location', // 分享类
35
+ ].includes(n.type));
31
36
  const element = V12_1.V12.fromSegment(segments);
32
37
  if (forward)
33
38
  element.unshift(
@@ -37,14 +42,12 @@ async function processMessage(message, quote_id) {
37
42
  forward.data.nodes.filter(n => n.type === 'node').map(async (forwardNode) => {
38
43
  return {
39
44
  // 转发套转发处理
40
- message: (await processMessage.apply(this, [V12_1.V12.fromSegment(forwardNode.data.message)])).element,
45
+ message: (await processMessage.apply(this, [forwardNode.data.message])).element,
41
46
  user_id: Number(forwardNode.data.user_id),
42
47
  nickname: forwardNode.data.user_name,
43
48
  time: forwardNode.data.time
44
49
  };
45
50
  }))));
46
- if (quote && !quote_id)
47
- quote_id = quote.data.message_id;
48
- return { element, quote_id };
51
+ return { element, quote: quote || source };
49
52
  }
50
53
  exports.processMessage = processMessage;
@@ -68,6 +68,15 @@ export declare namespace V12 {
68
68
  mention: {
69
69
  user_id: string;
70
70
  };
71
+ rps: {
72
+ id?: string;
73
+ };
74
+ dice: {
75
+ id?: string;
76
+ };
77
+ poke: {
78
+ user_id: string;
79
+ };
71
80
  mention_all: null;
72
81
  image: {
73
82
  file_id: string;
@@ -81,9 +90,6 @@ export declare namespace V12 {
81
90
  file: {
82
91
  file_id: string;
83
92
  };
84
- forward: {
85
- nodes: SegmentElem<'node'>[];
86
- };
87
93
  music: {
88
94
  type: "163" | 'qq' | 'xm' | 'custom';
89
95
  id?: string;
@@ -97,12 +103,6 @@ export declare namespace V12 {
97
103
  title?: string;
98
104
  content?: string;
99
105
  };
100
- node: {
101
- user_id: string;
102
- time?: number;
103
- user_name?: string;
104
- message: SegmentElem[];
105
- };
106
106
  share: {
107
107
  url: string;
108
108
  title: string;
@@ -112,6 +112,15 @@ export declare namespace V12 {
112
112
  reply: {
113
113
  message_id: string;
114
114
  };
115
+ node: {
116
+ user_id: string;
117
+ time?: number;
118
+ user_name?: string;
119
+ message: SegmentElem[];
120
+ };
121
+ forward: {
122
+ nodes: SegmentElem<'node'>[];
123
+ };
115
124
  }
116
125
  type SegmentElem<K extends keyof SegmentMap = keyof SegmentMap> = {
117
126
  type: K;
@@ -18,6 +18,7 @@ const utils_2 = require("../../utils");
18
18
  const db_1 = require("../../db");
19
19
  const app_1 = require("../../server/app");
20
20
  const fs_1 = require("fs");
21
+ const message_1 = require("icqq/lib/message");
21
22
  class V12 extends events_1.EventEmitter {
22
23
  constructor(oneBot, client, config) {
23
24
  super();
@@ -314,6 +315,16 @@ class V12 extends events_1.EventEmitter {
314
315
  if (!data.detail_type)
315
316
  data.detail_type = data.message_type || data.notice_type || data.request_type || data.system_type;
316
317
  data.message = data.type === 'message' ? V12.toSegment(data.message) : data.message;
318
+ if (data.source)
319
+ data.quote = {
320
+ type: 'reply',
321
+ data: {
322
+ message_id: data.detail_type === 'private' ?
323
+ (0, message_1.genDmMessageId)(data.source.user_id, data.source.seq, data.source.rand, data.source.time) :
324
+ (0, message_1.genGroupMessageId)(data.group_id, data.source.user_id, data.source.seq, data.source.rand, data.source.time),
325
+ user_id: data.source.user_id
326
+ }
327
+ };
317
328
  return V12.formatPayload(this.oneBot.uin, event, data);
318
329
  }
319
330
  dispatch(data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "基于icqq的多例oneBot实现",
5
5
  "engines": {
6
6
  "node": ">=16"