onebots 0.1.13 → 0.1.15

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/bin.js CHANGED
File without changes
package/lib/onebot.d.ts CHANGED
@@ -27,7 +27,7 @@ export declare enum OneBotStatus {
27
27
  Good = 0,
28
28
  Bad = 1
29
29
  }
30
- export declare type OneBotConfig = OneBot.Config<OneBot.Version>;
30
+ export type OneBotConfig = OneBot.Config<OneBot.Version>;
31
31
  export declare namespace OneBot {
32
32
  type Version = 'V11' | 'V12';
33
33
  type Config<V extends Version = 'V11'> = ({
@@ -12,7 +12,10 @@ export declare class FriendAction {
12
12
  * 发送私聊消息
13
13
  * @param user_id {number} 用户id
14
14
  * @param message {import('onebots/lib/service/v12').Sendable} 消息
15
- * @param quote {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
15
+ * @param source {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
16
16
  */
17
- sendPrivateMsg(this: V12, user_id: number, message: V12.Sendable, quote?: V12.SegmentElem<'reply'>): Promise<import("icqq").MessageRet>;
17
+ sendPrivateMsg(this: V12, user_id: number, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<import("icqq").MessageRet | {
18
+ message_id: string;
19
+ message: V12.Sendable;
20
+ }>;
18
21
  }
@@ -13,14 +13,24 @@ class FriendAction {
13
13
  * 发送私聊消息
14
14
  * @param user_id {number} 用户id
15
15
  * @param message {import('onebots/lib/service/v12').Sendable} 消息
16
- * @param quote {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
16
+ * @param source {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
17
17
  */
18
- async sendPrivateMsg(user_id, message, quote) {
19
- let { element, quote_id } = await utils_1.processMessage.apply(this.client, [message, quote]);
20
- element = await utils_1.processMusic.apply(this.client, ['friend', user_id, element]);
21
- if (!element.length)
22
- return;
23
- return await this.client.sendPrivateMsg(user_id, element, quote_id ? await this.client.getMsg(quote_id) : undefined);
18
+ async sendPrivateMsg(user_id, message, source) {
19
+ let { element, quote, music, share } = await utils_1.processMessage.apply(this.client, [message, source]);
20
+ if (!element.length && (!music || !share))
21
+ throw new Error('发送消息不受支持');
22
+ if (music || share) {
23
+ const target = this.client.pickFriend(user_id);
24
+ if (music)
25
+ await target.shareMusic(music.data.type, music.data.id);
26
+ if (share)
27
+ await target.shareUrl(share.data);
28
+ return {
29
+ message_id: '',
30
+ message
31
+ };
32
+ }
33
+ return await this.client.sendPrivateMsg(user_id, element, quote ? await this.client.getMsg(quote.data.message_id) : undefined);
24
34
  }
25
35
  }
26
36
  exports.FriendAction = FriendAction;
@@ -4,9 +4,12 @@ export declare class GroupAction {
4
4
  * 发送群聊消息
5
5
  * @param group_id {number} 群id
6
6
  * @param message {import('icqq/lib/service').Sendable} 消息
7
- * @param quote {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
7
+ * @param source {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
8
8
  */
9
- sendGroupMsg(this: V12, group_id: number, message: V12.Sendable, quote?: V12.SegmentElem<'reply'>): Promise<import("icqq").MessageRet>;
9
+ sendGroupMsg(this: V12, group_id: number, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<import("icqq").MessageRet | {
10
+ message_id: string;
11
+ message: V12.Sendable;
12
+ }>;
10
13
  /**
11
14
  * 群组踢人
12
15
  * @param group_id {number} 群id
@@ -7,14 +7,24 @@ class GroupAction {
7
7
  * 发送群聊消息
8
8
  * @param group_id {number} 群id
9
9
  * @param message {import('icqq/lib/service').Sendable} 消息
10
- * @param quote {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
11
- */
12
- async sendGroupMsg(group_id, message, quote) {
13
- let { element, quote_id } = await utils_1.processMessage.apply(this.client, [message, quote]);
14
- element = await utils_1.processMusic.apply(this.client, ['group', group_id, element]);
15
- if (!element.length)
16
- return;
17
- return await this.client.sendGroupMsg(group_id, element, quote_id ? await this.client.getMsg(quote_id) : undefined);
10
+ * @param source {import('onebots/lib/service/v12').SegmentElem<'reply'>} 引用内容
11
+ */
12
+ async sendGroupMsg(group_id, message, source) {
13
+ let { element, quote, music, share } = await utils_1.processMessage.apply(this.client, [message, source]);
14
+ if (!element.length && (!music || !share))
15
+ throw new Error('发送消息不受支持');
16
+ if (music || share) {
17
+ const target = this.client.pickGroup(group_id);
18
+ if (music)
19
+ await target.shareMusic(music.data.type, music.data.id);
20
+ if (share)
21
+ await target.shareUrl(share.data);
22
+ return {
23
+ message_id: '',
24
+ message
25
+ };
26
+ }
27
+ return await this.client.sendGroupMsg(group_id, element, quote ? await this.client.getMsg(quote.data.message_id) : undefined);
18
28
  }
19
29
  /**
20
30
  * 群组踢人
@@ -3,5 +3,7 @@ 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
4
  export declare function processMessage(this: Client, message: V12.Sendable, source?: V12.SegmentElem<'reply'>): Promise<{
5
5
  element: MessageElem[];
6
- quote: V12.SegmentElem<'reply'>;
6
+ music?: V12.SegmentElem<'music'>;
7
+ share?: V12.SegmentElem<'share'>;
8
+ quote?: V12.SegmentElem<'reply'>;
7
9
  }>;
@@ -20,26 +20,41 @@ async function processMessage(message, source) {
20
20
  return { type: 'text', data: { text: m } };
21
21
  return m;
22
22
  });
23
- const forward = segments.find(e => e.type === 'forward');
24
- if (forward)
25
- (0, utils_1.remove)(segments, forward);
23
+ const music = segments.find(e => e.type === 'music');
24
+ if (music)
25
+ (0, utils_1.remove)(segments, music);
26
+ if (segments.find(e => e.type === 'music'))
27
+ throw new Error('一次只能发送一个音乐元素');
28
+ if (segments.length && music)
29
+ throw new Error('音乐元素只能单独发送');
30
+ const share = segments.find(e => e.type === 'share');
31
+ if (share)
32
+ (0, utils_1.remove)(segments, share);
33
+ if (segments.find(e => e.type === 'share'))
34
+ throw new Error('一次只能发送一个分享元素');
35
+ if (segments.length && share)
36
+ throw new Error('分享元素只能单独发送');
37
+ const forwardNodes = segments.filter(e => e.type === 'node');
38
+ segments = segments.filter(s => !forwardNodes.includes(s));
39
+ if (forwardNodes.length && segments.length)
40
+ throw new Error('只能单独发送转发节点');
26
41
  let quote = segments.find(e => e.type === 'reply');
27
42
  if (quote)
28
43
  (0, utils_1.remove)(segments, quote);
29
44
  segments = segments.filter(n => [
30
45
  'face', 'text', 'image',
31
46
  'rpx', 'dice', 'poke', 'mention', 'mention_all',
32
- 'voice', 'file', 'audio',
47
+ 'voice', 'file', 'record',
33
48
  'forward', 'node',
34
49
  'music', 'share', 'xml', 'json', 'location', // 分享类
35
50
  ].includes(n.type));
36
51
  const element = V12_1.V12.fromSegment(segments);
37
- if (forward)
52
+ if (forwardNodes.length)
38
53
  element.unshift(
39
54
  // 构造抓发消息
40
55
  await this.makeForwardMsg(await Promise.all(
41
56
  // 处理转发消息段
42
- forward.data.nodes.filter(n => n.type === 'node').map(async (forwardNode) => {
57
+ forwardNodes.map(async (forwardNode) => {
43
58
  return {
44
59
  // 转发套转发处理
45
60
  message: (await processMessage.apply(this, [forwardNode.data.message])).element,
@@ -48,6 +63,6 @@ async function processMessage(message, source) {
48
63
  time: forwardNode.data.time
49
64
  };
50
65
  }))));
51
- return { element, quote: quote || source };
66
+ return { element, quote: quote || source, music, share };
52
67
  }
53
68
  exports.processMessage = processMessage;
package/lib/types.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export declare type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "mark" | "off";
2
- export declare type Dispose = () => any;
3
- export declare type MayBeArray<T extends any> = T | T[];
1
+ export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal" | "mark" | "off";
2
+ export type Dispose = () => any;
3
+ export type MayBeArray<T extends any> = T | T[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onebots",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "基于icqq的多例oneBot实现",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -50,7 +50,7 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "@koa/router": "^10.1.1",
53
- "icqq": "^0.0.13-7",
53
+ "icqq": "^0.0.21",
54
54
  "icqq-cq-enable": "^1.0.0",
55
55
  "js-yaml": "^4.1.0",
56
56
  "koa": "^2.13.4",
@@ -1,31 +0,0 @@
1
- port: 6727 # 监听端口
2
- general: # 通用配置,在单个配置省略时的默认值
3
- V11: # oneBotV11的通用配置
4
- heartbeat: 3 # 心跳间隔 (秒)
5
- access_token: '' # 访问api的token
6
- post_timeout: 15 # 上报超时时间,(秒)
7
- secret: '' # 上报数据的sha1签名密钥
8
- rate_limit_interval: 4 # ws心跳间隔(秒)
9
- post_message_format: string # "string"或"array"
10
- reconnect_interval: 3 # 重连间隔 (秒)
11
- use_http: true # 是否使用 http
12
- enable_cors: true # 是否允许跨域
13
- use_ws: true # 是否使用websocket
14
- http_reverse: [] # http上报地址
15
- ws_reverse: [] # 反向ws连接地址
16
- V12: # oneBotV12的通用配置
17
- heartbeat: 3 # 心跳间隔 (秒)
18
- access_token: '' # 访问api的token
19
- request_timeout: 15 # 上报超时时间 (秒)
20
- reconnect_interval: 3 # 重连间隔 (秒)
21
- enable_cors: true # 是否允许跨域
22
- use_http: true # 是否启用http
23
- use_ws: true # 是否启用 websocket
24
- webhook: [] # http 上报地址
25
- ws_reverse: [] # 反向ws连接地址
26
- log_level: info # 日志等级
27
- # 每个账号的单独配置(用于覆盖通用配置)
28
- 123456789:
29
- version: V11 # 使用的oneBot版本
30
- password: abcedfghi # 账号密码,未配置则扫码登陆
31
- # 。。。其他配置项参见上方对应oneBot版本的通用配置