@im-more/dsh-kook 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/cordis.patch.yml +12 -0
- package/lib/index.js +2380 -0
- package/lib/index.js.map +1 -0
- package/lib/types/bot.d.ts +53 -0
- package/lib/types/bot.d.ts.map +1 -0
- package/lib/types/bot.js +138 -0
- package/lib/types/bot.js.map +1 -0
- package/lib/types/config.d.ts +46 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +52 -0
- package/lib/types/config.js.map +1 -0
- package/lib/types/decode.d.ts +88 -0
- package/lib/types/decode.d.ts.map +1 -0
- package/lib/types/decode.js +564 -0
- package/lib/types/decode.js.map +1 -0
- package/lib/types/errors.d.ts +46 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/errors.js +159 -0
- package/lib/types/errors.js.map +1 -0
- package/lib/types/identity.d.ts +17 -0
- package/lib/types/identity.d.ts.map +1 -0
- package/lib/types/identity.js +24 -0
- package/lib/types/identity.js.map +1 -0
- package/lib/types/index.d.ts +15 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +15 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/kmarkdown.d.ts +76 -0
- package/lib/types/kmarkdown.d.ts.map +1 -0
- package/lib/types/kmarkdown.js +201 -0
- package/lib/types/kmarkdown.js.map +1 -0
- package/lib/types/modes/kmarkdown.d.ts +17 -0
- package/lib/types/modes/kmarkdown.d.ts.map +1 -0
- package/lib/types/modes/kmarkdown.js +166 -0
- package/lib/types/modes/kmarkdown.js.map +1 -0
- package/lib/types/modes/shared.d.ts +192 -0
- package/lib/types/modes/shared.d.ts.map +1 -0
- package/lib/types/modes/shared.js +371 -0
- package/lib/types/modes/shared.js.map +1 -0
- package/lib/types/request.d.ts +53 -0
- package/lib/types/request.d.ts.map +1 -0
- package/lib/types/request.js +147 -0
- package/lib/types/request.js.map +1 -0
- package/lib/types/send.d.ts +57 -0
- package/lib/types/send.d.ts.map +1 -0
- package/lib/types/send.js +141 -0
- package/lib/types/send.js.map +1 -0
- package/lib/types/types.d.ts +807 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js +168 -0
- package/lib/types/types.js.map +1 -0
- package/lib/types/webhook.d.ts +35 -0
- package/lib/types/webhook.d.ts.map +1 -0
- package/lib/types/webhook.js +132 -0
- package/lib/types/webhook.js.map +1 -0
- package/lib/types/ws.d.ts +54 -0
- package/lib/types/ws.d.ts.map +1 -0
- package/lib/types/ws.js +358 -0
- package/lib/types/ws.js.map +1 -0
- package/package.json +61 -3
- package/src/bot.ts +217 -0
- package/src/config.ts +84 -0
- package/src/decode.ts +660 -0
- package/src/errors.ts +188 -0
- package/src/identity.ts +32 -0
- package/src/index.ts +80 -0
- package/src/kmarkdown.ts +246 -0
- package/src/modes/kmarkdown.ts +204 -0
- package/src/modes/shared.ts +498 -0
- package/src/request.ts +196 -0
- package/src/send.ts +216 -0
- package/src/types.ts +764 -0
- package/src/webhook.ts +170 -0
- package/src/ws.ts +431 -0
- package/README.md +0 -3
package/src/config.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import z from '@deepseek-ai/schemastery'
|
|
2
|
+
|
|
3
|
+
/** How the adapter receives KOOK events: the Gateway WebSocket (outbound) or a Webhook (inbound HTTP). */
|
|
4
|
+
export type KookProtocol = 'ws' | 'http'
|
|
5
|
+
|
|
6
|
+
/** One KOOK bot. */
|
|
7
|
+
export interface Config {
|
|
8
|
+
/** Bot token (`Authorization: Bot <token>`). */
|
|
9
|
+
token: string
|
|
10
|
+
/** Bot user id: `bot.id = kook:<selfId>`, checked against `/user/me` on connect. */
|
|
11
|
+
selfId: string
|
|
12
|
+
protocol: KookProtocol
|
|
13
|
+
/** Inbound route of `protocol: 'http'`: absolute, no trailing slash. */
|
|
14
|
+
path: string
|
|
15
|
+
/** Webhook source check (`verify_token`); required by `protocol: 'http'`. */
|
|
16
|
+
verifyToken: string
|
|
17
|
+
/** API root; `/gateway/index`, `/message/create`, `/asset/create` and the rest hang off it. */
|
|
18
|
+
apiBaseUrl: string
|
|
19
|
+
ws: {
|
|
20
|
+
/** Fast-retry budget of the Gateway reconnect loop; it never gives up. */
|
|
21
|
+
retryTimes: number
|
|
22
|
+
/** Delay between dials while the fast-retry budget lasts. */
|
|
23
|
+
retryInterval: number
|
|
24
|
+
/** Delay between dials once the fast-retry budget is spent. */
|
|
25
|
+
retryLazy: number
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Validated KOOK adapter configuration, also exported as `KookConfig`. */
|
|
30
|
+
export type KookConfig = Config
|
|
31
|
+
|
|
32
|
+
/** Validated KOOK adapter configuration. */
|
|
33
|
+
export const Config: z<Config> = z.object({
|
|
34
|
+
token: z.string().role('secret').required(),
|
|
35
|
+
selfId: z.string().pattern(/^\d+$/).required(),
|
|
36
|
+
protocol: z.union(['ws', 'http']).required(),
|
|
37
|
+
path: z.string().default('/kook'),
|
|
38
|
+
verifyToken: z.string().role('secret').default(''),
|
|
39
|
+
apiBaseUrl: z.string().role('url').default('https://www.kookapp.cn/api/v3'),
|
|
40
|
+
ws: z
|
|
41
|
+
.object({
|
|
42
|
+
retryTimes: z.natural().default(6),
|
|
43
|
+
retryInterval: z.natural().role('ms').default(5_000),
|
|
44
|
+
retryLazy: z.natural().role('ms').default(60_000),
|
|
45
|
+
})
|
|
46
|
+
.default({}),
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The configuration the selected protocol cannot work from.
|
|
51
|
+
*
|
|
52
|
+
* The schema already refuses a missing token or a non-numeric `selfId`; what it cannot express is which credential a
|
|
53
|
+
* protocol needs, so that check runs when the plugin loads and names the corrective action.
|
|
54
|
+
*
|
|
55
|
+
* @param config - the validated configuration.
|
|
56
|
+
* @returns the configuration error, or undefined when the selection is complete.
|
|
57
|
+
*/
|
|
58
|
+
export function configError(config: Config): Error | undefined {
|
|
59
|
+
let url: URL
|
|
60
|
+
try {
|
|
61
|
+
url = new URL(config.apiBaseUrl)
|
|
62
|
+
} catch {
|
|
63
|
+
return new Error('kook: apiBaseUrl must be an absolute http(s) URL')
|
|
64
|
+
}
|
|
65
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
66
|
+
return new Error('kook: apiBaseUrl must be an absolute http(s) URL')
|
|
67
|
+
}
|
|
68
|
+
if (config.protocol === 'http' && config.verifyToken === '') {
|
|
69
|
+
return new Error(
|
|
70
|
+
'kook: protocol "http" needs verifyToken (the verify_token KOOK issues for the webhook)',
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
return undefined
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Normalize an inbound route path: absolute, no trailing slash.
|
|
78
|
+
* @param path - the configured `path`.
|
|
79
|
+
* @returns the pathname to register.
|
|
80
|
+
*/
|
|
81
|
+
export function routePath(path: string): string {
|
|
82
|
+
const withSlash = path.startsWith('/') ? path : `/${path}`
|
|
83
|
+
return withSlash.length > 1 ? withSlash.replace(/\/+$/, '') : withSlash
|
|
84
|
+
}
|