@alemonjs/onebot 0.1.0 → 0.2.0

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/README.md CHANGED
@@ -8,6 +8,6 @@
8
8
  onebot:
9
9
  url: ''
10
10
  token: ''
11
- master_id: null
11
+ master_key: null
12
12
  version: 'v11'
13
13
  ```
package/lib/index-11.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineBot, getConfig, Text, At, OnProcessor, useParse } from 'alemonjs';
1
+ import { defineBot, getConfig, useUserHashKey, OnProcessor } from 'alemonjs';
2
2
  import { OneBotClient } from './sdk-v11/wss.js';
3
3
 
4
4
  var INDEXV11 = defineBot(() => {
@@ -13,6 +13,7 @@ var INDEXV11 = defineBot(() => {
13
13
  // token
14
14
  access_token: config?.token ?? ''
15
15
  });
16
+ const Platform = 'onebot';
16
17
  //
17
18
  client.connect();
18
19
  //
@@ -26,7 +27,7 @@ var INDEXV11 = defineBot(() => {
26
27
  const uis = config.master_uids ?? [];
27
28
  let msg = '';
28
29
  const arr = [];
29
- let at_users = [];
30
+ // let at_users = []
30
31
  for (const item of event.message) {
31
32
  if (item.type == 'text') {
32
33
  msg = item.data.text;
@@ -35,41 +36,45 @@ var INDEXV11 = defineBot(() => {
35
36
  for (const item of arr) {
36
37
  msg = msg.replace(item.text, '').trim();
37
38
  }
39
+ const url = `https://q1.qlogo.cn/g?b=qq&s=0&nk=${event.user_id}`;
40
+ const UserAvatar = {
41
+ toBuffer: async () => {
42
+ const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
43
+ return Buffer.from(arrayBuffer);
44
+ },
45
+ toBase64: async () => {
46
+ const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
47
+ return Buffer.from(arrayBuffer).toString('base64');
48
+ },
49
+ toURL: async () => {
50
+ return url;
51
+ }
52
+ };
53
+ const UserId = String(event.user_id);
54
+ const UserKey = useUserHashKey({
55
+ Platform,
56
+ UserId
57
+ });
38
58
  // 定义消
39
59
  const e = {
40
60
  // 平台类型
41
- Platform: 'onebot',
61
+ Platform: Platform,
42
62
  // 频道
43
63
  GuildId: String(event.group_id),
44
64
  // guild_name: event.group_name,
45
65
  // 子频道
46
66
  ChannelId: String(event.group_id),
47
- // 是否是主人
48
67
  IsMaster: uis.includes(String(event.user_id)),
49
- // 用户ID
50
- UserId: String(event.user_id),
51
- GuildIdName: '',
52
- GuildIdAvatar: '',
53
- ChannelName: '',
54
- // 用户名
68
+ IsBot: false,
69
+ UserId: UserId,
55
70
  UserName: event.sender.nickname,
56
- // 用户头像
57
- UserAvatar: `https://q1.qlogo.cn/g?b=qq&s=0&nk=${event.user_id}`,
58
- // 格式化数据
59
- MsgId: String(event.message_id),
60
- // 用户消息
61
- MessageBody: [
62
- Text(msg),
63
- ...at_users.map(item => At(item.id, 'user', {
64
- name: item.name,
65
- avatar: item.avatar,
66
- bot: item.bot
67
- }))
68
- ],
71
+ UserKey,
72
+ UserAvatar: UserAvatar,
73
+ // message
74
+ MessageId: String(event.message_id),
69
75
  MessageText: msg,
70
76
  // 用户openId
71
- // 用户openId
72
- OpenID: String(event.user_id),
77
+ OpenId: String(event.user_id),
73
78
  // 创建时间
74
79
  CreateAt: Date.now(),
75
80
  // 标签
@@ -88,7 +93,7 @@ var INDEXV11 = defineBot(() => {
88
93
  });
89
94
  client.on('DIRECT_MESSAGE', () => {
90
95
  // const e = {
91
- // isMaster: event.user_id == masterID,
96
+ // isMaster: event.user_id == masterId,
92
97
  // msg_txt: event.raw_message,
93
98
  // msg: event.raw_message.trim(),
94
99
  // msg_id: event.message_id,
@@ -110,11 +115,12 @@ var INDEXV11 = defineBot(() => {
110
115
  send: (event, val) => {
111
116
  if (val.length < 0)
112
117
  return Promise.all([]);
113
- const content = useParse({
114
- MessageBody: val
115
- }, 'Text');
118
+ const content = val
119
+ .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
120
+ .map(item => item.value)
121
+ .join('');
116
122
  if (content) {
117
- return Promise.all([content].map(item => client.sendGroupMsg({
123
+ return Promise.all([content].map(item => client.sendGroupMessage({
118
124
  group_id: event.ChannelId,
119
125
  message: [
120
126
  {
@@ -126,11 +132,9 @@ var INDEXV11 = defineBot(() => {
126
132
  ]
127
133
  })));
128
134
  }
129
- const images = useParse({
130
- MessageBody: val
131
- }, 'Image');
135
+ const images = val.filter(item => item.type == 'Image').map(item => item.value);
132
136
  if (images) {
133
- return Promise.all(images.map(item => client.sendGroupMsg({
137
+ return Promise.all(images.map(item => client.sendGroupMessage({
134
138
  group_id: event.ChannelId,
135
139
  message: [
136
140
  {
@@ -143,6 +147,9 @@ var INDEXV11 = defineBot(() => {
143
147
  })));
144
148
  }
145
149
  return Promise.all([]);
150
+ },
151
+ mention: async () => {
152
+ return [];
146
153
  }
147
154
  }
148
155
  }
package/lib/index-12.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineBot, getConfig, Text, At, OnProcessor, useParse } from 'alemonjs';
1
+ import { defineBot, getConfig, useUserHashKey, OnProcessor } from 'alemonjs';
2
2
  import { OneBotClient } from './sdk-v12/wss.js';
3
3
 
4
4
  var INDEXV12 = defineBot(() => {
@@ -13,6 +13,7 @@ var INDEXV12 = defineBot(() => {
13
13
  // token
14
14
  access_token: config?.token ?? ''
15
15
  });
16
+ const Platform = 'onebot';
16
17
  //
17
18
  client.connect();
18
19
  //
@@ -53,46 +54,48 @@ var INDEXV12 = defineBot(() => {
53
54
  for (const item of arr) {
54
55
  msg = msg.replace(item.text, '').trim();
55
56
  }
57
+ const url = event.platform == 'qq' ? `https://q1.qlogo.cn/g?b=qq&s=0&nk=${event.user_id}` : '';
58
+ const UserAvatar = {
59
+ toBuffer: async () => {
60
+ const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
61
+ return Buffer.from(arrayBuffer);
62
+ },
63
+ toBase64: async () => {
64
+ const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
65
+ return Buffer.from(arrayBuffer).toString('base64');
66
+ },
67
+ toURL: async () => {
68
+ return url;
69
+ }
70
+ };
71
+ const UserId = String(event.user_id);
72
+ const UserKey = useUserHashKey({
73
+ Platform,
74
+ UserId
75
+ });
56
76
  // 定义消
57
77
  const e = {
58
78
  // 平台类型
59
- Platform: 'onebot',
79
+ Platform: Platform,
60
80
  // 频道
61
81
  GuildId: event.group_id,
62
82
  // guild_name: event.group_name,
63
83
  // 子频道
64
84
  ChannelId: event.group_id,
65
- // 是否是主人
85
+ // uyser
66
86
  IsMaster: uis.includes(String(event.user_id)),
67
- // 用户ID
68
- UserId: event.user_id,
69
- // 用户名
87
+ UserId: UserId,
88
+ IsBot: false,
89
+ UserKey,
70
90
  UserName: event.sender.nickname,
71
- GuildIdName: '',
72
- GuildIdAvatar: '',
73
- ChannelName: '',
74
- // 用户头像
75
- UserAvatar: event.platform == 'qq' ? `https://q1.qlogo.cn/g?b=qq&s=0&nk=${event.user_id}` : '',
76
- // 格式化数据
77
- MsgId: event.message_id,
78
- // 用户消息
79
- MessageBody: [
80
- Text(msg),
81
- ...at_users.map(item => At(item.id, 'user', {
82
- name: item.name,
83
- avatar: item.avatar,
84
- bot: item.bot
85
- }))
86
- ],
91
+ UserAvatar: UserAvatar,
92
+ // message
93
+ MessageId: event.message_id,
87
94
  MessageText: msg,
88
- // 表情
89
- // 用户openId
90
- OpenID: event.user_id,
91
- //
92
- tag: 'MESSAGES',
93
- // 创建时间
95
+ OpenId: event.user_id,
94
96
  CreateAt: Date.now(),
95
- //
97
+ // ohther
98
+ tag: 'MESSAGES',
96
99
  value: null
97
100
  };
98
101
  // 当访问的时候获取
@@ -106,7 +109,7 @@ var INDEXV12 = defineBot(() => {
106
109
  });
107
110
  client.on('DIRECT_MESSAGE', () => {
108
111
  // const e = {
109
- // isMaster: event.user_id == masterID,
112
+ // isMaster: event.user_id == masterId,
110
113
  // msg_txt: event.raw_message,
111
114
  // msg: event.raw_message.trim(),
112
115
  // msg_id: event.message_id,
@@ -128,11 +131,12 @@ var INDEXV12 = defineBot(() => {
128
131
  send: (event, val) => {
129
132
  if (val.length < 0)
130
133
  return Promise.all([]);
131
- const content = useParse({
132
- MessageBody: val
133
- }, 'Text');
134
+ const content = val
135
+ .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
136
+ .map(item => item.value)
137
+ .join('');
134
138
  if (content) {
135
- return Promise.all([content].map(item => client.sendGroupMsg({
139
+ return Promise.all([content].map(item => client.sendGroupMessage({
136
140
  group_id: event.ChannelId,
137
141
  message: [
138
142
  {
@@ -144,11 +148,9 @@ var INDEXV12 = defineBot(() => {
144
148
  ]
145
149
  })));
146
150
  }
147
- const images = useParse({
148
- MessageBody: val
149
- }, 'Image');
151
+ const images = val.filter(item => item.type == 'Image').map(item => item.value);
150
152
  if (images) {
151
- return Promise.all(images.map(item => client.sendGroupMsg({
153
+ return Promise.all(images.map(item => client.sendGroupMessage({
152
154
  group_id: event.ChannelId,
153
155
  message: [
154
156
  {
@@ -161,6 +163,9 @@ var INDEXV12 = defineBot(() => {
161
163
  })));
162
164
  }
163
165
  return Promise.all([]);
166
+ },
167
+ mention: async () => {
168
+ return [];
164
169
  }
165
170
  }
166
171
  }
package/lib/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
- declare const _default: () => typeof global.alemonjs;
1
+ import * as alemonjs from 'alemonjs';
2
+
3
+ declare const _default: () => alemonjs.ClientAPI;
2
4
 
3
5
  export { _default as default };
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/onebot",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "onebot",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",