onebots 0.1.10 → 0.1.12

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').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.SegmentElem[], 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').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;
@@ -3,10 +3,10 @@ export declare class GroupAction {
3
3
  /**
4
4
  * 发送群聊消息
5
5
  * @param group_id {number} 群id
6
- * @param message {import('icqq').Sendable} 消息
7
- * @param message_id {string} 引用的消息ID
6
+ * @param message {import('icqq/lib/service').Sendable} 消息
7
+ * @param quote {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
8
8
  */
9
- sendGroupMsg(this: V12, group_id: number, message: V12.SegmentElem[], 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
@@ -6,11 +6,11 @@ class GroupAction {
6
6
  /**
7
7
  * 发送群聊消息
8
8
  * @param group_id {number} 群id
9
- * @param message {import('icqq').Sendable} 消息
10
- * @param message_id {string} 引用的消息ID
9
+ * @param message {import('icqq/lib/service').Sendable} 消息
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,5 +1,4 @@
1
1
  import { V12 } from "../../../service/V12";
2
- import SegmentElem = V12.SegmentElem;
3
2
  export declare class GuildAction {
4
3
  getGuildList(this: V12): {
5
4
  guild_id: string;
@@ -12,7 +11,13 @@ export declare class GuildAction {
12
11
  channel_type: import("icqq/lib/channel").ChannelType;
13
12
  }[];
14
13
  getGuildMemberList(this: V12, guild_id: string): never[] | Promise<import("icqq/lib/guild").GuildMember[]>;
15
- sendGuildMsg(this: V12, guild_id: string, channel_id: string, message: SegmentElem[]): Promise<{
14
+ /**
15
+ * 发送群聊消息
16
+ * @param guild_id {number} 频道id
17
+ * @param channel_id {string} 子频道id
18
+ * @param message {import('icqq/lib/service').Sendable} 消息
19
+ */
20
+ sendGuildMsg(this: V12, guild_id: string, channel_id: string, message: V12.Sendable): Promise<{
16
21
  seq: number;
17
22
  rand: number;
18
23
  time: number;
@@ -12,6 +12,12 @@ class GuildAction {
12
12
  getGuildMemberList(guild_id) {
13
13
  return this.client.getGuildMemberList(guild_id);
14
14
  }
15
+ /**
16
+ * 发送群聊消息
17
+ * @param guild_id {number} 频道id
18
+ * @param channel_id {string} 子频道id
19
+ * @param message {import('icqq/lib/service').Sendable} 消息
20
+ */
15
21
  async sendGuildMsg(guild_id, channel_id, message) {
16
22
  const { element } = await utils_1.processMessage.apply(this.client, [message]);
17
23
  if (!element.length)
@@ -1,7 +1,7 @@
1
1
  import { Client, MessageElem } from "icqq";
2
2
  import { V12 } from "../../../service/V12";
3
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.SegmentElem[], quote_id?: string): Promise<{
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,16 +14,25 @@ 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) {
18
- const forward = message.find(e => e.type === 'forward');
17
+ async function processMessage(message, source) {
18
+ let segments = [].concat(message).map(m => {
19
+ if (typeof m === 'string')
20
+ return { type: 'text', data: { text: m } };
21
+ return m;
22
+ });
23
+ const forward = segments.find(e => e.type === 'forward');
19
24
  if (forward)
20
- (0, utils_1.remove)(message, forward);
21
- let quote = message.find(e => e.type === 'reply');
25
+ (0, utils_1.remove)(segments, forward);
26
+ let quote = segments.find(e => e.type === 'reply');
22
27
  if (quote)
23
- (0, utils_1.remove)(message, quote);
24
- // 直接发node?不允许,你用forward作为载体吧
25
- message = message.filter(n => n.type !== 'node');
26
- const element = V12_1.V12.fromSegment(message);
28
+ (0, utils_1.remove)(segments, quote);
29
+ segments = segments.filter(n => [
30
+ 'face', 'text', 'image',
31
+ 'rpx', 'dice', 'poke', 'mention', 'mention_all',
32
+ 'voice', 'file', 'audio',
33
+ 'music', 'share', 'xml', 'json', 'location', // 分享类
34
+ ].includes(n.type));
35
+ const element = V12_1.V12.fromSegment(segments);
27
36
  if (forward)
28
37
  element.unshift(
29
38
  // 构造抓发消息
@@ -38,8 +47,6 @@ async function processMessage(message, quote_id) {
38
47
  time: forwardNode.data.time
39
48
  };
40
49
  }))));
41
- if (quote && !quote_id)
42
- quote_id = quote.data.message_id;
43
- return { element, quote_id };
50
+ return { element, quote: quote || source };
44
51
  }
45
52
  exports.processMessage = processMessage;
@@ -1,13 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { Client, EventMap, MessageElem, Sendable } from "icqq";
3
+ import { Client, EventMap, MessageElem, Sendable as IcqqCanSend } from "icqq";
4
4
  import { Config } from './config';
5
5
  import { OneBot } from "../../onebot";
6
6
  import { Action } from "./action";
7
7
  import { EventEmitter } from "events";
8
8
  import { Logger } from "log4js";
9
9
  import { WebSocket, WebSocketServer } from "ws";
10
- import Payload = V12.Payload;
11
10
  export declare class V12 extends EventEmitter implements OneBot.Base {
12
11
  oneBot: OneBot<'V12'>;
13
12
  client: Client;
@@ -22,8 +21,8 @@ export declare class V12 extends EventEmitter implements OneBot.Base {
22
21
  wsr: Set<WebSocket>;
23
22
  private db;
24
23
  constructor(oneBot: OneBot<'V12'>, client: Client, config: V12.Config);
25
- get history(): Payload<keyof Action>[];
26
- set history(value: Payload<keyof Action>[]);
24
+ get history(): V12.Payload<keyof Action>[];
25
+ set history(value: V12.Payload<keyof Action>[]);
27
26
  start(path?: string): void;
28
27
  private startHttp;
29
28
  private startWebhook;
@@ -55,8 +54,9 @@ export declare class V12 extends EventEmitter implements OneBot.Base {
55
54
  protected _webSocketHandler(ws: WebSocket): void;
56
55
  }
57
56
  export declare namespace V12 {
58
- function fromSegment(msgList: SegmentElem | string | number | (SegmentElem | string | number)[]): MessageElem[];
59
- function toSegment(msgList: Sendable): SegmentElem<keyof SegmentMap>[];
57
+ type Sendable = string | SegmentElem | (string | SegmentElem)[];
58
+ function fromSegment(msgList: Sendable[]): MessageElem[];
59
+ function toSegment(msgList: IcqqCanSend): SegmentElem<keyof SegmentMap>[];
60
60
  interface SegmentMap {
61
61
  face: {
62
62
  id: number;
@@ -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.10",
3
+ "version": "0.1.12",
4
4
  "description": "基于icqq的多例oneBot实现",
5
5
  "engines": {
6
6
  "node": ">=16"