@kotori-bot/kotori-plugin-adapter-onebot 1.2.0 → 1.2.1

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/adapter.js CHANGED
@@ -9,7 +9,7 @@ exports.OnebotAdapter = exports.config = void 0;
9
9
  * @Blog: https://hotaru.icu
10
10
  * @Date: 2023-09-29 14:31:09
11
11
  * @LastEditors: Hotaru biyuehuya@gmail.com
12
- * @LastEditTime: 2024-02-05 17:40:51
12
+ * @LastEditTime: 2024-02-16 15:33:09
13
13
  */
14
14
  const kotori_bot_1 = require("kotori-bot");
15
15
  const ws_1 = __importDefault(require("ws"));
@@ -19,7 +19,9 @@ const elements_1 = __importDefault(require("./elements"));
19
19
  exports.config = kotori_bot_1.Tsu.Intersection([
20
20
  kotori_bot_1.Tsu.Object({
21
21
  port: kotori_bot_1.Tsu.Number().int().range(1, 65535),
22
- address: kotori_bot_1.Tsu.String().regexp(/^ws(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/),
22
+ address: kotori_bot_1.Tsu.String()
23
+ .regexp(/^ws(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/)
24
+ .default('ws://127.0.0.1'),
23
25
  retry: kotori_bot_1.Tsu.Number().int().min(1).default(10)
24
26
  }),
25
27
  kotori_bot_1.Tsu.Union([
@@ -31,13 +33,14 @@ exports.config = kotori_bot_1.Tsu.Intersection([
31
33
  })
32
34
  ])
33
35
  ]);
36
+ const handleMsg = (msg) => msg.replace(/\[CQ:at,qq=(.*?)\]/g, '$1');
34
37
  class OnebotAdapter extends kotori_bot_1.Adapter {
35
38
  address;
36
39
  config;
37
40
  constructor(ctx, config, identity) {
38
41
  super(ctx, config, identity, api_1.default, new elements_1.default());
39
42
  this.config = config;
40
- this.address = `${this.config.address}:${this.config.port}`;
43
+ this.address = `${this.config.address ?? 'ws://127.0.0.1'}:${this.config.port}`;
41
44
  }
42
45
  handle(data) {
43
46
  if (data.post_type === 'message' && data.message_type === 'private') {
@@ -45,7 +48,7 @@ class OnebotAdapter extends kotori_bot_1.Adapter {
45
48
  type: kotori_bot_1.MessageScope.PRIVATE,
46
49
  userId: data.user_id,
47
50
  messageId: data.message_id,
48
- message: data.message,
51
+ message: handleMsg(data.message),
49
52
  sender: {
50
53
  nickname: data.sender.nickname,
51
54
  age: data.sender.age,
@@ -59,11 +62,14 @@ class OnebotAdapter extends kotori_bot_1.Adapter {
59
62
  type: kotori_bot_1.MessageScope.GROUP,
60
63
  userId: data.user_id,
61
64
  messageId: data.message_id,
62
- message: data.message,
65
+ message: handleMsg(data.message),
63
66
  sender: {
64
67
  nickname: data.sender.nickname,
65
68
  age: data.sender.age,
66
- sex: data.sender.sex
69
+ sex: data.sender.sex,
70
+ level: data.sender.level,
71
+ role: data.sender.role,
72
+ title: data.sender.title
67
73
  },
68
74
  groupId: data.group_id
69
75
  });
package/lib/api.d.ts CHANGED
@@ -13,21 +13,21 @@ export declare class OnebotApi extends Api {
13
13
  * @param {number} messageId 消息id
14
14
  * @return {void}
15
15
  */
16
- delete_msg(messageId: number): void;
16
+ deleteMsg(messageId: number): void;
17
17
  /**
18
18
  * @description: 设置群名
19
19
  * @param {number} groupId 群号
20
20
  * @param {string} groupName 新群名
21
21
  * @return {void}
22
22
  */
23
- set_group_name(groupId: number, groupName: string): void;
23
+ setGroupName(groupId: number, groupName: string): void;
24
24
  /**
25
25
  * @description: 设置群头像
26
26
  * @param {number} groupId 群号
27
27
  * @param {string} image 图片路径
28
28
  * @return {void}
29
29
  */
30
- set_group_avatar(groupId: number, image: string): void;
30
+ setGroupAvatar(groupId: number, image: string): void;
31
31
  /**
32
32
  * @description: 设置群管理员
33
33
  * @param {number} groupId 群号
@@ -35,7 +35,7 @@ export declare class OnebotApi extends Api {
35
35
  * @param {boolean} enable true为设置,false取消,默认true
36
36
  * @return {void}
37
37
  */
38
- set_group_admin(groupId: number, userId: number, enable?: boolean): void;
38
+ setGroupAdmin(groupId: number, userId: number, enable?: boolean): void;
39
39
  /**
40
40
  * @description: 设置群名片(群备注)
41
41
  * @param {number} groupId 群号
@@ -43,7 +43,7 @@ export declare class OnebotApi extends Api {
43
43
  * @param {string} card 群名片内容,不填或空字符串表示删除群名片
44
44
  * @return {void}
45
45
  */
46
- set_group_card(groupId: number, userId: number, card: string): void;
46
+ setGroupCard(groupId: number, userId: number, card: string): void;
47
47
  /**
48
48
  * @description: 群禁言
49
49
  * @param {number} groupId 群号
package/lib/api.js CHANGED
@@ -6,7 +6,7 @@ exports.OnebotApi = void 0;
6
6
  * @Blog: https://hotaru.icu
7
7
  * @Date: 2023-09-29 14:31:13
8
8
  * @LastEditors: Hotaru biyuehuya@gmail.com
9
- * @LastEditTime: 2024-02-05 17:15:06
9
+ * @LastEditTime: 2024-02-21 10:40:20
10
10
  */
11
11
  const kotori_bot_1 = require("kotori-bot");
12
12
  class OnebotApi extends kotori_bot_1.Api {
@@ -31,7 +31,7 @@ class OnebotApi extends kotori_bot_1.Api {
31
31
  * @param {number} messageId 消息id
32
32
  * @return {void}
33
33
  */
34
- delete_msg(messageId) {
34
+ deleteMsg(messageId) {
35
35
  this.adapter.send('delete_msg', { messageId });
36
36
  }
37
37
  /**
@@ -40,7 +40,7 @@ class OnebotApi extends kotori_bot_1.Api {
40
40
  * @param {string} groupName 新群名
41
41
  * @return {void}
42
42
  */
43
- set_group_name(groupId, groupName) {
43
+ setGroupName(groupId, groupName) {
44
44
  this.adapter.send('set_group_name', { group_id: groupId, group_name: groupName });
45
45
  }
46
46
  /**
@@ -49,7 +49,7 @@ class OnebotApi extends kotori_bot_1.Api {
49
49
  * @param {string} image 图片路径
50
50
  * @return {void}
51
51
  */
52
- set_group_avatar(groupId, image) {
52
+ setGroupAvatar(groupId, image) {
53
53
  this.adapter.send('set_group_portrait', { group_id: groupId, file: image, cache: false });
54
54
  }
55
55
  /**
@@ -59,7 +59,7 @@ class OnebotApi extends kotori_bot_1.Api {
59
59
  * @param {boolean} enable true为设置,false取消,默认true
60
60
  * @return {void}
61
61
  */
62
- set_group_admin(groupId, userId, enable = true) {
62
+ setGroupAdmin(groupId, userId, enable = true) {
63
63
  this.adapter.send('set_group_admin', { group_id: groupId, user_id: userId, enable });
64
64
  }
65
65
  /**
@@ -69,7 +69,7 @@ class OnebotApi extends kotori_bot_1.Api {
69
69
  * @param {string} card 群名片内容,不填或空字符串表示删除群名片
70
70
  * @return {void}
71
71
  */
72
- set_group_card(groupId, userId, card) {
72
+ setGroupCard(groupId, userId, card) {
73
73
  this.adapter.send('set_group_card', { group_id: groupId, user_id: userId, card });
74
74
  }
75
75
  /**
@@ -9,13 +9,13 @@ exports.WsServer = void 0;
9
9
  * @Blog: https://hotaru.icu
10
10
  * @Date: 2023-06-24 15:12:55
11
11
  * @LastEditors: Hotaru biyuehuya@gmail.com
12
- * @LastEditTime: 2023-10-05 18:49:48
12
+ * @LastEditTime: 2024-02-20 20:17:46
13
13
  */
14
14
  const ws_1 = __importDefault(require("ws"));
15
15
  const WsServer = async (port) => new Promise((resolve, reject) => {
16
16
  try {
17
17
  const WebSocketServer = new ws_1.default.Server({ port });
18
- WebSocketServer.on('connection', ws => {
18
+ WebSocketServer.on('connection', (ws) => {
19
19
  resolve([ws, WebSocketServer]);
20
20
  });
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kotori-bot/kotori-plugin-adapter-onebot",
3
- "version": "v1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Adapter For Onebot (go-cqhttp)",
5
5
  "main": "lib/index.js",
6
6
  "keywords": [
@@ -17,7 +17,7 @@
17
17
  ],
18
18
  "author": "Hotaru <biyuehuya@gmail.com>",
19
19
  "peerDependencies": {
20
- "kotori-bot": "^v1.2.0"
20
+ "kotori-bot": "^1.3.0"
21
21
  },
22
22
  "dependencies": {
23
23
  "@types/ws": "^8.5.8",