@alemonjs/qq-bot 0.0.8 → 0.0.10

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.
Files changed (41) hide show
  1. package/README.md +2 -1
  2. package/dist/assets/index.css +476 -0
  3. package/dist/assets/index.js +11032 -0
  4. package/dist/index.html +15 -0
  5. package/lib/api.d.ts +975 -0
  6. package/lib/api.js +1172 -1156
  7. package/lib/client.d.ts +26 -0
  8. package/lib/client.js +201 -217
  9. package/lib/config.js +2 -2
  10. package/lib/desktop.d.ts +3 -0
  11. package/lib/desktop.js +66 -0
  12. package/lib/from.js +27 -34
  13. package/lib/index.d.ts +4 -1
  14. package/lib/index.js +406 -405
  15. package/lib/message/AT_MESSAGE_CREATE.d.ts +37 -0
  16. package/lib/message/C2C_MESSAGE_CREATE.d.ts +11 -0
  17. package/lib/message/CHANNEL_CREATE.d.ts +17 -0
  18. package/lib/message/CHANNEL_DELETE.d.ts +22 -0
  19. package/lib/message/CHANNEL_UPDATE.d.ts +22 -0
  20. package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +36 -0
  21. package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +24 -0
  22. package/lib/message/ERROR.d.ts +3 -0
  23. package/lib/message/GROUP_AT_MESSAGE_CREATE.d.ts +16 -0
  24. package/lib/message/GUILD_CREATE.d.ts +22 -0
  25. package/lib/message/GUILD_DELETE.d.ts +22 -0
  26. package/lib/message/GUILD_MEMBER_ADD.d.ts +21 -0
  27. package/lib/message/GUILD_MEMBER_REMOVE.d.ts +21 -0
  28. package/lib/message/GUILD_MEMBER_UPDATE.d.ts +21 -0
  29. package/lib/message/GUILD_UPDATE.d.ts +22 -0
  30. package/lib/message/INTERACTION_CREATE.d.ts +8 -0
  31. package/lib/message/MESSAGE_CREATE.d.ts +11 -0
  32. package/lib/message/MESSAGE_DELETE.d.ts +11 -0
  33. package/lib/message/MESSAGE_REACTION_ADD.d.ts +15 -0
  34. package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +15 -0
  35. package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +21 -0
  36. package/lib/message/READY.d.ts +11 -0
  37. package/lib/message.d.ts +49 -0
  38. package/lib/send/index.js +230 -192
  39. package/lib/typing.d.ts +73 -0
  40. package/lib/webhook.js +46 -48
  41. package/package.json +24 -2
package/lib/send/index.js CHANGED
@@ -1,101 +1,111 @@
1
1
  const GROUP_AT_MESSAGE_CREATE = (client, event, val) => {
2
- const content = val
3
- .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
4
- .map(item => {
5
- if (item.type == 'Link') {
6
- return `[${item.options?.title ?? item.value}](${item.value})`;
2
+ const content = val
3
+ .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
4
+ .map(item => {
5
+ if (item.type == 'Link') {
6
+ return `[${item.options?.title ?? item.value}](${item.value})`
7
+ } else if (item.type == 'Mention') {
8
+ if (
9
+ item.value == 'everyone' ||
10
+ item.value == 'all' ||
11
+ item.value == '' ||
12
+ typeof item.value != 'string'
13
+ ) {
14
+ return ``
7
15
  }
8
- else if (item.type == 'Mention') {
9
- if (item.value == 'everyone' ||
10
- item.value == 'all' ||
11
- item.value == '' ||
12
- typeof item.value != 'string') {
13
- return ``;
14
- }
15
- if (item.options?.belong == 'user') {
16
- return `<@${item.value}>`;
17
- }
18
- return '';
19
- }
20
- else if (item.type == 'Text') {
21
- return item.value;
16
+ if (item.options?.belong == 'user') {
17
+ return `<@${item.value}>`
22
18
  }
19
+ return ''
20
+ } else if (item.type == 'Text') {
21
+ return item.value
22
+ }
23
23
  })
24
- .join('');
25
- if (content) {
26
- return Promise.all([content].map(item => client.groupOpenMessages(event.GuildId, {
27
- content: item,
28
- msg_id: event.MessageId,
29
- msg_type: 0,
30
- msg_seq: client.getMessageSeq(event.MessageId)
31
- })));
32
- }
33
- const images = val.filter(item => item.type == 'Image').map(item => item.value);
34
- if (images) {
35
- return Promise.all(images.map(async (msg) => {
36
- const file_info = await client
37
- .postRichMediaByGroup(event.GuildId, {
38
- file_type: 1,
39
- file_data: msg.toString('base64')
40
- })
41
- .then(res => res?.file_info);
42
- if (!file_info)
43
- return Promise.resolve(null);
44
- return client.groupOpenMessages(event.GuildId, {
45
- content: '',
46
- media: {
47
- file_info
48
- },
49
- msg_id: event.MessageId,
50
- msg_type: 7,
51
- msg_seq: client.getMessageSeq(event.MessageId)
52
- });
53
- }));
54
- }
55
- return [];
56
- };
24
+ .join('')
25
+ if (content) {
26
+ return Promise.all(
27
+ [content].map(item =>
28
+ client.groupOpenMessages(event.GuildId, {
29
+ content: item,
30
+ msg_id: event.MessageId,
31
+ msg_type: 0,
32
+ msg_seq: client.getMessageSeq(event.MessageId)
33
+ })
34
+ )
35
+ )
36
+ }
37
+ const images = val.filter(item => item.type == 'Image').map(item => item.value)
38
+ if (images) {
39
+ return Promise.all(
40
+ images.map(async msg => {
41
+ const file_info = await client
42
+ .postRichMediaByGroup(event.GuildId, {
43
+ file_type: 1,
44
+ file_data: msg.toString('base64')
45
+ })
46
+ .then(res => res?.file_info)
47
+ if (!file_info) return Promise.resolve(null)
48
+ return client.groupOpenMessages(event.GuildId, {
49
+ content: '',
50
+ media: {
51
+ file_info
52
+ },
53
+ msg_id: event.MessageId,
54
+ msg_type: 7,
55
+ msg_seq: client.getMessageSeq(event.MessageId)
56
+ })
57
+ })
58
+ )
59
+ }
60
+ return []
61
+ }
57
62
  const C2C_MESSAGE_CREATE = (client, event, val) => {
58
- const content = val
59
- .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
60
- .map(item => {
61
- if (item.type == 'Text') {
62
- return item.value;
63
- }
64
- return '';
63
+ const content = val
64
+ .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
65
+ .map(item => {
66
+ if (item.type == 'Text') {
67
+ return item.value
68
+ }
69
+ return ''
65
70
  })
66
- .join('');
67
- if (content) {
68
- return Promise.all([content].map(item => client.usersOpenMessages(event.OpenId, {
69
- content: item,
70
- msg_id: event.MessageId,
71
- msg_type: 0,
72
- msg_seq: client.getMessageSeq(event.MessageId)
73
- })));
74
- }
75
- const images = val.filter(item => item.type == 'Image').map(item => item.value);
76
- if (images) {
77
- return Promise.all(images.map(async (msg) => {
78
- const file_info = await client
79
- .postRichMediaByUsers(event.OpenId, {
80
- file_type: 1,
81
- file_data: msg.toString('base64')
82
- })
83
- .then(res => res?.file_info);
84
- if (!file_info)
85
- return Promise.resolve(null);
86
- return client.usersOpenMessages(event.OpenId, {
87
- content: '',
88
- media: {
89
- file_info
90
- },
91
- msg_id: event.MessageId,
92
- msg_type: 7,
93
- msg_seq: client.getMessageSeq(event.MessageId)
94
- });
95
- }));
96
- }
97
- return [];
98
- };
71
+ .join('')
72
+ if (content) {
73
+ return Promise.all(
74
+ [content].map(item =>
75
+ client.usersOpenMessages(event.OpenId, {
76
+ content: item,
77
+ msg_id: event.MessageId,
78
+ msg_type: 0,
79
+ msg_seq: client.getMessageSeq(event.MessageId)
80
+ })
81
+ )
82
+ )
83
+ }
84
+ const images = val.filter(item => item.type == 'Image').map(item => item.value)
85
+ if (images) {
86
+ return Promise.all(
87
+ images.map(async msg => {
88
+ const file_info = await client
89
+ .postRichMediaByUsers(event.OpenId, {
90
+ file_type: 1,
91
+ file_data: msg.toString('base64')
92
+ })
93
+ .then(res => res?.file_info)
94
+ if (!file_info) return Promise.resolve(null)
95
+ return client.usersOpenMessages(event.OpenId, {
96
+ content: '',
97
+ media: {
98
+ file_info
99
+ },
100
+ msg_id: event.MessageId,
101
+ msg_type: 7,
102
+ msg_seq: client.getMessageSeq(event.MessageId)
103
+ })
104
+ })
105
+ )
106
+ }
107
+ return []
108
+ }
99
109
  /**
100
110
  * 频道私聊
101
111
  * @param client
@@ -104,72 +114,87 @@ const C2C_MESSAGE_CREATE = (client, event, val) => {
104
114
  * @returns
105
115
  */
106
116
  const DIRECT_MESSAGE_CREATE = (client, event, val) => {
107
- const content = val
108
- .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
109
- .map(item => {
110
- if (item.type == 'Text') {
111
- return item.value;
112
- }
113
- return '';
117
+ const content = val
118
+ .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
119
+ .map(item => {
120
+ if (item.type == 'Text') {
121
+ return item.value
122
+ }
123
+ return ''
114
124
  })
115
- .join('');
116
- if (content) {
117
- return Promise.all([content].map(item => client.dmsMessage(event.OpenId, {
118
- content: item,
119
- msg_id: event.MessageId
120
- })));
121
- }
122
- const images = val.filter(item => item.type == 'Image').map(item => item.value);
123
- if (images) {
124
- return Promise.all(images.map(item => client.postDirectImage(event.OpenId, {
125
- msg_id: event.MessageId,
126
- image: item
127
- })));
128
- }
129
- return [];
130
- };
125
+ .join('')
126
+ if (content) {
127
+ return Promise.all(
128
+ [content].map(item =>
129
+ client.dmsMessage(event.OpenId, {
130
+ content: item,
131
+ msg_id: event.MessageId
132
+ })
133
+ )
134
+ )
135
+ }
136
+ const images = val.filter(item => item.type == 'Image').map(item => item.value)
137
+ if (images) {
138
+ return Promise.all(
139
+ images.map(item =>
140
+ client.postDirectImage(event.OpenId, {
141
+ msg_id: event.MessageId,
142
+ image: item
143
+ })
144
+ )
145
+ )
146
+ }
147
+ return []
148
+ }
131
149
  const AT_MESSAGE_CREATE = (client, event, val) => {
132
- const content = val
133
- .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
134
- .map(item => {
135
- if (item.type == 'Link') {
136
- return `[${item.options?.title ?? item.value}](${item.value})`;
150
+ const content = val
151
+ .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
152
+ .map(item => {
153
+ if (item.type == 'Link') {
154
+ return `[${item.options?.title ?? item.value}](${item.value})`
155
+ } else if (item.type == 'Mention') {
156
+ if (
157
+ item.value == 'everyone' ||
158
+ item.value == 'all' ||
159
+ item.value == '' ||
160
+ typeof item.value != 'string'
161
+ ) {
162
+ return `@everyone`
137
163
  }
138
- else if (item.type == 'Mention') {
139
- if (item.value == 'everyone' ||
140
- item.value == 'all' ||
141
- item.value == '' ||
142
- typeof item.value != 'string') {
143
- return `@everyone`;
144
- }
145
- if (item.options?.belong == 'user') {
146
- return `<@!${item.value}>`;
147
- }
148
- else if (item.options?.belong == 'channel') {
149
- return `<#${item.value}>`;
150
- }
151
- return '';
152
- }
153
- else if (item.type == 'Text') {
154
- return item.value;
164
+ if (item.options?.belong == 'user') {
165
+ return `<@!${item.value}>`
166
+ } else if (item.options?.belong == 'channel') {
167
+ return `<#${item.value}>`
155
168
  }
169
+ return ''
170
+ } else if (item.type == 'Text') {
171
+ return item.value
172
+ }
156
173
  })
157
- .join('');
158
- if (content) {
159
- return Promise.all([content].map(item => client.channelsMessagesPost(event.ChannelId, {
160
- content: item,
161
- msg_id: event.MessageId
162
- })));
163
- }
164
- const images = val.filter(item => item.type == 'Image').map(item => item.value);
165
- if (images) {
166
- return Promise.all(images.map(item => client.postImage(event.ChannelId, {
167
- msg_id: event.MessageId,
168
- image: item
169
- })));
170
- }
171
- return [];
172
- };
174
+ .join('')
175
+ if (content) {
176
+ return Promise.all(
177
+ [content].map(item =>
178
+ client.channelsMessagesPost(event.ChannelId, {
179
+ content: item,
180
+ msg_id: event.MessageId
181
+ })
182
+ )
183
+ )
184
+ }
185
+ const images = val.filter(item => item.type == 'Image').map(item => item.value)
186
+ if (images) {
187
+ return Promise.all(
188
+ images.map(item =>
189
+ client.postImage(event.ChannelId, {
190
+ msg_id: event.MessageId,
191
+ image: item
192
+ })
193
+ )
194
+ )
195
+ }
196
+ return []
197
+ }
173
198
  /**
174
199
  *
175
200
  * @param event
@@ -177,46 +202,59 @@ const AT_MESSAGE_CREATE = (client, event, val) => {
177
202
  * @returns
178
203
  */
179
204
  const MESSAGE_CREATE = (client, event, val) => {
180
- const content = val
181
- .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
182
- .map(item => {
183
- if (item.type == 'Link') {
184
- return `[${item.options?.title ?? item.value}](${item.value})`;
185
- }
186
- else if (item.type == 'Mention') {
187
- if (item.value == 'everyone' ||
188
- item.value == 'all' ||
189
- item.value == '' ||
190
- typeof item.value != 'string') {
191
- return `@everyone`;
192
- }
193
- if (item.options?.belong == 'user') {
194
- return `<@!${item.value}>`;
195
- }
196
- else if (item.options?.belong == 'channel') {
197
- return `<#${item.value}>`;
198
- }
199
- return '';
205
+ const content = val
206
+ .filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
207
+ .map(item => {
208
+ if (item.type == 'Link') {
209
+ return `[${item.options?.title ?? item.value}](${item.value})`
210
+ } else if (item.type == 'Mention') {
211
+ if (
212
+ item.value == 'everyone' ||
213
+ item.value == 'all' ||
214
+ item.value == '' ||
215
+ typeof item.value != 'string'
216
+ ) {
217
+ return `@everyone`
200
218
  }
201
- else if (item.type == 'Text') {
202
- return item.value;
219
+ if (item.options?.belong == 'user') {
220
+ return `<@!${item.value}>`
221
+ } else if (item.options?.belong == 'channel') {
222
+ return `<#${item.value}>`
203
223
  }
224
+ return ''
225
+ } else if (item.type == 'Text') {
226
+ return item.value
227
+ }
204
228
  })
205
- .join('');
206
- if (content) {
207
- return Promise.all([content].map(item => client.channelsMessagesPost(event.ChannelId, {
208
- content: item,
209
- msg_id: event.MessageId
210
- })));
211
- }
212
- const images = val.filter(item => item.type == 'Image').map(item => item.value);
213
- if (images) {
214
- return Promise.all(images.map(item => client.postImage(event.ChannelId, {
215
- msg_id: event.MessageId,
216
- image: item
217
- })));
218
- }
219
- return [];
220
- };
229
+ .join('')
230
+ if (content) {
231
+ return Promise.all(
232
+ [content].map(item =>
233
+ client.channelsMessagesPost(event.ChannelId, {
234
+ content: item,
235
+ msg_id: event.MessageId
236
+ })
237
+ )
238
+ )
239
+ }
240
+ const images = val.filter(item => item.type == 'Image').map(item => item.value)
241
+ if (images) {
242
+ return Promise.all(
243
+ images.map(item =>
244
+ client.postImage(event.ChannelId, {
245
+ msg_id: event.MessageId,
246
+ image: item
247
+ })
248
+ )
249
+ )
250
+ }
251
+ return []
252
+ }
221
253
 
222
- export { AT_MESSAGE_CREATE, C2C_MESSAGE_CREATE, DIRECT_MESSAGE_CREATE, GROUP_AT_MESSAGE_CREATE, MESSAGE_CREATE };
254
+ export {
255
+ AT_MESSAGE_CREATE,
256
+ C2C_MESSAGE_CREATE,
257
+ DIRECT_MESSAGE_CREATE,
258
+ GROUP_AT_MESSAGE_CREATE,
259
+ MESSAGE_CREATE
260
+ }
@@ -0,0 +1,73 @@
1
+ type MessageType = 0 | 1 | 2 | 3 | 4 | 7
2
+ type FileType = 1 | 2 | 3 | 4
3
+ interface ButtonType {
4
+ id: string
5
+ render_data: {
6
+ label: string
7
+ visited_label: string
8
+ style: number
9
+ }
10
+ action: {
11
+ type: number
12
+ permission: {
13
+ type: number
14
+ }
15
+ reply?: boolean
16
+ enter?: boolean
17
+ unsupport_tips: string
18
+ data: string
19
+ }
20
+ }
21
+ interface KeyboardType {
22
+ id?: string
23
+ content?: {
24
+ rows: {
25
+ buttons: ButtonType[]
26
+ }[]
27
+ }
28
+ }
29
+ interface MarkdownType {
30
+ /** markdown 模版id,申请模版后获得 */
31
+ custom_template_id: string
32
+ /** 原生 markdown 文本内容(内邀使用) */
33
+ content?: string
34
+ /** 模版内变量与填充值的kv映射 */
35
+ params?: Array<{
36
+ key: string
37
+ values: string[]
38
+ }>
39
+ }
40
+ interface ApiRequestData {
41
+ content?: string
42
+ msg_type: MessageType
43
+ markdown?: MarkdownType
44
+ keyboard?: KeyboardType
45
+ media?: {
46
+ file_info: string
47
+ }
48
+ ark?: any
49
+ image?: any
50
+ message_reference?: any
51
+ event_id?: any
52
+ msg_id?: string
53
+ msg_seq?: number
54
+ }
55
+ interface Options {
56
+ secret: string
57
+ app_id: string
58
+ token: string
59
+ sandbox?: boolean
60
+ route?: string
61
+ port?: string
62
+ ws?: string
63
+ }
64
+
65
+ export type {
66
+ ApiRequestData,
67
+ ButtonType,
68
+ FileType,
69
+ KeyboardType,
70
+ MarkdownType,
71
+ MessageType,
72
+ Options
73
+ }
package/lib/webhook.js CHANGED
@@ -1,53 +1,51 @@
1
- import { ed25519 } from '@noble/curves/ed25519';
1
+ import { ed25519 } from '@noble/curves/ed25519'
2
2
 
3
3
  class WebhookAPI {
4
- config;
5
- constructor(config) {
6
- this.config = config;
7
- }
8
- /**
9
- * 验证签名
10
- * @param ts
11
- * @param body
12
- * @param sign
13
- * @returns
14
- */
15
- validSign(ts, body, sign) {
16
- const { publicKey } = this.getKey();
17
- const sig = Buffer.isBuffer(sign) ? sign : Buffer.from(sign, 'hex');
18
- const httpBody = Buffer.from(body);
19
- const msg = Buffer.from(ts + httpBody);
20
- return ed25519.verify(sig, msg, publicKey);
21
- }
22
- /**
23
- * 生成签名
24
- * @param eventTs
25
- * @param plainToken
26
- * @returns
27
- */
28
- getSign(eventTs, plainToken) {
29
- const { privateKey } = this.getKey();
30
- const msg = Buffer.from(eventTs + plainToken);
31
- const signature = Buffer.from(ed25519.sign(msg, privateKey)).toString('hex');
32
- return signature;
33
- }
34
- /**
35
- * 获取 key
36
- * @returns
37
- */
38
- getKey() {
39
- let seed = this.config.secret;
40
- if (!seed)
41
- throw new Error("secret not set, can't calc ed25519 key");
42
- while (seed.length < 32)
43
- seed = seed.repeat(2); // Ed25519 的种子大小是 32 字节
44
- seed = seed.slice(0, 32); // 修剪到 32 字节
45
- const privateKey = Buffer.from(seed);
46
- return {
47
- privateKey,
48
- publicKey: ed25519.getPublicKey(privateKey)
49
- };
4
+ config
5
+ constructor(config) {
6
+ this.config = config
7
+ }
8
+ /**
9
+ * 验证签名
10
+ * @param ts
11
+ * @param body
12
+ * @param sign
13
+ * @returns
14
+ */
15
+ validSign(ts, body, sign) {
16
+ const { publicKey } = this.getKey()
17
+ const sig = Buffer.isBuffer(sign) ? sign : Buffer.from(sign, 'hex')
18
+ const httpBody = Buffer.from(body)
19
+ const msg = Buffer.from(ts + httpBody)
20
+ return ed25519.verify(sig, msg, publicKey)
21
+ }
22
+ /**
23
+ * 生成签名
24
+ * @param eventTs
25
+ * @param plainToken
26
+ * @returns
27
+ */
28
+ getSign(eventTs, plainToken) {
29
+ const { privateKey } = this.getKey()
30
+ const msg = Buffer.from(eventTs + plainToken)
31
+ const signature = Buffer.from(ed25519.sign(msg, privateKey)).toString('hex')
32
+ return signature
33
+ }
34
+ /**
35
+ * 获取 key
36
+ * @returns
37
+ */
38
+ getKey() {
39
+ let seed = this.config.secret
40
+ if (!seed) throw new Error("secret not set, can't calc ed25519 key")
41
+ while (seed.length < 32) seed = seed.repeat(2) // Ed25519 的种子大小是 32 字节
42
+ seed = seed.slice(0, 32) // 修剪到 32 字节
43
+ const privateKey = Buffer.from(seed)
44
+ return {
45
+ privateKey,
46
+ publicKey: ed25519.getPublicKey(privateKey)
50
47
  }
48
+ }
51
49
  }
52
50
 
53
- export { WebhookAPI };
51
+ export { WebhookAPI }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/qq-bot",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "qq-bot",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
@@ -37,7 +37,29 @@
37
37
  "import": "./lib/index.js",
38
38
  "types": "./lib/index.d.ts"
39
39
  },
40
- "./package": "./package.json"
40
+ "./package": "./package.json",
41
+ "./desktop": "./lib/desktop.js"
42
+ },
43
+ "alemonjs": {
44
+ "desktop": {
45
+ "platform": [
46
+ {
47
+ "name": "qq-bot"
48
+ }
49
+ ],
50
+ "commond": [
51
+ {
52
+ "name": "qq-bot",
53
+ "commond": "open.qq-bot"
54
+ }
55
+ ],
56
+ "sidebars": [
57
+ {
58
+ "name": "qq-bot",
59
+ "commond": "open.qq-bot"
60
+ }
61
+ ]
62
+ }
41
63
  },
42
64
  "keywords": [
43
65
  "alemonjs"