@alemonjs/qq-bot 0.0.11 → 0.0.13
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 +19 -8
- package/dist/assets/index.css +1 -1
- package/dist/assets/index.js +1 -1
- package/lib/api.d.ts +971 -843
- package/lib/api.js +1172 -1156
- package/lib/client.d.ts +22 -22
- package/lib/client.js +201 -217
- package/lib/config.js +2 -2
- package/lib/desktop.js +4 -2
- package/lib/from.js +27 -34
- package/lib/index.d.ts +3 -3
- package/lib/index.group.js +238 -0
- package/lib/index.guild.js +338 -0
- package/lib/index.js +43 -2
- package/lib/message/AT_MESSAGE_CREATE.d.ts +35 -35
- package/lib/message/C2C_MESSAGE_CREATE.d.ts +9 -9
- package/lib/message/CHANNEL_CREATE.d.ts +15 -15
- package/lib/message/CHANNEL_DELETE.d.ts +15 -15
- package/lib/message/CHANNEL_UPDATE.d.ts +15 -15
- package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +29 -29
- package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +17 -17
- package/lib/message/ERROR.d.ts +2 -2
- package/lib/message/GROUP_AT_MESSAGE_CREATE.d.ts +10 -10
- package/lib/message/GUILD_CREATE.d.ts +15 -15
- package/lib/message/GUILD_DELETE.d.ts +15 -15
- package/lib/message/GUILD_MEMBER_ADD.d.ts +14 -14
- package/lib/message/GUILD_MEMBER_REMOVE.d.ts +14 -14
- package/lib/message/GUILD_MEMBER_UPDATE.d.ts +14 -14
- package/lib/message/GUILD_UPDATE.d.ts +15 -15
- package/lib/message/INTERACTION_CREATE.d.ts +2 -2
- package/lib/message/MESSAGE_CREATE.d.ts +2 -2
- package/lib/message/MESSAGE_DELETE.d.ts +2 -2
- package/lib/message/MESSAGE_REACTION_ADD.d.ts +13 -13
- package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +13 -13
- package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +15 -15
- package/lib/message/READY.d.ts +6 -6
- package/lib/message.d.ts +46 -46
- package/lib/sdk/api.d.ts +847 -0
- package/lib/sdk/api.js +1183 -0
- package/lib/sdk/client.js +228 -0
- package/lib/sdk/config.js +3 -0
- package/lib/sdk/counter.js +19 -0
- package/lib/sdk/from.js +44 -0
- package/lib/sdk/intents.js +102 -0
- package/lib/sdk/typing.d.ts +56 -0
- package/lib/sdk/webhook.secret.js +53 -0
- package/lib/sdk/websoket.group.js +221 -0
- package/lib/sdk/websoket.guild.js +203 -0
- package/lib/send/index.js +87 -21
- package/lib/typing.d.ts +62 -54
- package/lib/utils.js +14 -0
- package/lib/webhook.js +46 -48
- package/package.json +1 -7
package/lib/typing.d.ts
CHANGED
|
@@ -1,65 +1,73 @@
|
|
|
1
|
-
type MessageType = 0 | 1 | 2 | 3 | 4 | 7
|
|
2
|
-
type FileType = 1 | 2 | 3 | 4
|
|
1
|
+
type MessageType = 0 | 1 | 2 | 3 | 4 | 7
|
|
2
|
+
type FileType = 1 | 2 | 3 | 4
|
|
3
3
|
interface ButtonType {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
20
|
}
|
|
21
21
|
interface KeyboardType {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
id?: string
|
|
23
|
+
content?: {
|
|
24
|
+
rows: {
|
|
25
|
+
buttons: ButtonType[]
|
|
26
|
+
}[]
|
|
27
|
+
}
|
|
28
28
|
}
|
|
29
29
|
interface MarkdownType {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
39
|
}
|
|
40
40
|
interface ApiRequestData {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
54
|
}
|
|
55
55
|
interface Options {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
secret: string
|
|
57
|
+
app_id: string
|
|
58
|
+
token: string
|
|
59
|
+
sandbox?: boolean
|
|
60
|
+
route?: string
|
|
61
|
+
port?: string
|
|
62
|
+
ws?: string
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
export type {
|
|
65
|
+
export type {
|
|
66
|
+
ApiRequestData,
|
|
67
|
+
ButtonType,
|
|
68
|
+
FileType,
|
|
69
|
+
KeyboardType,
|
|
70
|
+
MarkdownType,
|
|
71
|
+
MessageType,
|
|
72
|
+
Options
|
|
73
|
+
}
|
package/lib/utils.js
ADDED
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"description": "阿柠檬qqbot平台连接",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,12 +25,6 @@
|
|
|
25
25
|
"uuid": "^11.0.3",
|
|
26
26
|
"@noble/curves": "^1.7.0"
|
|
27
27
|
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@rollup/plugin-typescript": "^11.1.6",
|
|
30
|
-
"lvyjs": "^0.2.13",
|
|
31
|
-
"rollup": "^4.18.1",
|
|
32
|
-
"rollup-plugin-dts": "^6.1.1"
|
|
33
|
-
},
|
|
34
28
|
"types": "lib",
|
|
35
29
|
"exports": {
|
|
36
30
|
".": {
|