40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
|
|
import type { CreatedHooks } from "../create-hooks"
|
||
|
|
|
||
|
|
type CommandExecuteBeforeInput = {
|
||
|
|
command: string
|
||
|
|
sessionID: string
|
||
|
|
arguments: string
|
||
|
|
}
|
||
|
|
|
||
|
|
type CommandExecuteBeforeOutput = {
|
||
|
|
parts: Array<{ type: string; text?: string; [key: string]: unknown }>
|
||
|
|
}
|
||
|
|
|
||
|
|
function hasPartsOutput(value: unknown): value is CommandExecuteBeforeOutput {
|
||
|
|
if (typeof value !== "object" || value === null) return false
|
||
|
|
const record = value as Record<string, unknown>
|
||
|
|
const parts = record["parts"]
|
||
|
|
return Array.isArray(parts)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function createCommandExecuteBeforeHandler(args: {
|
||
|
|
hooks: CreatedHooks
|
||
|
|
}): (
|
||
|
|
input: CommandExecuteBeforeInput,
|
||
|
|
output: CommandExecuteBeforeOutput,
|
||
|
|
) => Promise<void> {
|
||
|
|
const { hooks } = args
|
||
|
|
|
||
|
|
return async (input, output): Promise<void> => {
|
||
|
|
await hooks.autoSlashCommand?.["command.execute.before"]?.(input, output)
|
||
|
|
|
||
|
|
if (
|
||
|
|
hooks.startWork
|
||
|
|
&& input.command.toLowerCase() === "start-work"
|
||
|
|
&& hasPartsOutput(output)
|
||
|
|
) {
|
||
|
|
await hooks.startWork["command.execute.before"]?.(input, output)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|