Skip to content

Commit d8fc1fb

Browse files
authored
Merge pull request #891 from the-draupnir-project/gnuxie/mps-interface-adaptor
Extract out and depend upon @the-draupnir-project/mps-interface-adaptor This is just a very simple PR to extract the contents of `src/command/interface-manager` and `src/capabilities/CommonRenderers.tsx` to a library that can be used by other bots that depend on the matrix-protection-suite and interface-manager. Since this is essentially glue code that hasn't made its way into abstractions yet that other bots would need to duplicate to get started. And we're doing this because we're thinking of making a contributor bot for fun primarily, gathering feedback, and encouraging testing .
2 parents 6fe9138 + 375d7ad commit d8fc1fb

File tree

54 files changed

+165
-1686
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+165
-1686
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"@sinclair/typebox": "0.34.13",
5454
"@the-draupnir-project/interface-manager": "4.1.0",
5555
"@the-draupnir-project/matrix-basic-types": "1.3.0",
56+
"@the-draupnir-project/mps-interface-adaptor": "^0.4.1",
5657
"better-sqlite3": "^9.4.3",
5758
"body-parser": "^1.20.2",
5859
"config": "^3.3.9",
@@ -62,8 +63,8 @@
6263
"jsdom": "^24.0.0",
6364
"matrix-appservice-bridge": "^10.3.1",
6465
"matrix-bot-sdk": "npm:@vector-im/matrix-bot-sdk@^0.7.1-element.6",
65-
"matrix-protection-suite": "npm:@gnuxie/matrix-protection-suite@3.4.0",
66-
"matrix-protection-suite-for-matrix-bot-sdk": "npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@3.1.4",
66+
"matrix-protection-suite": "npm:@gnuxie/matrix-protection-suite@3.5.0",
67+
"matrix-protection-suite-for-matrix-bot-sdk": "npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@3.5.0",
6768
"pg": "^8.8.0",
6869
"yaml": "^2.3.2"
6970
},

src/Draupnir.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,12 @@ import { ThrottlingQueue } from "./queues/ThrottlingQueue";
3434
import ManagementRoomOutput from "./managementroom/ManagementRoomOutput";
3535
import { ReportPoller } from "./report/ReportPoller";
3636
import { StandardReportManager } from "./report/ReportManager";
37-
import { MatrixReactionHandler } from "./commands/interface-manager/MatrixReactionHandler";
3837
import {
3938
MatrixSendClient,
4039
SynapseAdminClient,
4140
} from "matrix-protection-suite-for-matrix-bot-sdk";
4241
import { IConfig } from "./config";
4342
import { LogLevel } from "matrix-bot-sdk";
44-
import {
45-
ARGUMENT_PROMPT_LISTENER,
46-
DEFAUILT_ARGUMENT_PROMPT_LISTENER,
47-
makeListenerForArgumentPrompt as makeListenerForArgumentPrompt,
48-
makeListenerForPromptDefault,
49-
} from "./commands/interface-manager/MatrixPromptForAccept";
5043
import { RendererMessageCollector } from "./capabilities/RendererMessageCollector";
5144
import { DraupnirRendererMessageCollector } from "./capabilities/DraupnirRendererMessageCollector";
5245
import { renderProtectionFailedToStart } from "./protections/ProtectedRoomsSetRenderers";
@@ -60,10 +53,6 @@ import {
6053
MatrixRoomReference,
6154
userServerName,
6255
} from "@the-draupnir-project/matrix-basic-types";
63-
import {
64-
MatrixAdaptorContext,
65-
sendMatrixEventsFromDeadDocument,
66-
} from "./commands/interface-manager/MPSMatrixInterfaceAdaptor";
6756
import {
6857
makeDraupnirCommandDispatcher,
6958
makeDraupnirJSCommandDispatcher,
@@ -77,13 +66,21 @@ import {
7766
StandardPresentationArgumentStream,
7867
} from "@the-draupnir-project/interface-manager";
7968
import { ManagementRoomDetail } from "./managementroom/ManagementRoomDetail";
80-
import {
81-
COMMAND_CONFIRMATION_LISTENER,
82-
makeConfirmationPromptListener,
83-
} from "./commands/interface-manager/MatrixPromptForConfirmation";
8469
import { SynapseHttpAntispam } from "./webapis/SynapseHTTPAntispam/SynapseHttpAntispam";
8570
import { DraupnirStores } from "./backingstore/DraupnirStores";
8671
import { HomeserverUserPurgingDeactivate } from "./protections/HomeserverUserPolicyApplication/HomeserverUserPurgingDeactivate";
72+
import {
73+
ARGUMENT_PROMPT_LISTENER,
74+
COMMAND_CONFIRMATION_LISTENER,
75+
DEFAUILT_ARGUMENT_PROMPT_LISTENER,
76+
makeConfirmationPromptListener,
77+
makeListenerForArgumentPrompt,
78+
makeListenerForPromptDefault,
79+
MatrixAdaptorContext,
80+
MatrixReactionHandler,
81+
sendMatrixEventsFromDeadDocument,
82+
} from "@the-draupnir-project/mps-interface-adaptor";
83+
8784
const log = new Logger("Draupnir");
8885

8986
// webAPIS should not be included on the Draupnir class.
@@ -171,7 +168,6 @@ export class Draupnir implements Client, MatrixAdaptorContext {
171168
);
172169
this.reactionHandler = new MatrixReactionHandler(
173170
this.managementRoom.toRoomIDOrAlias(),
174-
client,
175171
clientUserID,
176172
clientPlatform
177173
);

src/appservice/bot/AppserviceBotCommandDispatcher.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ import {
1616
StandardJSInterfaceCommandDispatcher,
1717
StandardMatrixInterfaceCommandDispatcher,
1818
} from "@the-draupnir-project/interface-manager";
19-
import {
20-
MPSCommandDispatcherCallbacks,
21-
MatrixEventContext,
22-
invocationInformationFromMatrixEventcontext,
23-
} from "../../commands/interface-manager/MPSMatrixInterfaceAdaptor";
2419
import { AppserviceAdaptorContext } from "./AppserviceBotPrerequisite";
2520
import { AppserviceBotCommands } from "./AppserviceBotCommandTable";
2621
import { AppserviceBotHelpCommand } from "./AppserviceBotHelp";
2722
import {
2823
AppserviceBotInterfaceAdaptor,
2924
AppserviceAdaptorContextToCommandContextTranslator,
3025
} from "./AppserviceBotInterfaceAdaptor";
26+
import {
27+
invocationInformationFromMatrixEventcontext,
28+
MatrixEventContext,
29+
MPSCommandDispatcherCallbacks,
30+
} from "@the-draupnir-project/mps-interface-adaptor";
3131

3232
function makeAppserviceCommandNormaliser(
3333
appserviceContext: AppserviceAdaptorContext

src/appservice/bot/AppserviceBotHelp.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import {
1212
describeCommand,
1313
} from "@the-draupnir-project/interface-manager";
1414
import { ActionResult, Ok } from "matrix-protection-suite";
15-
import { MatrixAdaptorContext } from "../../commands/interface-manager/MPSMatrixInterfaceAdaptor";
1615
import { AppserviceBotCommands } from "./AppserviceBotCommandTable";
17-
import { renderTableHelp } from "../../commands/interface-manager/MatrixHelpRenderer";
1816
import { AppserviceBotInterfaceAdaptor } from "./AppserviceBotInterfaceAdaptor";
17+
import {
18+
MatrixAdaptorContext,
19+
renderTableHelp,
20+
} from "@the-draupnir-project/mps-interface-adaptor";
21+
import { DOCUMENTATION_URL } from "../../config";
1922

2023
export const AppserviceBotHelpCommand = describeCommand({
2124
rest: {
@@ -34,7 +37,9 @@ export const AppserviceBotHelpCommand = describeCommand({
3437
});
3538

3639
function renderAppserviceBotHelp(): Result<DocumentNode> {
37-
return Ok(<root>{renderTableHelp(AppserviceBotCommands)}</root>);
40+
return Ok(
41+
<root>{renderTableHelp(AppserviceBotCommands, DOCUMENTATION_URL)}</root>
42+
);
3843
}
3944

4045
AppserviceBotInterfaceAdaptor.describeRenderer(AppserviceBotHelpCommand, {

src/appservice/bot/AppserviceBotInterfaceAdaptor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import {
1111
StandardAdaptorContextToCommandContextTranslator,
1212
StandardMatrixInterfaceAdaptor,
1313
} from "@the-draupnir-project/interface-manager";
14+
import { AppserviceAdaptorContext } from "./AppserviceBotPrerequisite";
1415
import {
15-
MatrixEventContext,
1616
invocationInformationFromMatrixEventcontext,
17-
MPSMatrixInterfaceAdaptorCallbacks,
17+
MatrixEventContext,
1818
MPSCommandDispatcherCallbacks,
19-
} from "../../commands/interface-manager/MPSMatrixInterfaceAdaptor";
20-
import { AppserviceAdaptorContext } from "./AppserviceBotPrerequisite";
19+
MPSMatrixInterfaceAdaptorCallbacks,
20+
} from "@the-draupnir-project/mps-interface-adaptor";
2121

2222
export const AppserviceAdaptorContextToCommandContextTranslator =
2323
new StandardAdaptorContextToCommandContextTranslator<AppserviceAdaptorContext>();

src/appservice/bot/AppserviceBotPrerequisite.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
// https://github.com/the-draupnir-project/Draupnir
88
// </text>
99

10-
import { MatrixAdaptorContext } from "../../commands/interface-manager/MPSMatrixInterfaceAdaptor";
10+
import { MatrixAdaptorContext } from "@the-draupnir-project/mps-interface-adaptor";
1111
import { MjolnirAppService } from "../AppService";
12+
import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
1213

1314
export interface AppserviceAdaptorContext extends MatrixAdaptorContext {
1415
appservice: MjolnirAppService;
16+
client: MatrixSendClient;
1517
}

src/appservice/bot/AppserviceCommandHandler.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ import {
2828
StandardPresentationArgumentStream,
2929
Presentation,
3030
} from "@the-draupnir-project/interface-manager";
31-
import { MatrixEventContext } from "../../commands/interface-manager/MPSMatrixInterfaceAdaptor";
32-
import { MatrixReactionHandler } from "../../commands/interface-manager/MatrixReactionHandler";
31+
import "./AppserviceBotCommands";
3332
import {
3433
ARGUMENT_PROMPT_LISTENER,
3534
DEFAUILT_ARGUMENT_PROMPT_LISTENER,
3635
makeListenerForArgumentPrompt,
3736
makeListenerForPromptDefault,
38-
} from "../../commands/interface-manager/MatrixPromptForAccept";
39-
import "./AppserviceBotCommands";
37+
MatrixEventContext,
38+
MatrixReactionHandler,
39+
} from "@the-draupnir-project/mps-interface-adaptor";
4040

4141
export type AppserviceBaseExecutor = (
4242
this: AppserviceAdaptorContext,
@@ -58,7 +58,6 @@ export class AppserviceCommandHandler {
5858
) {
5959
this.reactionHandler = new MatrixReactionHandler(
6060
this.appservice.accessControlRoomID,
61-
this.appservice.bridge.getBot().getClient(),
6261
this.appservice.botUserID,
6362
clientPlatform
6463
);

0 commit comments

Comments
 (0)