@alemonjs/onebot 0.0.2 → 0.1.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/index-11.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineBot, getConfig, Text, At, OnProcessor, useParse } from 'alemonjs';
1
+ import { defineBot, getConfig, createHash, Text, At, OnProcessor, useParse } from 'alemonjs';
2
2
  import { OneBotClient } from './sdk-v11/wss.js';
3
3
 
4
4
  var INDEXV11 = defineBot(() => {
@@ -35,6 +35,21 @@ var INDEXV11 = defineBot(() => {
35
35
  for (const item of arr) {
36
36
  msg = msg.replace(item.text, '').trim();
37
37
  }
38
+ const url = `https://q1.qlogo.cn/g?b=qq&s=0&nk=${event.user_id}`;
39
+ const UserAvatar = {
40
+ toBuffer: async () => {
41
+ const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
42
+ return Buffer.from(arrayBuffer);
43
+ },
44
+ toBase64: async () => {
45
+ const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
46
+ return Buffer.from(arrayBuffer).toString('base64');
47
+ },
48
+ toURL: async () => {
49
+ return url;
50
+ }
51
+ };
52
+ const UserKey = createHash(`onebot:${event.user_id}`);
38
53
  // 定义消
39
54
  const e = {
40
55
  // 平台类型
@@ -46,16 +61,17 @@ var INDEXV11 = defineBot(() => {
46
61
  ChannelId: String(event.group_id),
47
62
  // 是否是主人
48
63
  IsMaster: uis.includes(String(event.user_id)),
49
- // 用户ID
64
+ // 用户Id
50
65
  UserId: String(event.user_id),
51
66
  // 用户名
52
67
  UserName: event.sender.nickname,
68
+ UserKey,
53
69
  // 用户头像
54
- UserAvatar: `https://q1.qlogo.cn/g?b=qq&s=0&nk=${event.user_id}`,
70
+ UserAvatar: UserAvatar,
55
71
  // 格式化数据
56
- MsgId: String(event.message_id),
72
+ MessageId: String(event.message_id),
57
73
  // 用户消息
58
- Megs: [
74
+ MessageBody: [
59
75
  Text(msg),
60
76
  ...at_users.map(item => At(item.id, 'user', {
61
77
  name: item.name,
@@ -63,8 +79,10 @@ var INDEXV11 = defineBot(() => {
63
79
  bot: item.bot
64
80
  }))
65
81
  ],
82
+ MessageText: msg,
83
+ // 用户openId
66
84
  // 用户openId
67
- OpenID: String(event.user_id),
85
+ OpenId: String(event.user_id),
68
86
  // 创建时间
69
87
  CreateAt: Date.now(),
70
88
  // 标签
@@ -83,7 +101,7 @@ var INDEXV11 = defineBot(() => {
83
101
  });
84
102
  client.on('DIRECT_MESSAGE', () => {
85
103
  // const e = {
86
- // isMaster: event.user_id == masterID,
104
+ // isMaster: event.user_id == masterId,
87
105
  // msg_txt: event.raw_message,
88
106
  // msg: event.raw_message.trim(),
89
107
  // msg_id: event.message_id,
@@ -105,9 +123,11 @@ var INDEXV11 = defineBot(() => {
105
123
  send: (event, val) => {
106
124
  if (val.length < 0)
107
125
  return Promise.all([]);
108
- const content = useParse(val, 'Text');
126
+ const content = useParse({
127
+ MessageBody: val
128
+ }, 'Text');
109
129
  if (content) {
110
- return Promise.all([content].map(item => client.sendGroupMsg({
130
+ return Promise.all([content].map(item => client.sendGroupMessage({
111
131
  group_id: event.ChannelId,
112
132
  message: [
113
133
  {
@@ -119,9 +139,11 @@ var INDEXV11 = defineBot(() => {
119
139
  ]
120
140
  })));
121
141
  }
122
- const images = useParse(val, 'Image');
142
+ const images = useParse({
143
+ MessageBody: val
144
+ }, 'Image');
123
145
  if (images) {
124
- return Promise.all(images.map(item => client.sendGroupMsg({
146
+ return Promise.all(images.map(item => client.sendGroupMessage({
125
147
  group_id: event.ChannelId,
126
148
  message: [
127
149
  {
package/lib/index-12.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineBot, getConfig, Text, At, OnProcessor, useParse } from 'alemonjs';
1
+ import { defineBot, getConfig, createHash, Text, At, OnProcessor, useParse } from 'alemonjs';
2
2
  import { OneBotClient } from './sdk-v12/wss.js';
3
3
 
4
4
  var INDEXV12 = defineBot(() => {
@@ -53,6 +53,21 @@ var INDEXV12 = defineBot(() => {
53
53
  for (const item of arr) {
54
54
  msg = msg.replace(item.text, '').trim();
55
55
  }
56
+ const url = event.platform == 'qq' ? `https://q1.qlogo.cn/g?b=qq&s=0&nk=${event.user_id}` : '';
57
+ const UserAvatar = {
58
+ toBuffer: async () => {
59
+ const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
60
+ return Buffer.from(arrayBuffer);
61
+ },
62
+ toBase64: async () => {
63
+ const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
64
+ return Buffer.from(arrayBuffer).toString('base64');
65
+ },
66
+ toURL: async () => {
67
+ return url;
68
+ }
69
+ };
70
+ const UserKey = createHash(`onebot:${event.user_id}`);
56
71
  // 定义消
57
72
  const e = {
58
73
  // 平台类型
@@ -64,16 +79,17 @@ var INDEXV12 = defineBot(() => {
64
79
  ChannelId: event.group_id,
65
80
  // 是否是主人
66
81
  IsMaster: uis.includes(String(event.user_id)),
67
- // 用户ID
82
+ // 用户Id
68
83
  UserId: event.user_id,
84
+ UserKey,
69
85
  // 用户名
70
86
  UserName: event.sender.nickname,
71
87
  // 用户头像
72
- UserAvatar: event.platform == 'qq' ? `https://q1.qlogo.cn/g?b=qq&s=0&nk=${event.user_id}` : '',
88
+ UserAvatar: UserAvatar,
73
89
  // 格式化数据
74
- MsgId: event.message_id,
90
+ MessageId: event.message_id,
75
91
  // 用户消息
76
- Megs: [
92
+ MessageBody: [
77
93
  Text(msg),
78
94
  ...at_users.map(item => At(item.id, 'user', {
79
95
  name: item.name,
@@ -81,8 +97,10 @@ var INDEXV12 = defineBot(() => {
81
97
  bot: item.bot
82
98
  }))
83
99
  ],
100
+ MessageText: msg,
101
+ // 表情
84
102
  // 用户openId
85
- OpenID: event.user_id,
103
+ OpenId: event.user_id,
86
104
  //
87
105
  tag: 'MESSAGES',
88
106
  // 创建时间
@@ -101,7 +119,7 @@ var INDEXV12 = defineBot(() => {
101
119
  });
102
120
  client.on('DIRECT_MESSAGE', () => {
103
121
  // const e = {
104
- // isMaster: event.user_id == masterID,
122
+ // isMaster: event.user_id == masterId,
105
123
  // msg_txt: event.raw_message,
106
124
  // msg: event.raw_message.trim(),
107
125
  // msg_id: event.message_id,
@@ -123,9 +141,11 @@ var INDEXV12 = defineBot(() => {
123
141
  send: (event, val) => {
124
142
  if (val.length < 0)
125
143
  return Promise.all([]);
126
- const content = useParse(val, 'Text');
144
+ const content = useParse({
145
+ MessageBody: val
146
+ }, 'Text');
127
147
  if (content) {
128
- return Promise.all([content].map(item => client.sendGroupMsg({
148
+ return Promise.all([content].map(item => client.sendGroupMessage({
129
149
  group_id: event.ChannelId,
130
150
  message: [
131
151
  {
@@ -137,9 +157,11 @@ var INDEXV12 = defineBot(() => {
137
157
  ]
138
158
  })));
139
159
  }
140
- const images = useParse(val, 'Image');
160
+ const images = useParse({
161
+ MessageBody: val
162
+ }, 'Image');
141
163
  if (images) {
142
- return Promise.all(images.map(item => client.sendGroupMsg({
164
+ return Promise.all(images.map(item => client.sendGroupMessage({
143
165
  group_id: event.ChannelId,
144
166
  message: [
145
167
  {
@@ -111,7 +111,7 @@ class OneBotClient {
111
111
  * @param options
112
112
  * @returns
113
113
  */
114
- sendGroupMsg(options) {
114
+ sendGroupMessage(options) {
115
115
  return this.#ws.send(JSON.stringify({
116
116
  action: 'send_group_msg',
117
117
  params: options,
@@ -122,7 +122,7 @@ class OneBotClient {
122
122
  * @param options
123
123
  * @returns
124
124
  */
125
- sendPrivateMsg(options) {
125
+ sendPrivateMessage(options) {
126
126
  return this.#ws.send(JSON.stringify({
127
127
  action: 'send_private_msg',
128
128
  params: options,
@@ -99,7 +99,7 @@ class OneBotClient {
99
99
  * @param options
100
100
  * @returns
101
101
  */
102
- sendGroupMsg(options) {
102
+ sendGroupMessage(options) {
103
103
  return this.#ws.send(JSON.stringify({
104
104
  action: 'send_group_msg',
105
105
  params: options,
@@ -110,7 +110,7 @@ class OneBotClient {
110
110
  * @param options
111
111
  * @returns
112
112
  */
113
- sendPrivateMsg(options) {
113
+ sendPrivateMessage(options) {
114
114
  return this.#ws.send(JSON.stringify({
115
115
  action: 'send_private_msg',
116
116
  params: options,
package/package.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
2
  "name": "@alemonjs/onebot",
3
- "version": "0.0.2",
3
+ "version": "0.1.1",
4
4
  "description": "onebot",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "main": "lib/index.js",
9
- "dependencies": {
10
- "chat-space": "^0.0.6"
11
- },
12
9
  "types": "lib",
13
10
  "exports": {
14
11
  ".": {
@@ -26,9 +23,9 @@
26
23
  "registry": "https://registry.npmjs.org",
27
24
  "access": "public"
28
25
  },
29
- "bugs": "https://github.com/ningmengchongshui/alemonjs/issues",
26
+ "bugs": "https://github.com/lemonade-lab/alemonjs/issues",
30
27
  "repository": {
31
28
  "type": "git",
32
- "url": "https://github.com/ningmengchongshui/alemonjs.git"
29
+ "url": "https://github.com/lemonade-lab/alemonjs.git"
33
30
  }
34
31
  }