mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-06-03 22:31:17 +00:00
8973db487b
* Migrate to eslint-9 strictTypeChecked & typescript 5. * Update to MPS 0.23.0. Required for strict type checks. * Looks like we found a test that was complete garbage, amazing really. * FIXUP * Well, the command handler was bugged previously... The command handler used to always only return the command without the prefix due to an operator precedence bug. This meant that when we made the order of operations explicit, we were now including the prefix of the command in the copy. So when we parsed arguments the code wasn't expecting the prefix to be there. * update to MPS 0.23.1. MPS 0.23.0 was bugged because we didn't enable `noUncheckedIndexedAccess` while upgrading to typescript 5. * Make sure eslint runs on all ts files. * eslint fixes. * enable `noUncheckedIndexedAccess` & `exactOptionalPropertyTypes`. * eslint ignores is clearly not understood by me. * Update SuperCoolStream for eslint and ts5. * stricter eslint done i thinks * Whoops, added on .only somewhere. * Update MPS. * fix broken test realted things. * Well I guess that part of getMessagesByUserIn was part of the interface. * Fix redactionCommandTest. * Account for escapeHTML in tests. * Fix tests. * stuff not matching with .editorconfig fixes. * Fix appservice webAPI test. * Update for MPS 0.23.3.
21 lines
1.0 KiB
TypeScript
21 lines
1.0 KiB
TypeScript
import { ActionResult } from "matrix-protection-suite";
|
|
import { MjolnirAppService } from "../../../src/appservice/AppService";
|
|
import { ReadItem } from "../../../src/commands/interface-manager/CommandReader";
|
|
import { findCommandTable } from "../../../src/commands/interface-manager/InterfaceCommand";
|
|
import { ArgumentStream } from "../../../src/commands/interface-manager/ParameterParsing";
|
|
|
|
export class AppservideBotCommandClient {
|
|
constructor(private readonly appservice: MjolnirAppService) {
|
|
|
|
}
|
|
|
|
public async sendCommand<CommandReturnType extends ActionResult<unknown>>(...items: ReadItem[]): Promise<CommandReturnType> {
|
|
const stream = new ArgumentStream(items);
|
|
const matchingCommand = findCommandTable("appservice bot").findAMatchingCommand(stream);
|
|
if (!matchingCommand) {
|
|
throw new TypeError(`Couldn't finnd a command from these items ${JSON.stringify(items)}`);
|
|
}
|
|
return await matchingCommand.parseThenInvoke({ appservice: this.appservice }, stream) as CommandReturnType;
|
|
}
|
|
}
|