@jsbot-tellus/core 2.0.3 → 2.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/README.md +13 -17
- package/dist/app.js +12 -40
- package/dist/app.js.map +1 -1
- package/dist/core/config/schema.d.ts +0 -2
- package/dist/core/config/schema.d.ts.map +1 -1
- package/dist/core/config/schema.js +0 -1
- package/dist/core/config/schema.js.map +1 -1
- package/dist/core/dispatch/command.d.ts +24 -2
- package/dist/core/dispatch/command.d.ts.map +1 -1
- package/dist/core/dispatch/command.js +297 -60
- package/dist/core/dispatch/command.js.map +1 -1
- package/dist/core/dispatch/router.d.ts +17 -3
- package/dist/core/dispatch/router.d.ts.map +1 -1
- package/dist/core/dispatch/router.js +38 -2
- package/dist/core/dispatch/router.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/plugin/command-params.d.ts +15 -0
- package/dist/core/plugin/command-params.d.ts.map +1 -0
- package/dist/core/plugin/command-params.js +427 -0
- package/dist/core/plugin/command-params.js.map +1 -0
- package/dist/core/plugin/context.d.ts.map +1 -1
- package/dist/core/plugin/context.js +27 -0
- package/dist/core/plugin/context.js.map +1 -1
- package/dist/core/plugin/install-dir.d.ts +6 -9
- package/dist/core/plugin/install-dir.d.ts.map +1 -1
- package/dist/core/plugin/install-dir.js +99 -79
- package/dist/core/plugin/install-dir.js.map +1 -1
- package/dist/core/plugin/install-validate.d.ts +2 -1
- package/dist/core/plugin/install-validate.d.ts.map +1 -1
- package/dist/core/plugin/install-validate.js +25 -17
- package/dist/core/plugin/install-validate.js.map +1 -1
- package/dist/core/plugin/installer.d.ts +3 -3
- package/dist/core/plugin/installer.d.ts.map +1 -1
- package/dist/core/plugin/installer.js +143 -140
- package/dist/core/plugin/installer.js.map +1 -1
- package/dist/core/plugin/loader.d.ts +1 -0
- package/dist/core/plugin/loader.d.ts.map +1 -1
- package/dist/core/plugin/loader.js +24 -2
- package/dist/core/plugin/loader.js.map +1 -1
- package/dist/core/plugin/types.d.ts +11 -3
- package/dist/core/plugin/types.d.ts.map +1 -1
- package/dist/core/plugin/types.js.map +1 -1
- package/dist/plugins/admin/index.d.ts.map +1 -1
- package/dist/plugins/admin/index.js +119 -86
- package/dist/plugins/admin/index.js.map +1 -1
- package/dist/plugins/core/index.d.ts.map +1 -1
- package/dist/plugins/core/index.js +4 -1
- package/dist/plugins/core/index.js.map +1 -1
- package/docs/architecture.md +22 -24
- package/docs/configuration.md +19 -23
- package/docs/feature-parity.md +4 -4
- package/docs/migration.md +13 -13
- package/docs/plugin-api.md +156 -26
- package/docs/plugin-development.md +390 -0
- package/docs/release.md +2 -2
- package/examples/plugins/hello/README.md +10 -5
- package/examples/plugins/hello/index.js +3 -6
- package/package.json +2 -1
- package/src/app.ts +16 -55
- package/src/core/config/schema.ts +0 -1
- package/src/core/dispatch/command.ts +474 -70
- package/src/core/dispatch/router.ts +77 -3
- package/src/core/index.ts +2 -0
- package/src/core/plugin/command-params.ts +595 -0
- package/src/core/plugin/context.ts +47 -2
- package/src/core/plugin/install-dir.ts +117 -111
- package/src/core/plugin/install-validate.ts +36 -34
- package/src/core/plugin/installer.ts +228 -184
- package/src/core/plugin/loader.ts +36 -2
- package/src/core/plugin/types.ts +23 -3
- package/src/plugins/admin/index.ts +302 -233
- package/src/plugins/core/index.ts +5 -1
- package/dist/core/plugin/installed.d.ts +0 -9
- package/dist/core/plugin/installed.d.ts.map +0 -1
- package/dist/core/plugin/installed.js +0 -113
- package/dist/core/plugin/installed.js.map +0 -1
- package/src/core/plugin/installed.ts +0 -165
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
EventNext,
|
|
3
|
+
OneBotMessageEvent,
|
|
3
4
|
SnowLumaEvent,
|
|
4
5
|
SnowLumaEventContextWithQuote,
|
|
5
6
|
} from '@snowluma/sdk'
|
|
6
7
|
import { isMessageEvent, isNoticeEvent, isRequestEvent } from '@snowluma/sdk'
|
|
7
8
|
import type { Logger } from '../logging/logger.js'
|
|
8
9
|
import type { MessageSender } from '../messaging/sender.js'
|
|
10
|
+
import { CommandParamsError } from '../plugin/command-params.js'
|
|
9
11
|
import type { PluginGate } from '../plugin/gating.js'
|
|
10
12
|
import type {
|
|
13
|
+
CommandGroupRegistrar,
|
|
11
14
|
CommandHandler,
|
|
12
15
|
CommandInfo,
|
|
13
16
|
EventType,
|
|
@@ -22,7 +25,11 @@ import type {
|
|
|
22
25
|
import type { RoleService } from '../security/roles.js'
|
|
23
26
|
import { PermissionRefuser } from '../security/refuse.js'
|
|
24
27
|
import type { Permission } from '../security/permission.js'
|
|
25
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
CommandRegistry,
|
|
30
|
+
type CommandGroupRegistration,
|
|
31
|
+
type CommandRegistration,
|
|
32
|
+
} from './command.js'
|
|
26
33
|
import {
|
|
27
34
|
createEventContext,
|
|
28
35
|
eventTypeOf,
|
|
@@ -48,6 +55,8 @@ export interface RouterDeps {
|
|
|
48
55
|
logger: Logger
|
|
49
56
|
}
|
|
50
57
|
|
|
58
|
+
type AnyCommandHandler = CommandHandler<OneBotMessageEvent, any[]>
|
|
59
|
+
|
|
51
60
|
export interface RegisterCommandOptions {
|
|
52
61
|
pluginId: string
|
|
53
62
|
name: string
|
|
@@ -55,7 +64,19 @@ export interface RegisterCommandOptions {
|
|
|
55
64
|
prefixes?: string[] | undefined
|
|
56
65
|
permission?: Permission | undefined
|
|
57
66
|
description?: string | undefined
|
|
58
|
-
|
|
67
|
+
params?: string | undefined
|
|
68
|
+
handler: AnyCommandHandler
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface RegisterCommandGroupOptions {
|
|
72
|
+
pluginId: string
|
|
73
|
+
name: string
|
|
74
|
+
aliases?: string[] | undefined
|
|
75
|
+
prefixes?: string[] | undefined
|
|
76
|
+
permission?: Permission | undefined
|
|
77
|
+
description?: string | undefined
|
|
78
|
+
params?: string | undefined
|
|
79
|
+
handler?: AnyCommandHandler | undefined
|
|
59
80
|
}
|
|
60
81
|
|
|
61
82
|
export interface RegisterNoticeOptions extends NoticeOptions {
|
|
@@ -153,6 +174,35 @@ export class Router {
|
|
|
153
174
|
this.sender,
|
|
154
175
|
found.match
|
|
155
176
|
)
|
|
177
|
+
let args: unknown[] = []
|
|
178
|
+
|
|
179
|
+
if (found.registration.paramsParser) {
|
|
180
|
+
try {
|
|
181
|
+
const parsed =
|
|
182
|
+
found.registration.paramsParser.parse(
|
|
183
|
+
found.match.rest
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
args = parsed.args
|
|
187
|
+
|
|
188
|
+
if (parsed.ignored.length > 0) {
|
|
189
|
+
this.logger.debug(
|
|
190
|
+
`ignored extra arguments for ${found.registration.name}`,
|
|
191
|
+
parsed.ignored.join(' ')
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
} catch (error) {
|
|
195
|
+
if (error instanceof CommandParamsError) {
|
|
196
|
+
await commandContext.send(
|
|
197
|
+
`${error.message}\n用法:${found.match.prefix}${found.registration.name} ${error.usage}`,
|
|
198
|
+
{ quote: false }
|
|
199
|
+
)
|
|
200
|
+
return
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
throw error
|
|
204
|
+
}
|
|
205
|
+
}
|
|
156
206
|
|
|
157
207
|
await this.safeRun(
|
|
158
208
|
found.registration.pluginId,
|
|
@@ -161,7 +211,8 @@ export class Router {
|
|
|
161
211
|
found.registration.handler(
|
|
162
212
|
event,
|
|
163
213
|
commandContext,
|
|
164
|
-
found.match
|
|
214
|
+
found.match,
|
|
215
|
+
...args
|
|
165
216
|
)
|
|
166
217
|
)
|
|
167
218
|
|
|
@@ -193,12 +244,35 @@ export class Router {
|
|
|
193
244
|
...(options.description !== undefined
|
|
194
245
|
? { description: options.description }
|
|
195
246
|
: {}),
|
|
247
|
+
...(options.params !== undefined ? { params: options.params } : {}),
|
|
196
248
|
handler: options.handler,
|
|
197
249
|
}
|
|
198
250
|
|
|
199
251
|
return this.commands.register(registration)
|
|
200
252
|
}
|
|
201
253
|
|
|
254
|
+
registerCommandGroup(
|
|
255
|
+
options: RegisterCommandGroupOptions,
|
|
256
|
+
setup: (group: CommandGroupRegistrar) => void
|
|
257
|
+
): () => void {
|
|
258
|
+
const registration: CommandGroupRegistration = {
|
|
259
|
+
pluginId: options.pluginId,
|
|
260
|
+
name: options.name,
|
|
261
|
+
aliases: options.aliases ?? [],
|
|
262
|
+
prefixes: options.prefixes ?? ['/'],
|
|
263
|
+
permission: options.permission ?? 'User',
|
|
264
|
+
...(options.description !== undefined
|
|
265
|
+
? { description: options.description }
|
|
266
|
+
: {}),
|
|
267
|
+
...(options.params !== undefined ? { params: options.params } : {}),
|
|
268
|
+
...(options.handler !== undefined
|
|
269
|
+
? { handler: options.handler }
|
|
270
|
+
: {}),
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return this.commands.group(registration, setup)
|
|
274
|
+
}
|
|
275
|
+
|
|
202
276
|
registerMessage(pluginId: string, handler: MessageHandler): () => void {
|
|
203
277
|
return this.handlers.registerMessage(pluginId, handler)
|
|
204
278
|
}
|
package/src/core/index.ts
CHANGED