mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-10-23 09:22:24 +00:00
Command Context should have MatrixSendClient.
This commit is contained in:
1 parent
f6771b06cf
commit
8fbec62df7
3 files changed
+9
-9
No files matched your search
@@ -38,7 +38,7 @@ import { ParameterParser, IArgumentStream, IArgumentListParser, ParsedKeywords,
|
||||
* Probably am "doing something wrong", and no, trying to make this protocol isn't it.
|
||||
*/
|
||||
|
||||
export type BaseFunction = (keywords: ParsedKeywords, ...args: any) => Promise<ActionResult<any>>;
|
||||
export type BaseFunction = (keywords: ParsedKeywords, ...args: unknown[]) => Promise<ActionResult<unknown>>;
|
||||
|
||||
type CommandLookupEntry<ExecutorType extends BaseFunction> = {
|
||||
next?: Map<string, CommandLookupEntry<ExecutorType>>,
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
*/
|
||||
|
||||
import { BaseFunction, CommandTable, InterfaceCommand } from "./InterfaceCommand";
|
||||
import { MatrixContext, MatrixInterfaceAdaptor } from "./MatrixInterfaceAdaptor";
|
||||
import { MatrixContext, MatrixInterfaceAdaptor, RendererSignature } from "./MatrixInterfaceAdaptor";
|
||||
import { ArgumentParseError, ParameterDescription, RestDescription } from "./ParameterParsing";
|
||||
import { JSXFactory } from "./JSXFactory";
|
||||
import { DocumentNode } from "./DeadDocument";
|
||||
import { renderMatrixAndSend } from "./DeadDocumentMatrix";
|
||||
import { LogService } from "matrix-bot-sdk";
|
||||
import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
|
||||
import { ActionException, ActionResult, StringRoomID, isError } from "matrix-protection-suite";
|
||||
import { ActionException, ActionResult, RoomEvent, StringRoomID, isError } from "matrix-protection-suite";
|
||||
|
||||
function requiredArgument(argumentName: string): string {
|
||||
return `<${argumentName}>`;
|
||||
@@ -88,7 +88,7 @@ export async function renderHelp(client: MatrixSendClient, commandRoomID: String
|
||||
);
|
||||
}
|
||||
|
||||
export async function tickCrossRenderer(this: MatrixInterfaceAdaptor<MatrixContext, BaseFunction>, client: MatrixSendClient, commandRoomID: StringRoomID, event: any, result: ActionResult<unknown>): Promise<void> {
|
||||
export const tickCrossRenderer: RendererSignature<MatrixContext, BaseFunction> = async function tickCrossRenderer(this: MatrixInterfaceAdaptor<MatrixContext, BaseFunction>, client: MatrixSendClient, commandRoomID: StringRoomID, event: RoomEvent, result: ActionResult<unknown>): Promise<void> {
|
||||
const react = async (emote: string) => {
|
||||
try {
|
||||
await client.unstableApis.addReactionToEvent(commandRoomID, event['event_id'], emote);
|
||||
|
||||
@@ -46,19 +46,19 @@ export interface MatrixContext {
|
||||
event: RoomMessage,
|
||||
}
|
||||
|
||||
type RendererSignature<C extends MatrixContext, ExecutorType extends BaseFunction> = (
|
||||
export type RendererSignature<C extends MatrixContext, ExecutorType extends BaseFunction> = (
|
||||
this: MatrixInterfaceAdaptor<C, ExecutorType>,
|
||||
client: MatrixClient,
|
||||
commandRoomId: string,
|
||||
client: MatrixSendClient,
|
||||
commandRoomID: StringRoomID,
|
||||
event: RoomEvent,
|
||||
result: Awaited<ReturnType<ExecutorType>>) => Promise<void>;
|
||||
result: ActionResult<unknown>) => Promise<void>;
|
||||
|
||||
export class MatrixInterfaceAdaptor<C extends MatrixContext, ExecutorType extends BaseFunction = BaseFunction> implements InterfaceAcceptor {
|
||||
public readonly isPromptable = true;
|
||||
constructor(
|
||||
public readonly interfaceCommand: InterfaceCommand<ExecutorType>,
|
||||
private readonly renderer: RendererSignature<C, ExecutorType>,
|
||||
private readonly validationErrorHandler?: (client: MatrixClient, roomID: StringRoomID, event: RoomEvent, validationError: ActionError) => Promise<void>
|
||||
private readonly validationErrorHandler?: (client: MatrixSendClient, roomID: StringRoomID, event: RoomEvent, validationError: ActionError) => Promise<void>
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user