@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.
Files changed (53) hide show
  1. package/README.md +19 -8
  2. package/dist/assets/index.css +1 -1
  3. package/dist/assets/index.js +1 -1
  4. package/lib/api.d.ts +971 -843
  5. package/lib/api.js +1172 -1156
  6. package/lib/client.d.ts +22 -22
  7. package/lib/client.js +201 -217
  8. package/lib/config.js +2 -2
  9. package/lib/desktop.js +4 -2
  10. package/lib/from.js +27 -34
  11. package/lib/index.d.ts +3 -3
  12. package/lib/index.group.js +238 -0
  13. package/lib/index.guild.js +338 -0
  14. package/lib/index.js +43 -2
  15. package/lib/message/AT_MESSAGE_CREATE.d.ts +35 -35
  16. package/lib/message/C2C_MESSAGE_CREATE.d.ts +9 -9
  17. package/lib/message/CHANNEL_CREATE.d.ts +15 -15
  18. package/lib/message/CHANNEL_DELETE.d.ts +15 -15
  19. package/lib/message/CHANNEL_UPDATE.d.ts +15 -15
  20. package/lib/message/DIRECT_MESSAGE_CREATE.d.ts +29 -29
  21. package/lib/message/DIRECT_MESSAGE_DELETE.d.ts +17 -17
  22. package/lib/message/ERROR.d.ts +2 -2
  23. package/lib/message/GROUP_AT_MESSAGE_CREATE.d.ts +10 -10
  24. package/lib/message/GUILD_CREATE.d.ts +15 -15
  25. package/lib/message/GUILD_DELETE.d.ts +15 -15
  26. package/lib/message/GUILD_MEMBER_ADD.d.ts +14 -14
  27. package/lib/message/GUILD_MEMBER_REMOVE.d.ts +14 -14
  28. package/lib/message/GUILD_MEMBER_UPDATE.d.ts +14 -14
  29. package/lib/message/GUILD_UPDATE.d.ts +15 -15
  30. package/lib/message/INTERACTION_CREATE.d.ts +2 -2
  31. package/lib/message/MESSAGE_CREATE.d.ts +2 -2
  32. package/lib/message/MESSAGE_DELETE.d.ts +2 -2
  33. package/lib/message/MESSAGE_REACTION_ADD.d.ts +13 -13
  34. package/lib/message/MESSAGE_REACTION_REMOVE.d.ts +13 -13
  35. package/lib/message/PUBLIC_MESSAGE_DELETE.d.ts +15 -15
  36. package/lib/message/READY.d.ts +6 -6
  37. package/lib/message.d.ts +46 -46
  38. package/lib/sdk/api.d.ts +847 -0
  39. package/lib/sdk/api.js +1183 -0
  40. package/lib/sdk/client.js +228 -0
  41. package/lib/sdk/config.js +3 -0
  42. package/lib/sdk/counter.js +19 -0
  43. package/lib/sdk/from.js +44 -0
  44. package/lib/sdk/intents.js +102 -0
  45. package/lib/sdk/typing.d.ts +56 -0
  46. package/lib/sdk/webhook.secret.js +53 -0
  47. package/lib/sdk/websoket.group.js +221 -0
  48. package/lib/sdk/websoket.guild.js +203 -0
  49. package/lib/send/index.js +87 -21
  50. package/lib/typing.d.ts +62 -54
  51. package/lib/utils.js +14 -0
  52. package/lib/webhook.js +46 -48
  53. 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
- 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
- };
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
- id?: string;
23
- content?: {
24
- rows: {
25
- buttons: ButtonType[];
26
- }[];
27
- };
22
+ id?: string
23
+ content?: {
24
+ rows: {
25
+ buttons: ButtonType[]
26
+ }[]
27
+ }
28
28
  }
29
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
- }>;
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
- 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;
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
- secret: string;
57
- app_id: string;
58
- token: string;
59
- sandbox?: boolean;
60
- route?: string;
61
- port?: string;
62
- ws?: string;
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 { ApiRequestData, ButtonType, FileType, KeyboardType, MarkdownType, MessageType, Options };
65
+ export type {
66
+ ApiRequestData,
67
+ ButtonType,
68
+ FileType,
69
+ KeyboardType,
70
+ MarkdownType,
71
+ MessageType,
72
+ Options
73
+ }
package/lib/utils.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ *
3
+ * @param str
4
+ * @returns
5
+ */
6
+ const isGuild = (str) => {
7
+ // guild ID 纯数字,例如:11586990140073229091
8
+ // 转换失败,是群id。return false
9
+ if (isNaN(Number(str.substring(0, 6))))
10
+ return false;
11
+ return true;
12
+ };
13
+
14
+ export { isGuild };
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.11",
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
  ".": {