@alemonjs/onebot 0.1.1 → 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, createHash, 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;
@@ -49,39 +50,30 @@ var INDEXV11 = defineBot(() => {
49
50
  return url;
50
51
  }
51
52
  };
52
- const UserKey = createHash(`onebot:${event.user_id}`);
53
+ const UserId = String(event.user_id);
54
+ const UserKey = useUserHashKey({
55
+ Platform,
56
+ UserId
57
+ });
53
58
  // 定义消
54
59
  const e = {
55
60
  // 平台类型
56
- Platform: 'onebot',
61
+ Platform: Platform,
57
62
  // 频道
58
63
  GuildId: String(event.group_id),
59
64
  // guild_name: event.group_name,
60
65
  // 子频道
61
66
  ChannelId: String(event.group_id),
62
- // 是否是主人
63
67
  IsMaster: uis.includes(String(event.user_id)),
64
- // 用户Id
65
- UserId: String(event.user_id),
66
- // 用户名
68
+ IsBot: false,
69
+ UserId: UserId,
67
70
  UserName: event.sender.nickname,
68
71
  UserKey,
69
- // 用户头像
70
72
  UserAvatar: UserAvatar,
71
- // 格式化数据
73
+ // message
72
74
  MessageId: String(event.message_id),
73
- // 用户消息
74
- MessageBody: [
75
- Text(msg),
76
- ...at_users.map(item => At(item.id, 'user', {
77
- name: item.name,
78
- avatar: item.avatar,
79
- bot: item.bot
80
- }))
81
- ],
82
75
  MessageText: msg,
83
76
  // 用户openId
84
- // 用户openId
85
77
  OpenId: String(event.user_id),
86
78
  // 创建时间
87
79
  CreateAt: Date.now(),
@@ -123,9 +115,10 @@ var INDEXV11 = defineBot(() => {
123
115
  send: (event, val) => {
124
116
  if (val.length < 0)
125
117
  return Promise.all([]);
126
- const content = useParse({
127
- MessageBody: val
128
- }, 'Text');
118
+ const content = val
119
+ .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
120
+ .map(item => item.value)
121
+ .join('');
129
122
  if (content) {
130
123
  return Promise.all([content].map(item => client.sendGroupMessage({
131
124
  group_id: event.ChannelId,
@@ -139,9 +132,7 @@ var INDEXV11 = defineBot(() => {
139
132
  ]
140
133
  })));
141
134
  }
142
- const images = useParse({
143
- MessageBody: val
144
- }, 'Image');
135
+ const images = val.filter(item => item.type == 'Image').map(item => item.value);
145
136
  if (images) {
146
137
  return Promise.all(images.map(item => client.sendGroupMessage({
147
138
  group_id: event.ChannelId,
@@ -156,6 +147,9 @@ var INDEXV11 = defineBot(() => {
156
147
  })));
157
148
  }
158
149
  return Promise.all([]);
150
+ },
151
+ mention: async () => {
152
+ return [];
159
153
  }
160
154
  }
161
155
  }
package/lib/index-12.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineBot, getConfig, createHash, 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
  //
@@ -67,45 +68,34 @@ var INDEXV12 = defineBot(() => {
67
68
  return url;
68
69
  }
69
70
  };
70
- const UserKey = createHash(`onebot:${event.user_id}`);
71
+ const UserId = String(event.user_id);
72
+ const UserKey = useUserHashKey({
73
+ Platform,
74
+ UserId
75
+ });
71
76
  // 定义消
72
77
  const e = {
73
78
  // 平台类型
74
- Platform: 'onebot',
79
+ Platform: Platform,
75
80
  // 频道
76
81
  GuildId: event.group_id,
77
82
  // guild_name: event.group_name,
78
83
  // 子频道
79
84
  ChannelId: event.group_id,
80
- // 是否是主人
85
+ // uyser
81
86
  IsMaster: uis.includes(String(event.user_id)),
82
- // 用户Id
83
- UserId: event.user_id,
87
+ UserId: UserId,
88
+ IsBot: false,
84
89
  UserKey,
85
- // 用户名
86
90
  UserName: event.sender.nickname,
87
- // 用户头像
88
91
  UserAvatar: UserAvatar,
89
- // 格式化数据
92
+ // message
90
93
  MessageId: event.message_id,
91
- // 用户消息
92
- MessageBody: [
93
- Text(msg),
94
- ...at_users.map(item => At(item.id, 'user', {
95
- name: item.name,
96
- avatar: item.avatar,
97
- bot: item.bot
98
- }))
99
- ],
100
94
  MessageText: msg,
101
- // 表情
102
- // 用户openId
103
95
  OpenId: event.user_id,
104
- //
105
- tag: 'MESSAGES',
106
- // 创建时间
107
96
  CreateAt: Date.now(),
108
- //
97
+ // ohther
98
+ tag: 'MESSAGES',
109
99
  value: null
110
100
  };
111
101
  // 当访问的时候获取
@@ -141,9 +131,10 @@ var INDEXV12 = defineBot(() => {
141
131
  send: (event, val) => {
142
132
  if (val.length < 0)
143
133
  return Promise.all([]);
144
- const content = useParse({
145
- MessageBody: val
146
- }, 'Text');
134
+ const content = val
135
+ .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
136
+ .map(item => item.value)
137
+ .join('');
147
138
  if (content) {
148
139
  return Promise.all([content].map(item => client.sendGroupMessage({
149
140
  group_id: event.ChannelId,
@@ -157,9 +148,7 @@ var INDEXV12 = defineBot(() => {
157
148
  ]
158
149
  })));
159
150
  }
160
- const images = useParse({
161
- MessageBody: val
162
- }, 'Image');
151
+ const images = val.filter(item => item.type == 'Image').map(item => item.value);
163
152
  if (images) {
164
153
  return Promise.all(images.map(item => client.sendGroupMessage({
165
154
  group_id: event.ChannelId,
@@ -174,6 +163,9 @@ var INDEXV12 = defineBot(() => {
174
163
  })));
175
164
  }
176
165
  return Promise.all([]);
166
+ },
167
+ mention: async () => {
168
+ return [];
177
169
  }
178
170
  }
179
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/onebot",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "onebot",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",