Move to @the-draupnir-project/basic-matrix-types. (#508)

We split out some utility types from the matrix-protection-suite into a library https://github.com/the-draupnir-project/matrix-basic-types



I can't believe that like the extra lines from 

```
import {
} from ...
```

are adding up so much but whatever. 

* Move to @the-draupnir-project/basic-matrix-types.

* Whoopsie missed a test.
This commit is contained in:
Gnuxie
2024-08-16 19:12:21 +01:00
committed by GitHub
parent 07667c71dd
commit cc9d4cb9d5
77 changed files with 358 additions and 254 deletions
+3 -2
View File
@@ -53,6 +53,7 @@
"@sentry/node": "^7.17.2",
"@sentry/tracing": "^7.17.2",
"@sinclair/typebox": "0.32.34",
"@the-draupnir-project/matrix-basic-types": "^0.1.1",
"await-lock": "^2.2.2",
"better-sqlite3": "^9.4.3",
"body-parser": "^1.20.2",
@@ -64,8 +65,8 @@
"js-yaml": "^4.1.0",
"jsdom": "^24.0.0",
"matrix-appservice-bridge": "^9.0.1",
"matrix-protection-suite": "npm:@gnuxie/matrix-protection-suite@0.23.4",
"matrix-protection-suite-for-matrix-bot-sdk": "npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@0.23.4",
"matrix-protection-suite": "npm:@gnuxie/matrix-protection-suite@1.0.0",
"matrix-protection-suite-for-matrix-bot-sdk": "npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@1.0.0",
"parse-duration": "^1.0.2",
"pg": "^8.8.0",
"shell-quote": "^1.7.3",
+11 -9
View File
@@ -16,8 +16,6 @@ import {
EventReport,
LoggableConfigTracker,
Logger,
MatrixRoomID,
MatrixRoomReference,
MembershipEvent,
Ok,
PolicyRoomManager,
@@ -27,16 +25,10 @@ import {
RoomMembershipRevisionIssuer,
RoomMessage,
RoomStateManager,
StringRoomID,
StringUserID,
Task,
TextMessageContent,
Value,
isError,
isStringRoomAlias,
isStringRoomID,
serverName,
userLocalpart,
} from "matrix-protection-suite";
import { UnlistedUserRedactionQueue } from "./queues/UnlistedUserRedactionQueue";
import { findCommandTable } from "./commands/interface-manager/InterfaceCommand";
@@ -69,6 +61,16 @@ import { renderProtectionFailedToStart } from "./protections/ProtectedRoomsSetRe
import { draupnirStatusInfo, renderStatusInfo } from "./commands/StatusCommand";
import { renderMatrixAndSend } from "./commands/interface-manager/DeadDocumentMatrix";
import { isInvitationForUser } from "./protections/invitation/inviteCore";
import {
StringRoomID,
StringUserID,
MatrixRoomID,
isStringRoomID,
isStringRoomAlias,
MatrixRoomReference,
userLocalpart,
userServerName,
} from "@the-draupnir-project/matrix-basic-types";
const log = new Logger("Draupnir");
@@ -403,7 +405,7 @@ export class Draupnir implements Client {
}
public createRoomReference(roomID: StringRoomID): MatrixRoomID {
return new MatrixRoomID(roomID, [serverName(this.clientUserID)]);
return new MatrixRoomID(roomID, [userServerName(this.clientUserID)]);
}
public handleEventReport(report: EventReport): void {
this.protectedRoomsSet.handleEventReport(report);
+7 -5
View File
@@ -10,11 +10,6 @@
import {
isError,
StringUserID,
MatrixRoomReference,
isStringUserID,
isStringRoomAlias,
isStringRoomID,
StandardClientsInRoomMap,
DefaultEventDecoder,
setGlobalLoggerProvider,
@@ -32,6 +27,13 @@ import { IConfig } from "./config";
import { Draupnir } from "./Draupnir";
import { DraupnirFactory } from "./draupnirfactory/DraupnirFactory";
import { WebAPIs } from "./webapis/WebAPIs";
import {
isStringUserID,
isStringRoomAlias,
isStringRoomID,
MatrixRoomReference,
StringUserID,
} from "@the-draupnir-project/matrix-basic-types";
setGlobalLoggerProvider(new BotSDKLogServiceLogger());
+5 -5
View File
@@ -19,12 +19,12 @@ import { IConfig } from "./config";
import { htmlEscape } from "./utils";
import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
import {
Permalinks,
StringRoomAlias,
StringRoomID,
StringUserID,
serverName,
} from "matrix-protection-suite";
Permalinks,
StringRoomAlias,
userServerName,
} from "@the-draupnir-project/matrix-basic-types";
const levelToFn = {
[LogLevel.DEBUG.toString()]: LogService.debug,
@@ -73,7 +73,7 @@ export default class ManagementRoomOutput {
return v.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
};
const viaServers = [serverName(this.clientUserID)];
const viaServers = [userServerName(this.clientUserID)];
for (const roomId of roomIds) {
let alias = roomId;
try {
+4 -2
View File
@@ -8,14 +8,16 @@
// https://github.com/matrix-org/mjolnir
// </text>
import {
MatrixRoomID,
StringUserID,
} from "@the-draupnir-project/matrix-basic-types";
import {
ActionResult,
EntityAccess,
MatrixRoomID,
Ok,
PolicyListRevisionIssuer,
PolicyRoomManager,
StringUserID,
isError,
AccessControl as MPSAccess,
PolicyRoomEditor,
+2 -1
View File
@@ -14,7 +14,8 @@ import * as bodyParser from "body-parser";
import * as http from "http";
import { Logger } from "matrix-appservice-bridge";
import { AppServiceDraupnirManager } from "./AppServiceDraupnirManager";
import { isError, isStringUserID } from "matrix-protection-suite";
import { isError } from "matrix-protection-suite";
import { isStringUserID } from "@the-draupnir-project/matrix-basic-types";
const log = new Logger("Api");
/**
+7 -5
View File
@@ -36,16 +36,18 @@ import {
ClientsInRoomMap,
DefaultEventDecoder,
EventDecoder,
MatrixRoomReference,
StandardClientsInRoomMap,
StringRoomID,
StringUserID,
Task,
isError,
isStringRoomAlias,
isStringRoomID,
} from "matrix-protection-suite";
import { AppServiceDraupnirManager } from "./AppServiceDraupnirManager";
import {
MatrixRoomReference,
StringRoomID,
StringUserID,
isStringRoomAlias,
isStringRoomID,
} from "@the-draupnir-project/matrix-basic-types";
const log = new Logger("AppService");
/**
+7 -5
View File
@@ -22,15 +22,10 @@ import {
ActionException,
ActionExceptionKind,
ActionResult,
MatrixRoomReference,
Ok,
PropagationType,
StringRoomID,
StringUserID,
Task,
isError,
isStringRoomID,
userLocalpart,
} from "matrix-protection-suite";
import { Draupnir } from "../Draupnir";
import {
@@ -44,6 +39,13 @@ import {
UnstartedDraupnir,
} from "../draupnirfactory/StandardDraupnirManager";
import { DraupnirFactory } from "../draupnirfactory/DraupnirFactory";
import {
StringUserID,
StringRoomID,
MatrixRoomReference,
userLocalpart,
isStringRoomID,
} from "@the-draupnir-project/matrix-basic-types";
const log = new Logger("AppServiceDraupnirManager");
+6 -5
View File
@@ -12,9 +12,10 @@ import {
ParsedKeywords,
} from "../../commands/interface-manager/ParameterParsing";
import { AppserviceContext } from "./AppserviceCommandHandler";
import { UserID, ActionResult } from "matrix-protection-suite";
import { ActionResult } from "matrix-protection-suite";
import { defineMatrixInterfaceAdaptor } from "../../commands/interface-manager/MatrixInterfaceAdaptor";
import { tickCrossRenderer } from "../../commands/interface-manager/MatrixHelpRenderer";
import { MatrixUserID } from "@the-draupnir-project/matrix-basic-types";
defineInterfaceCommand({
designator: ["allow"],
@@ -22,14 +23,14 @@ defineInterfaceCommand({
parameters: parameters([
{
name: "user",
acceptor: findPresentationType("UserID"),
acceptor: findPresentationType("MatrixUserID"),
description: "The user that should be allowed to provision a bot",
},
]),
command: async function (
this: AppserviceContext,
_keywords: ParsedKeywords,
user: UserID
user: MatrixUserID
): Promise<ActionResult<void>> {
return await this.appservice.accessControl.allow(user.toString());
},
@@ -48,7 +49,7 @@ defineInterfaceCommand({
parameters: parameters([
{
name: "user",
acceptor: findPresentationType("UserID"),
acceptor: findPresentationType("MatrixUserID"),
description:
"The user which shall not be allowed to provision bots anymore",
},
@@ -56,7 +57,7 @@ defineInterfaceCommand({
command: async function (
this: AppserviceContext,
_keywords: ParsedKeywords,
user: UserID
user: MatrixUserID
): Promise<ActionResult<void>> {
return await this.appservice.accessControl.remove(user.toString());
},
@@ -28,8 +28,6 @@ import {
ClientPlatform,
Ok,
RoomMessage,
StringRoomID,
StringUserID,
Task,
Value,
isError,
@@ -57,6 +55,10 @@ export type AppserviceBaseExecutor = (
import "../../commands/interface-manager/MatrixPresentations";
import "./ListCommand";
import "./AccessCommands";
import {
StringUserID,
StringRoomID,
} from "@the-draupnir-project/matrix-basic-types";
defineInterfaceCommand({
parameters: parameters(
+3 -3
View File
@@ -22,10 +22,10 @@ import {
isError,
Ok,
RoomEvent,
UserID,
} from "matrix-protection-suite";
import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
import { UnstartedDraupnir } from "../../draupnirfactory/StandardDraupnirManager";
import { MatrixUserID } from "@the-draupnir-project/matrix-basic-types";
/**
* There is ovbiously something we're doing very wrong here,
@@ -95,14 +95,14 @@ const restart = defineInterfaceCommand<AppserviceBaseExecutor>({
parameters: parameters([
{
name: "draupnir",
acceptor: findPresentationType("UserID"),
acceptor: findPresentationType("MatrixUserID"),
description: "The userid of the draupnir to restart",
},
]),
command: async function (
this,
_keywords,
draupnirUser: UserID
draupnirUser: MatrixUserID
): Promise<ActionResult<void>> {
const draupnirManager = this.appservice.draupnirManager;
const draupnir = draupnirManager.findUnstartedDraupnir(
+4 -1
View File
@@ -8,7 +8,10 @@
// https://github.com/matrix-org/mjolnir
// </text>
import { StringRoomID, StringUserID } from "matrix-protection-suite";
import {
StringUserID,
StringRoomID,
} from "@the-draupnir-project/matrix-basic-types";
export interface MjolnirRecord {
local_part: string;
@@ -13,11 +13,11 @@ import {
RoomStateRevision,
StateChange,
StateEvent,
StringRoomID,
isError,
} from "matrix-protection-suite";
import { BetterSqliteStore } from "./BetterSqliteStore";
import { jsonReviver } from "../../utils";
import { StringRoomID } from "@the-draupnir-project/matrix-basic-types";
const log = new Logger("SqliteRoomStateBackingStore");
+5 -3
View File
@@ -13,11 +13,8 @@ import {
ActionException,
ActionResult,
DescriptionMeta,
MatrixRoomReference,
ResultForUsersInRoom,
RoomSetResult,
StringRoomID,
StringUserID,
isOk,
} from "matrix-protection-suite";
import { DocumentNode } from "../commands/interface-manager/DeadDocument";
@@ -26,6 +23,11 @@ import {
renderMentionPill,
renderRoomPill,
} from "../commands/interface-manager/MatrixHelpRenderer";
import {
StringRoomID,
MatrixRoomReference,
StringUserID,
} from "@the-draupnir-project/matrix-basic-types";
export function renderElaborationTrail(error: ActionError): DocumentNode {
return (
@@ -7,10 +7,11 @@ import {
RendererMessage,
RendererMessageCollector,
} from "./RendererMessageCollector";
import { DescriptionMeta, StringRoomID, Task } from "matrix-protection-suite";
import { DescriptionMeta, Task } from "matrix-protection-suite";
import { DocumentNode } from "../commands/interface-manager/DeadDocument";
import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix";
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
import { StringRoomID } from "@the-draupnir-project/matrix-basic-types";
export class DraupnirRendererMessageCollector
implements RendererMessageCollector
@@ -13,12 +13,10 @@ import {
Capability,
DescriptionMeta,
Ok,
Permalinks,
PolicyListRevision,
RoomSetResult,
ServerACLConsequencesContext,
ServerConsequences,
StringRoomID,
describeCapabilityContextGlue,
describeCapabilityRenderer,
isError,
@@ -30,6 +28,10 @@ import {
} from "./CommonRenderers";
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
import { Draupnir } from "../Draupnir";
import {
StringRoomID,
Permalinks,
} from "@the-draupnir-project/matrix-basic-types";
class StandardServerConsequencesRenderer implements ServerConsequences {
constructor(
@@ -13,10 +13,7 @@ import {
Capability,
DescriptionMeta,
EventConsequences,
Permalinks,
RoomEventRedacter,
StringEventID,
StringRoomID,
describeCapabilityContextGlue,
describeCapabilityRenderer,
isError,
@@ -25,6 +22,11 @@ import { RendererMessageCollector } from "./RendererMessageCollector";
import { renderFailedSingularConsequence } from "./CommonRenderers";
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
import { Draupnir } from "../Draupnir";
import {
Permalinks,
StringEventID,
StringRoomID,
} from "@the-draupnir-project/matrix-basic-types";
class StandardEventConsequencesRenderer implements EventConsequences {
constructor(
@@ -13,16 +13,12 @@ import {
ActionResult,
Capability,
DescriptionMeta,
MatrixRoomReference,
Ok,
Permalinks,
PolicyListRevision,
ResultForUsersInRoom,
ResultForUsersInSet,
RoomSetResult,
StandardUserConsequencesContext,
StringRoomID,
StringUserID,
UserConsequences,
describeCapabilityContextGlue,
describeCapabilityRenderer,
@@ -38,6 +34,12 @@ import {
import { DocumentNode } from "../commands/interface-manager/DeadDocument";
import { Draupnir } from "../Draupnir";
import { renderRoomPill } from "../commands/interface-manager/MatrixHelpRenderer";
import {
StringUserID,
StringRoomID,
Permalinks,
MatrixRoomReference,
} from "@the-draupnir-project/matrix-basic-types";
// yeah i know this is a bit insane but whatever, it can be our secret.
function renderResultForUserInSetMap(
+4 -2
View File
@@ -24,11 +24,13 @@ import {
ActionError,
ActionResult,
isError,
MatrixRoomAlias,
MatrixRoomReference,
Ok,
} from "matrix-protection-suite";
import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk";
import {
MatrixRoomAlias,
MatrixRoomReference,
} from "@the-draupnir-project/matrix-basic-types";
// TODO: we should probably add an --admin keyword to these commands
// since they don't actually need admin. Mjolnir had them as admin though.
+7 -5
View File
@@ -28,15 +28,17 @@ import { PromptOptions } from "./interface-manager/PromptForAccept";
import { Draupnir } from "../Draupnir";
import {
ActionResult,
MatrixRoomReference,
PolicyRoomEditor,
PolicyRuleType,
isError,
UserID,
Ok,
} from "matrix-protection-suite";
import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk";
import { findPolicyRoomIDFromShortcode } from "./CreateBanListCommand";
import {
MatrixRoomReference,
MatrixUserID,
} from "@the-draupnir-project/matrix-basic-types";
export async function findPolicyRoomEditorFromRoomReference(
draupnir: Draupnir,
@@ -55,7 +57,7 @@ export async function findPolicyRoomEditorFromRoomReference(
async function ban(
this: DraupnirContext,
_keywords: ParsedKeywords,
entity: UserID | MatrixRoomReference | string,
entity: MatrixUserID | MatrixRoomReference | string,
policyRoomDesignator: MatrixRoomReference | string,
...reasonParts: string[]
): Promise<ActionResult<string>> {
@@ -75,7 +77,7 @@ async function ban(
}
const policyListEditor = policyListEditorResult.ok;
const reason = reasonParts.join(" ");
if (entity instanceof UserID) {
if (entity instanceof MatrixUserID) {
return await policyListEditor.banEntity(
PolicyRuleType.User,
entity.toString(),
@@ -111,7 +113,7 @@ defineInterfaceCommand({
{
name: "entity",
acceptor: union(
findPresentationType("UserID"),
findPresentationType("MatrixUserID"),
findPresentationType("MatrixRoomReference"),
findPresentationType("string")
),
+1 -1
View File
@@ -29,9 +29,9 @@ import {
ActionResult,
ResultError,
RoomMessage,
StringRoomID,
} from "matrix-protection-suite";
import { Draupnir } from "../Draupnir";
import { StringRoomID } from "@the-draupnir-project/matrix-basic-types";
export interface DraupnirContext extends MatrixContext {
draupnir: Draupnir;
+1 -1
View File
@@ -11,7 +11,6 @@
import {
ActionError,
ActionResult,
MatrixRoomID,
Ok,
PolicyRuleType,
PropagationType,
@@ -31,6 +30,7 @@ import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfac
import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer";
import { listInfo } from "./StatusCommand";
import { Draupnir } from "../Draupnir";
import { MatrixRoomID } from "@the-draupnir-project/matrix-basic-types";
export async function createList(
this: DraupnirContext,
+3 -3
View File
@@ -24,9 +24,9 @@ import {
ActionError,
ActionResult,
Ok,
UserID,
isError,
} from "matrix-protection-suite";
import { MatrixUserID } from "@the-draupnir-project/matrix-basic-types";
defineInterfaceCommand({
table: "synapse admin",
@@ -36,13 +36,13 @@ defineInterfaceCommand({
parameters: parameters([
{
name: "user",
acceptor: findPresentationType("UserID"),
acceptor: findPresentationType("MatrixUserID"),
},
]),
command: async function (
this: DraupnirContext,
_keywords: ParsedKeywords,
targetUser: UserID
targetUser: MatrixUserID
): Promise<ActionResult<void>> {
const isAdmin = await this.draupnir.synapseAdminClient?.isSynapseAdmin();
if (isAdmin === undefined || isError(isAdmin) || !isAdmin.ok) {
+6 -4
View File
@@ -23,18 +23,20 @@ import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfac
import {
ActionError,
ActionResult,
MatrixRoomReference,
Ok,
UserID,
isError,
} from "matrix-protection-suite";
import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk";
import {
MatrixRoomReference,
MatrixUserID,
} from "@the-draupnir-project/matrix-basic-types";
async function hijackRoomCommand(
this: DraupnirContext,
_keywords: ParsedKeywords,
room: MatrixRoomReference,
user: UserID
user: MatrixUserID
): Promise<ActionResult<void>> {
const isAdmin = await this.draupnir.synapseAdminClient?.isSynapseAdmin();
if (
@@ -71,7 +73,7 @@ defineInterfaceCommand<DraupnirBaseExecutor>({
},
{
name: "user",
acceptor: findPresentationType("UserID"),
acceptor: findPresentationType("MatrixUserID"),
},
]),
command: hijackRoomCommand,
+1 -1
View File
@@ -11,7 +11,6 @@
import { DraupnirBaseExecutor, DraupnirContext } from "./CommandHandler";
import {
ActionResult,
MatrixRoomReference,
MultipleErrors,
PolicyRuleType,
RoomActionError,
@@ -30,6 +29,7 @@ import {
} from "./interface-manager/ParameterParsing";
import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor";
import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer";
import { MatrixRoomReference } from "@the-draupnir-project/matrix-basic-types";
export async function importCommand(
this: DraupnirContext,
+8 -6
View File
@@ -13,11 +13,7 @@ import { DraupnirContext } from "./CommandHandler";
import {
ActionError,
ActionResult,
MatrixRoomReference,
Ok,
StringRoomID,
StringUserID,
UserID,
isError,
} from "matrix-protection-suite";
import {
@@ -36,6 +32,12 @@ import {
import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor";
import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix";
import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer";
import {
StringUserID,
StringRoomID,
MatrixRoomReference,
MatrixUserID,
} from "@the-draupnir-project/matrix-basic-types";
type UsersToKick = Map<StringUserID, StringRoomID[]>;
@@ -77,7 +79,7 @@ function renderUsersToKick(usersToKick: UsersToKick): DocumentNode {
export async function kickCommand(
this: DraupnirContext,
keywords: ParsedKeywords,
user: UserID,
user: MatrixUserID,
...reasonParts: string[]
): Promise<ActionResult<UsersToKick>> {
const restrictToRoomReference = keywords.getKeyword<MatrixRoomReference>(
@@ -143,7 +145,7 @@ defineInterfaceCommand({
[
{
name: "user",
acceptor: findPresentationType("string"),
acceptor: findPresentationType("MatrixUserID"),
},
],
undefined,
+1 -1
View File
@@ -27,7 +27,6 @@ import {
ProtectionSetting,
ProtectionSettings,
RoomEvent,
StringRoomID,
UnknownSettings,
findProtection,
getAllProtections,
@@ -41,6 +40,7 @@ import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
import { DeadDocumentJSX } from "./interface-manager/JSXFactory";
import { DocumentNode } from "./interface-manager/DeadDocument";
import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix";
import { StringRoomID } from "@the-draupnir-project/matrix-basic-types";
defineInterfaceCommand({
designator: ["protections", "enable"],
+10 -12
View File
@@ -8,16 +8,7 @@
// https://github.com/matrix-org/mjolnir
// </text>
import {
ActionResult,
MatrixEventReference,
MatrixEventViaAlias,
MatrixEventViaRoomID,
MatrixRoomReference,
Ok,
UserID,
isError,
} from "matrix-protection-suite";
import { ActionResult, Ok, isError } from "matrix-protection-suite";
import { redactUserMessagesIn } from "../utils";
import {
KeywordsDescription,
@@ -36,6 +27,13 @@ import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot
import { Draupnir } from "../Draupnir";
import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor";
import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer";
import {
MatrixEventReference,
MatrixEventViaAlias,
MatrixEventViaRoomID,
MatrixRoomReference,
MatrixUserID,
} from "@the-draupnir-project/matrix-basic-types";
export async function redactEvent(
draupnir: Draupnir,
@@ -60,7 +58,7 @@ export async function redactEvent(
export async function redactCommand(
this: DraupnirContext,
keywords: ParsedKeywords,
reference: UserID | MatrixEventReference,
reference: MatrixUserID | MatrixEventReference,
...reasonParts: string[]
): Promise<ActionResult<void>> {
const reason = reasonParts.join(" ");
@@ -106,7 +104,7 @@ defineInterfaceCommand({
{
name: "entity",
acceptor: union(
findPresentationType("UserID"),
findPresentationType("MatrixUserID"),
findPresentationType("MatrixEventReference")
),
},
+5 -6
View File
@@ -8,12 +8,7 @@
// https://github.com/matrix-org/mjolnir
// </text>
import {
ActionResult,
MatrixRoomAlias,
MatrixRoomID,
isError,
} from "matrix-protection-suite";
import { ActionResult, isError } from "matrix-protection-suite";
import { DraupnirContext } from "./CommandHandler";
import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk";
import {
@@ -32,6 +27,10 @@ import {
} from "./interface-manager/MatrixHelpRenderer";
import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix";
import { DeadDocumentJSX } from "./interface-manager/JSXFactory";
import {
MatrixRoomAlias,
MatrixRoomID,
} from "@the-draupnir-project/matrix-basic-types";
async function resolveAliasCommand(
this: DraupnirContext,
+4 -2
View File
@@ -26,12 +26,14 @@ import {
ActionException,
ActionExceptionKind,
ActionResult,
MatrixRoomID,
MatrixRoomReference,
Ok,
isError,
} from "matrix-protection-suite";
import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk";
import {
MatrixRoomID,
MatrixRoomReference,
} from "@the-draupnir-project/matrix-basic-types";
defineInterfaceCommand({
table: "draupnir",
+8 -6
View File
@@ -29,17 +29,19 @@ import {
} from "./interface-manager/ParameterParsing";
import {
ActionResult,
MatrixRoomID,
MatrixRoomReference,
Ok,
PolicyRoomWatchProfile,
PolicyRule,
StringRoomID,
isError,
UserID,
RoomEvent,
} from "matrix-protection-suite";
import { listInfo } from "./StatusCommand";
import {
StringRoomID,
MatrixRoomID,
MatrixRoomReference,
MatrixUserID,
} from "@the-draupnir-project/matrix-basic-types";
async function renderListMatches(
this: MatrixInterfaceAdaptor<MatrixContext>,
@@ -144,7 +146,7 @@ defineInterfaceCommand({
{
name: "entity",
acceptor: union(
findPresentationType("UserID"),
findPresentationType("MatrixUserID"),
findPresentationType("MatrixRoomReference"),
findPresentationType("string")
),
@@ -153,7 +155,7 @@ defineInterfaceCommand({
command: async function (
this: DraupnirContext,
_keywords,
entity: string | UserID | MatrixRoomReference
entity: string | MatrixUserID | MatrixRoomReference
): Promise<ActionResult<ListMatches[]>> {
const policyRooms = await listInfo(this.draupnir);
return Ok(
+8 -10
View File
@@ -8,14 +8,7 @@
// https://github.com/matrix-org/mjolnir
// </text>
import {
ActionResult,
MatrixRoomID,
MatrixRoomReference,
Ok,
UserID,
isError,
} from "matrix-protection-suite";
import { ActionResult, Ok, isError } from "matrix-protection-suite";
import { DraupnirContext } from "./CommandHandler";
import {
ParsedKeywords,
@@ -25,11 +18,16 @@ import {
} from "./interface-manager/ParameterParsing";
import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk";
import { defineInterfaceCommand } from "./interface-manager/InterfaceCommand";
import {
MatrixRoomID,
MatrixRoomReference,
MatrixUserID,
} from "@the-draupnir-project/matrix-basic-types";
async function setPowerLevelCommand(
this: DraupnirContext,
_keywords: ParsedKeywords,
user: UserID,
user: MatrixUserID,
powerLevel: string,
...givenRooms: MatrixRoomReference[]
): Promise<ActionResult<void>> {
@@ -64,7 +62,7 @@ defineInterfaceCommand({
[
{
name: "user",
acceptor: findPresentationType("UserID"),
acceptor: findPresentationType("MatrixUserID"),
},
{
name: "power level",
+1 -1
View File
@@ -24,11 +24,11 @@ import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer";
import {
ActionError,
ActionResult,
MatrixRoomReference,
Ok,
isError,
} from "matrix-protection-suite";
import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk";
import { MatrixRoomReference } from "@the-draupnir-project/matrix-basic-types";
defineInterfaceCommand({
table: "synapse admin",
+9 -7
View File
@@ -27,14 +27,16 @@ import { Draupnir } from "../Draupnir";
import {
ActionResult,
isError,
isStringUserID,
MatrixRoomReference,
Ok,
PolicyRuleType,
UserID,
} from "matrix-protection-suite";
import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk";
import { findPolicyRoomIDFromShortcode } from "./CreateBanListCommand";
import {
isStringUserID,
MatrixRoomReference,
MatrixUserID,
} from "@the-draupnir-project/matrix-basic-types";
async function unbanUserFromRooms(draupnir: Draupnir, rule: MatrixGlob) {
await draupnir.managementRoomOutput.logMessage(
@@ -75,7 +77,7 @@ async function unbanUserFromRooms(draupnir: Draupnir, rule: MatrixGlob) {
async function unban(
this: DraupnirContext,
keywords: ParsedKeywords,
entity: UserID | MatrixRoomReference | string,
entity: MatrixUserID | MatrixRoomReference | string,
policyRoomDesignator: MatrixRoomReference | string
): Promise<ActionResult<void>> {
const policyRoomReference =
@@ -98,7 +100,7 @@ async function unban(
return policyRoomEditor;
}
const policyRoomUnban =
entity instanceof UserID
entity instanceof MatrixUserID
? await policyRoomEditor.ok.unbanEntity(
PolicyRuleType.User,
entity.toString()
@@ -121,7 +123,7 @@ async function unban(
if (isError(policyRoomUnban)) {
return policyRoomUnban;
}
if (typeof entity === "string" || entity instanceof UserID) {
if (typeof entity === "string" || entity instanceof MatrixUserID) {
const rawEnttiy = typeof entity === "string" ? entity : entity.toString();
const isGlob = (string: string) =>
string.includes("*") ? true : string.includes("?");
@@ -154,7 +156,7 @@ defineInterfaceCommand({
{
name: "entity",
acceptor: union(
findPresentationType("UserID"),
findPresentationType("MatrixUserID"),
findPresentationType("MatrixRoomReference"),
findPresentationType("string")
),
+1 -1
View File
@@ -22,11 +22,11 @@ import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer";
import { defineMatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor";
import {
ActionResult,
MatrixRoomReference,
PropagationType,
isError,
} from "matrix-protection-suite";
import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk";
import { MatrixRoomReference } from "@the-draupnir-project/matrix-basic-types";
defineInterfaceCommand({
table: "draupnir",
@@ -10,12 +10,14 @@
import {
MatrixEventReference,
MatrixRoomReference,
MatrixUserID,
Permalinks,
UserID,
isError,
isStringRoomAlias,
isStringRoomID,
} from "matrix-protection-suite";
isStringUserID,
} from "@the-draupnir-project/matrix-basic-types";
import { isError } from "matrix-protection-suite";
export interface SuperCoolStream<Item, Sequence> {
readonly source: Sequence;
peekItem<EOF = undefined>(eof?: EOF): Item | EOF;
@@ -189,7 +191,7 @@ const WORD_DISPATCH_CHARACTERS = new Map<string, ReadMacro>();
export type ReadItem =
| string
| MatrixRoomReference
| UserID
| MatrixUserID
| Keyword
| MatrixEventReference;
@@ -292,7 +294,7 @@ defineReadItem("!", readRoomIDOrAlias);
/**
* Read the word as a UserID, otherwise return a string if what has been read doesn not represent a user.
*/
defineReadItem("@", (stream: StringStream): UserID | string => {
defineReadItem("@", (stream: StringStream): MatrixUserID | string => {
const word: string[] = [stream.readChar()];
readUntil(/[:\s]/, stream, word);
if (
@@ -302,7 +304,11 @@ defineReadItem("@", (stream: StringStream): UserID | string => {
return word.join("");
}
readUntil(/\s/, stream, word);
return new UserID(word.join(""));
const protoUserID = word.join("");
if (!isStringUserID(protoUserID)) {
return protoUserID;
}
return new MatrixUserID(protoUserID);
});
/**
@@ -353,7 +359,7 @@ definePostReadReplace(/^https:\/\/matrix\.to/, (input) => {
return eventResult.ok;
}
} else if (url.userID !== undefined) {
return new UserID(url.userID);
return new MatrixUserID(url.userID);
} else {
const roomResult = MatrixRoomReference.fromPermalink(input);
if (isError(roomResult)) {
@@ -2,7 +2,10 @@
//
// SPDX-License-Identifier: Apache-2.0
import { MatrixRoomAlias, MatrixRoomID } from "matrix-protection-suite";
import {
MatrixRoomID,
MatrixRoomAlias,
} from "@the-draupnir-project/matrix-basic-types";
import { DocumentNode } from "./DeadDocument";
import {
PresentationType,
@@ -27,10 +27,8 @@ import {
ActionException,
ActionExceptionKind,
ActionResult,
MatrixRoomReference,
Ok,
RoomEvent,
StringRoomID,
Task,
isError,
isOk,
@@ -41,6 +39,10 @@ import {
renderExceptionTrail,
} from "../../capabilities/CommonRenderers";
import { printReadably } from "./PrintReadably";
import {
MatrixRoomReference,
StringRoomID,
} from "@the-draupnir-project/matrix-basic-types";
function requiredArgument(argumentName: string): string {
return `<${argumentName}>`;
@@ -31,12 +31,12 @@ import {
ClientPlatform,
ResultError,
RoomEvent,
StringRoomID,
Task,
isError,
} from "matrix-protection-suite";
import { MatrixReactionHandler } from "./MatrixReactionHandler";
import { PromptRequiredError } from "./PromptRequiredError";
import { StringRoomID } from "@the-draupnir-project/matrix-basic-types";
export interface MatrixContext {
reactionHandler: MatrixReactionHandler;
@@ -17,14 +17,14 @@ import {
MatrixRoomAlias,
MatrixRoomID,
MatrixRoomReference,
UserID,
} from "matrix-protection-suite";
MatrixUserID,
} from "@the-draupnir-project/matrix-basic-types";
makePresentationType({
name: "UserID",
name: "MatrixUserID",
validator: simpleTypeValidator(
"UserID",
(item: ReadItem) => item instanceof UserID
"MatrixUserID",
(item: ReadItem) => item instanceof MatrixUserID
),
});
@@ -64,8 +64,8 @@ makePresentationType({
// Wouldn't this be better as a custom document node so that we could render the plain text version differently?
definePresentationRenderer(
findPresentationType("UserID"),
function (presentation: UserID): DocumentNode {
findPresentationType("MatrixUserID"),
function (presentation: MatrixUserID): DocumentNode {
return (
<a href={`https://matrix.to/#/${presentation.toString()}`}>
{presentation.toString()}
@@ -6,7 +6,6 @@ import {
ClientPlatform,
Logger,
RoomEvent,
StringRoomID,
Task,
Value,
isError,
@@ -28,6 +27,7 @@ import { StaticDecode, Type } from "@sinclair/typebox";
import { ReadItem, readCommand } from "./CommandReader";
import { printReadably } from "./PrintReadably";
import { DeadDocumentPresentationMirror } from "./DeadDocumentPresentation";
import { StringRoomID } from "@the-draupnir-project/matrix-basic-types";
const log = new Logger("MatrixPromptForAccept");
@@ -10,13 +10,15 @@ import {
Logger,
ReactionEvent,
RoomEvent,
StringEventID,
StringRoomID,
StringUserID,
Task,
Value,
isError,
} from "matrix-protection-suite";
import {
StringRoomID,
StringUserID,
StringEventID,
} from "@the-draupnir-project/matrix-basic-types";
const log = new Logger("MatrixReactionHandler");
@@ -3,19 +3,19 @@
// SPDX-License-Identifier: AFL-3.0
import {
MatrixRoomID,
MatrixRoomAlias,
MatrixEventViaAlias,
MatrixEventViaRoomID,
MatrixRoomAlias,
MatrixRoomID,
Permalinks,
UserID,
} from "matrix-protection-suite";
MatrixUserID,
} from "@the-draupnir-project/matrix-basic-types";
import { ReadItem } from "./CommandReader";
export function printReadably(item: ReadItem): string {
if (item instanceof MatrixRoomID || item instanceof MatrixRoomAlias) {
return item.toPermalink();
} else if (item instanceof UserID) {
} else if (item instanceof MatrixUserID) {
return item.toString();
} else if (
item instanceof MatrixEventViaAlias ||
+4 -2
View File
@@ -5,9 +5,7 @@
import {
ActionResult,
ClientsInRoomMap,
MatrixRoomID,
StandardLoggableConfigTracker,
StringUserID,
isError,
} from "matrix-protection-suite";
import { Draupnir } from "../Draupnir";
@@ -19,6 +17,10 @@ import {
} from "matrix-protection-suite-for-matrix-bot-sdk";
import { IConfig } from "../config";
import { makeProtectedRoomsSet } from "./DraupnirProtectedRoomsSet";
import {
StringUserID,
MatrixRoomID,
} from "@the-draupnir-project/matrix-basic-types";
export class DraupnirFactory {
public constructor(
@@ -15,7 +15,6 @@ import {
Logger,
MJOLNIR_PROTECTED_ROOMS_EVENT_TYPE,
MJOLNIR_WATCHED_POLICY_ROOMS_EVENT_TYPE,
MatrixRoomID,
MissingProtectionCB,
MjolnirEnabledProtectionsEvent,
MjolnirEnabledProtectionsEventType,
@@ -40,7 +39,6 @@ import {
StandardProtectionsManager,
StandardSetMembership,
StandardSetRoomState,
StringUserID,
isError,
} from "matrix-protection-suite";
import {
@@ -53,6 +51,10 @@ import "../protections/DraupnirProtectionsIndex";
import { IConfig } from "../config";
import { runProtectionConfigHooks } from "../protections/ConfigHooks";
import { makeHandleMissingProtectionPermissions } from "../protections/MissingProtectionPermissions";
import {
MatrixRoomID,
StringUserID,
} from "@the-draupnir-project/matrix-basic-types";
const log = new Logger("DraupnirProtectedRoomsSet");
@@ -11,14 +11,16 @@
import {
ActionError,
ActionResult,
MatrixRoomID,
StringUserID,
Task,
isError,
} from "matrix-protection-suite";
import { IConfig } from "../config";
import { DraupnirFactory } from "./DraupnirFactory";
import { Draupnir } from "../Draupnir";
import {
StringUserID,
MatrixRoomID,
} from "@the-draupnir-project/matrix-basic-types";
export class StandardDraupnirManager {
private readonly readyDraupnirs = new Map<StringUserID, Draupnir>();
+1 -1
View File
@@ -8,6 +8,7 @@
// https://github.com/matrix-org/mjolnir
// </text>
import { StringRoomID } from "@the-draupnir-project/matrix-basic-types";
import { DocumentNode } from "../commands/interface-manager/DeadDocument";
import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix";
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
@@ -17,7 +18,6 @@ import {
ActionResult,
Ok,
RoomUpdateError,
StringRoomID,
} from "matrix-protection-suite";
import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
+8 -6
View File
@@ -20,8 +20,6 @@ import {
AbstractProtection,
ActionResult,
Logger,
MatrixRoomID,
MatrixRoomReference,
MembershipChange,
MembershipChangeType,
Ok,
@@ -34,12 +32,9 @@ import {
RoomActionError,
RoomMembershipRevision,
RoomUpdateError,
StringRoomID,
StringUserID,
Task,
describeProtection,
isError,
serverName,
UnknownSettings,
UserConsequences,
Membership,
@@ -49,6 +44,13 @@ import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot
import { DraupnirProtection } from "./Protection";
import { listInfo } from "../commands/StatusCommand";
import { MatrixReactionHandler } from "../commands/interface-manager/MatrixReactionHandler";
import {
MatrixRoomID,
StringRoomID,
MatrixRoomReference,
StringUserID,
userServerName,
} from "@the-draupnir-project/matrix-basic-types";
const log = new Logger("BanPropagationProtection");
@@ -410,7 +412,7 @@ export class BanPropagationProtection
);
if (editablePolicyRoom === undefined) {
const roomID = MatrixRoomReference.fromRoomID(roomIDWithPolicy, [
serverName(this.draupnir.clientUserID),
userServerName(this.draupnir.clientUserID),
]);
errors.push(
new PermissionError(
+6 -4
View File
@@ -8,6 +8,12 @@
// https://github.com/matrix-org/mjolnir
// </text>
import {
StringEventID,
StringUserID,
StringRoomID,
MatrixRoomID,
} from "@the-draupnir-project/matrix-basic-types";
import { Draupnir } from "../Draupnir";
import { DraupnirProtection } from "./Protection";
import { LogLevel } from "matrix-bot-sdk";
@@ -16,16 +22,12 @@ import {
ActionResult,
EventConsequences,
Logger,
MatrixRoomID,
Ok,
ProtectedRoomsSet,
ProtectionDescription,
RoomEvent,
SafeIntegerProtectionSetting,
StandardProtectionSettings,
StringEventID,
StringRoomID,
StringUserID,
UserConsequences,
describeProtection,
isError,
+6 -5
View File
@@ -13,7 +13,6 @@ import {
AbstractProtection,
ActionResult,
EventConsequences,
MatrixRoomID,
MembershipChange,
MembershipChangeType,
Ok,
@@ -23,13 +22,16 @@ import {
RoomEvent,
RoomMembershipRevision,
RoomMessage,
StringRoomID,
StringUserID,
UserConsequences,
Value,
describeProtection,
} from "matrix-protection-suite";
import { Draupnir } from "../Draupnir";
import {
MatrixRoomID,
StringRoomID,
StringUserID,
} from "@the-draupnir-project/matrix-basic-types";
type FirstMessageIsImageProtectionSettings = Record<never, never>;
@@ -83,8 +85,7 @@ export class FirstMessageIsImageProtection
extends AbstractProtection<FirstMessageIsImageProtectionDescription>
implements Protection<FirstMessageIsImageProtectionDescription>
{
private justJoined: { [roomID: StringRoomID]: StringUserID[] | undefined } =
{};
private justJoined: { [roomID: StringRoomID]: StringUserID[] } = {};
private recentlyBanned: StringUserID[] = [];
private readonly userConsequences: UserConsequences;
+1 -1
View File
@@ -21,13 +21,13 @@ import {
RoomMembershipRevision,
SafeIntegerProtectionSetting,
StandardProtectionSettings,
StringRoomID,
describeProtection,
isError,
} from "matrix-protection-suite";
import { LogLevel } from "matrix-bot-sdk";
import { Draupnir } from "../Draupnir";
import { DraupnirProtection } from "./Protection";
import { StringRoomID } from "@the-draupnir-project/matrix-basic-types";
const log = new Logger("JoinWaveShortCircuitProtection");
+6 -4
View File
@@ -13,9 +13,7 @@ import {
AbstractProtection,
ActionResult,
EventConsequences,
MatrixRoomID,
Ok,
Permalinks,
ProtectedRoomsSet,
Protection,
ProtectionDescription,
@@ -23,9 +21,13 @@ import {
RoomMessage,
Value,
describeProtection,
serverName,
} from "matrix-protection-suite";
import { Draupnir } from "../Draupnir";
import {
MatrixRoomID,
Permalinks,
userServerName,
} from "@the-draupnir-project/matrix-basic-types";
type MessageIsMediaProtectionSettings = Record<never, never>;
@@ -108,7 +110,7 @@ export class MessageIsMediaProtection
await this.draupnir.managementRoomOutput.logMessage(
LogLevel.WARN,
"MessageIsMedia",
`Redacting event from ${event["sender"]} for posting an image/video. ${Permalinks.forEvent(roomID, event["event_id"], [serverName(this.draupnir.clientUserID)])}`
`Redacting event from ${event["sender"]} for posting an image/video. ${Permalinks.forEvent(roomID, event["event_id"], [userServerName(this.draupnir.clientUserID)])}`
);
// Redact the event
if (this.draupnir.config.noop) {
+6 -4
View File
@@ -14,9 +14,7 @@ import {
ActionResult,
CapabilitySet,
EventConsequences,
MatrixRoomID,
Ok,
Permalinks,
ProtectedRoomsSet,
Protection,
ProtectionDescription,
@@ -24,9 +22,13 @@ import {
RoomMessage,
Value,
describeProtection,
serverName,
} from "matrix-protection-suite";
import { Draupnir } from "../Draupnir";
import {
MatrixRoomID,
Permalinks,
userServerName,
} from "@the-draupnir-project/matrix-basic-types";
type MessageIsVoiceCapabilities = {
eventConsequences: EventConsequences;
@@ -100,7 +102,7 @@ export class MessageIsVoiceProtection
await this.draupnir.managementRoomOutput.logMessage(
LogLevel.INFO,
"MessageIsVoice",
`Redacting event from ${event["sender"]} for posting a voice message. ${Permalinks.forEvent(roomID, event["event_id"], [serverName(this.draupnir.clientUserID)])}`
`Redacting event from ${event["sender"]} for posting a voice message. ${Permalinks.forEvent(roomID, event["event_id"], [userServerName(this.draupnir.clientUserID)])}`
);
// Redact the event
if (!this.draupnir.config.noop) {
@@ -4,9 +4,7 @@
import {
HandleMissingProtectionPermissions,
MatrixRoomReference,
ProtectionPermissionsChange,
StringRoomID,
Task,
} from "matrix-protection-suite";
import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix";
@@ -14,6 +12,10 @@ import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
import { DocumentNode } from "../commands/interface-manager/DeadDocument";
import { renderRoomPill } from "../commands/interface-manager/MatrixHelpRenderer";
import {
StringRoomID,
MatrixRoomReference,
} from "@the-draupnir-project/matrix-basic-types";
function renderPermissions(
title: DocumentNode,
+2 -2
View File
@@ -18,10 +18,10 @@ import {
UserConsequences,
describeProtection,
isError,
serverName,
} from "matrix-protection-suite";
import { Draupnir } from "../Draupnir";
import { IConfig } from "../config";
import { userServerName } from "@the-draupnir-project/matrix-basic-types";
export type NewJoinerProtectionDescription = ProtectionDescription<
unknown,
@@ -57,7 +57,7 @@ export class NewJoinerProtection
const errors: ActionError[] = [];
for (const change of changes) {
if (change.membershipChangeType === MembershipChangeType.Joined) {
if (this.bannedServers.has(serverName(change.userID))) {
if (this.bannedServers.has(userServerName(change.userID))) {
const banResult =
await this.userConsequences.consequenceForUserInRoom(
revision.room.toRoomIDOrAlias(),
+4 -2
View File
@@ -12,7 +12,6 @@ import {
AbstractProtection,
ActionResult,
Logger,
MatrixRoomReference,
Ok,
PolicyListRevision,
PolicyRoomManager,
@@ -20,7 +19,6 @@ import {
PolicyRuleChange,
ProtectedRoomsSet,
ProtectionDescription,
StringRoomID,
UnknownSettings,
describeProtection,
isError,
@@ -34,6 +32,10 @@ import {
renderRoomPill,
} from "../commands/interface-manager/MatrixHelpRenderer";
import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix";
import {
StringRoomID,
MatrixRoomReference,
} from "@the-draupnir-project/matrix-basic-types";
const log = new Logger("PolicyChangeNotification");
@@ -8,14 +8,11 @@
// https://github.com/matrix-org/mjolnir
// </text>
import {
ActionError,
ProtectionDescription,
StringRoomID,
} from "matrix-protection-suite";
import { ActionError, ProtectionDescription } from "matrix-protection-suite";
import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix";
import { DeadDocumentJSX } from "../commands/interface-manager/JSXFactory";
import { StringRoomID } from "@the-draupnir-project/matrix-basic-types";
export async function renderProtectionFailedToStart(
client: MatrixSendClient,
+5 -3
View File
@@ -11,7 +11,6 @@ import {
AbstractProtection,
ActionResult,
CapabilitySet,
MatrixGlob,
MembershipChange,
MembershipChangeType,
Ok,
@@ -26,13 +25,16 @@ import {
Recommendation,
RoomMembershipRevision,
SimpleChangeType,
StringRoomID,
StringUserID,
Task,
describeProtection,
} from "matrix-protection-suite";
import { Draupnir } from "../Draupnir";
import { redactUserMessagesIn } from "../utils";
import {
MatrixGlob,
StringRoomID,
StringUserID,
} from "@the-draupnir-project/matrix-basic-types";
type RedactionSynchronisationProtectionDescription =
ProtectionDescription<Draupnir>;
+4 -2
View File
@@ -19,14 +19,16 @@ import {
ProtectionDescription,
SafeIntegerProtectionSetting,
StandardProtectionSettings,
StringEventID,
StringUserID,
StringUserIDSetProtectionSettings,
UserConsequences,
describeProtection,
isError,
} from "matrix-protection-suite";
import { Draupnir } from "../Draupnir";
import {
StringUserID,
StringEventID,
} from "@the-draupnir-project/matrix-basic-types";
const MAX_REPORTED_EVENT_BACKLOG = 20;
+5 -3
View File
@@ -13,7 +13,6 @@ import {
ActionResult,
EventConsequences,
Logger,
MatrixRoomID,
MembershipChange,
MembershipChangeType,
Ok,
@@ -23,13 +22,16 @@ import {
RoomEvent,
RoomMembershipRevision,
RoomMessage,
StringRoomID,
StringUserID,
UserConsequences,
Value,
describeProtection,
} from "matrix-protection-suite";
import { Draupnir } from "../Draupnir";
import {
StringUserID,
StringRoomID,
MatrixRoomID,
} from "@the-draupnir-project/matrix-basic-types";
const log = new Logger("WordList");
@@ -12,17 +12,14 @@ import {
AbstractProtection,
ActionError,
ActionResult,
MatrixRoomReference,
MembershipEvent,
Ok,
ProtectedRoomsSet,
ProtectionDescription,
StandardDeduplicator,
StringRoomID,
Task,
describeProtection,
isError,
serverName,
} from "matrix-protection-suite";
import { Draupnir } from "../../Draupnir";
import { DraupnirProtection } from "../Protection";
@@ -37,6 +34,11 @@ import {
import { renderFailedSingularConsequence } from "../../capabilities/CommonRenderers";
import { ProtectroomsOnInvite } from "./ProtectRoomsOnInvite";
import { WatchRoomsOnInvite } from "./WatchRoomsOnInvite";
import {
StringRoomID,
MatrixRoomReference,
userServerName,
} from "@the-draupnir-project/matrix-basic-types";
export type JoinRoomsOnInviteProtectionCapabilities = Record<string, never>;
export type JoinRoomsOnInviteProtectionSettings = Record<string, unknown>;
@@ -165,8 +167,8 @@ export class JoinRoomsOnInviteProtection
event: MembershipEvent
): Promise<ActionResult<void>> {
const invitedRoomReference = MatrixRoomReference.fromRoomID(event.room_id, [
serverName(event.sender),
serverName(event.state_key),
userServerName(event.sender),
userServerName(event.state_key),
]);
const joinResult = await this.joinInvitedRoom(event, invitedRoomReference);
if (isError(joinResult)) {
@@ -10,15 +10,14 @@
import {
Logger,
MatrixRoomID,
MembershipEvent,
Ok,
Permalink,
ProtectedRoomsSet,
RoomEvent,
Task,
Value,
isError,
PermalinkSchema,
} from "matrix-protection-suite";
import { DocumentNode } from "../../commands/interface-manager/DeadDocument";
import {
@@ -30,6 +29,7 @@ import { DeadDocumentJSX } from "../../commands/interface-manager/JSXFactory";
import { renderMatrixAndSend } from "../../commands/interface-manager/DeadDocumentMatrix";
import { StaticDecode, Type } from "@sinclair/typebox";
import { Draupnir } from "../../Draupnir";
import { MatrixRoomID } from "@the-draupnir-project/matrix-basic-types";
const log = new Logger("ProtectRoomsOnInvite");
@@ -38,7 +38,7 @@ const PROTECT_ROOMS_ON_INVITE_PROMPT_LISTENER =
// would be nice to be able to use presentation types here idk.
const ProtectRoomsOnInvitePromptContext = Type.Object({
invited_room: Permalink,
invited_room: PermalinkSchema,
});
// this rule is stupid.
@@ -12,10 +12,9 @@ import {
ALL_RULE_TYPES,
Logger,
MJOLNIR_SHORTCODE_EVENT_TYPE,
MatrixRoomID,
MembershipEvent,
Ok,
Permalink,
PermalinkSchema,
PropagationType,
ProtectedRoomsSet,
RoomEvent,
@@ -34,6 +33,7 @@ import {
} from "../../commands/interface-manager/MatrixHelpRenderer";
import { renderMatrixAndSend } from "../../commands/interface-manager/DeadDocumentMatrix";
import { StaticDecode, Type } from "@sinclair/typebox";
import { MatrixRoomID } from "@the-draupnir-project/matrix-basic-types";
const log = new Logger("WatchRoomsOnInvite");
@@ -42,7 +42,7 @@ const WATCH_LISTS_ON_INVITE_PROMPT_LISTENER =
// would be nice to be able to use presentation types here idk.
const WatchRoomsOnInvitePromptContext = Type.Object({
invited_room: Permalink,
invited_room: PermalinkSchema,
});
// this rule is stupid.
+1 -1
View File
@@ -2,11 +2,11 @@
//
// SPDX-License-Identifier: AFL-3.0
import { StringUserID } from "@the-draupnir-project/matrix-basic-types";
import {
Membership,
MembershipEvent,
RoomMembershipRevision,
StringUserID,
} from "matrix-protection-suite";
export function isInvitationForUser(
+4 -2
View File
@@ -14,12 +14,14 @@ import ManagementRoomOutput from "../ManagementRoomOutput";
import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
import {
ActionExceptionKind,
MatrixRoomReference,
RoomUpdateError,
RoomUpdateException,
} from "matrix-protection-suite";
import {
StringRoomID,
StringUserID,
} from "matrix-protection-suite";
MatrixRoomReference,
} from "@the-draupnir-project/matrix-basic-types";
export interface QueuedRedaction {
/** The room which the redaction will take place in. */
+2 -1
View File
@@ -8,7 +8,8 @@
// https://github.com/matrix-org/mjolnir
// </text>
import { RoomEvent, StringRoomID } from "matrix-protection-suite";
import { StringRoomID } from "@the-draupnir-project/matrix-basic-types";
import { RoomEvent } from "matrix-protection-suite";
/**
* Used to keep track of protected rooms so they are always ordered for activity.
+6 -6
View File
@@ -8,13 +8,13 @@
// https://github.com/matrix-org/mjolnir
// </text>
import { LogLevel, LogService } from "matrix-bot-sdk";
import {
Permalinks,
RoomEvent,
StringRoomID,
StringUserID,
} from "matrix-protection-suite";
import { RoomEvent } from "matrix-protection-suite";
import { Draupnir } from "../Draupnir";
import {
StringUserID,
StringRoomID,
Permalinks,
} from "@the-draupnir-project/matrix-basic-types";
/**
* A queue of users who have been flagged for redaction typically by the flooding or image protection.
+8 -6
View File
@@ -15,19 +15,21 @@ import { htmlEscape } from "../utils";
import { JSDOM } from "jsdom";
import { Draupnir } from "../Draupnir";
import {
MatrixRoomReference,
ReactionContent,
RoomEvent,
RoomMessage,
StringEventID,
StringRoomID,
StringUserID,
Task,
TextMessageContent,
Value,
isError,
serverName,
} from "matrix-protection-suite";
import {
StringRoomID,
StringUserID,
StringEventID,
MatrixRoomReference,
userServerName,
} from "@the-draupnir-project/matrix-basic-types";
/// Regexp, used to extract the action label from an action reaction
/// such as `⚽ Kick user @foobar:localhost from room [kick-user]`.
@@ -967,7 +969,7 @@ class DisplayManager {
const roomID = event["room_id"];
const room = MatrixRoomReference.fromRoomID(roomID, [
serverName(this.owner.draupnir.clientUserID),
userServerName(this.owner.draupnir.clientUserID),
]);
const eventId = event["event_id"];
const MAX_EVENT_CONTENT_LENGTH = 2048;
+5 -1
View File
@@ -13,7 +13,11 @@ import express from "express";
import { MatrixClient } from "matrix-bot-sdk";
import { ReportManager } from "../report/ReportManager";
import { IConfig } from "../config";
import { StringEventID, StringRoomID, Task } from "matrix-protection-suite";
import {
StringRoomID,
StringEventID,
} from "@the-draupnir-project/matrix-basic-types";
import { Task } from "matrix-protection-suite";
/**
* A common prefix for all web-exposed APIs.
+7 -3
View File
@@ -7,7 +7,11 @@ import {
Keyword,
readCommand,
} from "../../src/commands/interface-manager/CommandReader";
import { MatrixRoomAlias, MatrixRoomID, UserID } from "matrix-protection-suite";
import {
MatrixRoomAlias,
MatrixRoomID,
MatrixUserID,
} from "@the-draupnir-project/matrix-basic-types";
describe("Can read", function () {
it("Can read a simple command with only strings", function () {
@@ -56,8 +60,8 @@ describe("Can read", function () {
it("Can parse userID's", function () {
const command = "@spam:example.com";
const readItems = readCommand(command);
expect(readItems.at(0)).toBeInstanceOf(UserID);
const user = readItems.at(0) as UserID;
expect(readItems.at(0)).toBeInstanceOf(MatrixUserID);
const user = readItems.at(0) as MatrixUserID;
expect(user.localpart).toBe("spam");
});
});
+2 -2
View File
@@ -17,7 +17,7 @@ import {
import { readCommand } from "../../src/commands/interface-manager/CommandReader";
import "../../src/commands/interface-manager/MatrixPresentations";
it("A command that fookin parses mxids", async function () {
it("A command that parses mxids", async function () {
const tableName = Symbol("ParseTest");
defineCommandTable(tableName);
defineInterfaceCommand({
@@ -28,7 +28,7 @@ it("A command that fookin parses mxids", async function () {
{
name: "entity",
acceptor: union(
findPresentationType("UserID"),
findPresentationType("MatrixUserID"),
findPresentationType("MatrixRoomReference"),
findPresentationType("string")
),
+1 -1
View File
@@ -17,9 +17,9 @@ import {
ReactionContent,
ReactionEvent,
RoomMessage,
StringEventID,
Value,
} from "matrix-protection-suite";
import { StringEventID } from "@the-draupnir-project/matrix-basic-types";
/**
* Test the ability to turn abuse reports into room messages.
+4 -2
View File
@@ -7,15 +7,17 @@ import { newTestUser } from "./clientHelper";
import { getFirstEventMatching } from "./commands/commandUtils";
import { DraupnirTestContext, draupnirClient } from "./mjolnirSetupUtils";
import {
MatrixRoomReference,
NoticeMessageContent,
PolicyRuleType,
PropagationType,
RoomMessage,
StringRoomID,
Value,
findProtection,
} from "matrix-protection-suite";
import {
MatrixRoomReference,
StringRoomID,
} from "@the-draupnir-project/matrix-basic-types";
// We will need to disable this in tests that are banning people otherwise it will cause
// mocha to hang for awhile until it times out waiting for a response to a prompt.
+2 -2
View File
@@ -16,9 +16,9 @@ import {
NoticeMessageContent,
ReactionEvent,
RoomEvent,
StringEventID,
TextMessageContent,
Value,
StringEventIDSchema,
} from "matrix-protection-suite";
import { Type } from "@sinclair/typebox";
@@ -26,7 +26,7 @@ export const ReplyContent = Type.Intersect([
Type.Object({
"m.relates_to": Type.Object({
"m.in_reply_to": Type.Object({
event_id: StringEventID,
event_id: StringEventIDSchema,
}),
}),
}),
+1 -1
View File
@@ -9,7 +9,6 @@
// </text>
import {
MatrixRoomReference,
MJOLNIR_PROTECTED_ROOMS_EVENT_TYPE,
MJOLNIR_WATCHED_POLICY_ROOMS_EVENT_TYPE,
} from "matrix-protection-suite";
@@ -22,6 +21,7 @@ import {
makeMjolnir,
teardownManagementRoom,
} from "./mjolnirSetupUtils";
import { MatrixRoomReference } from "@the-draupnir-project/matrix-basic-types";
patchMatrixClient();
+4 -2
View File
@@ -13,14 +13,16 @@ import { newTestUser } from "./clientHelper";
import { DraupnirTestContext } from "./mjolnirSetupUtils";
import {
ActionResult,
MatrixRoomReference,
Ok,
Protection,
ProtectionDescription,
StandardProtectionSettings,
StringRoomID,
Task,
} from "matrix-protection-suite";
import {
MatrixRoomReference,
StringRoomID,
} from "@the-draupnir-project/matrix-basic-types";
describe("Test: Report polling", function () {
let client: MatrixClient;
+22 -8
View File
@@ -93,6 +93,11 @@
resolved "https://registry.yarnpkg.com/@eslint/object-schema/-/object-schema-2.1.4.tgz#9e69f8bb4031e11df79e03db09f9dbbae1740843"
integrity sha512-BsWiH1yFGjXXS2yvrf5LyuoSIIbPrGUWob917o+BTKuZ7qJdxX8aJLRxs1fS9n6r7vESrq1OUqb68dANcFXuQQ==
"@gnuxie/typescript-result@^0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@gnuxie/typescript-result/-/typescript-result-0.2.0.tgz#870e29d079341c32a7cae7e0ee77ffdd09aad60f"
integrity sha512-V5VZUpl21fRNTBHqdigWVkkXhoue/6MVfpWLBOMVgi5unR4ePoXjzNXc9diNmnmDe+mrQfXGPT8LiB18Cc+0Ig==
"@humanwhocodes/module-importer@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz#af5b2691a22b44be847b0ca81641c5fb6ad0172c"
@@ -221,6 +226,14 @@
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e"
integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==
"@the-draupnir-project/matrix-basic-types@^0.1.1":
version "0.1.1"
resolved "https://registry.yarnpkg.com/@the-draupnir-project/matrix-basic-types/-/matrix-basic-types-0.1.1.tgz#27a131e2f92d6d25b377f7339177d8ac204d95a2"
integrity sha512-g5CDAdQMe1dxbVlzPvrrPPluZCFKaBqJ2iAarspGHkr0V3YBBCdz9v3Yb6TY8e2d/eXz5gSWDKzeZElWD33oeA==
dependencies:
"@gnuxie/typescript-result" "^0.2.0"
glob-to-regexp "^0.4.1"
"@types/better-sqlite3@^7.6.9":
version "7.6.9"
resolved "https://registry.yarnpkg.com/@types/better-sqlite3/-/better-sqlite3-7.6.9.tgz#4bff3eb7c5eaaae26f8099606c69279146561c50"
@@ -2405,16 +2418,17 @@ matrix-appservice@^2.0.0:
request-promise "^4.2.6"
sanitize-html "^2.8.0"
"matrix-protection-suite-for-matrix-bot-sdk@npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@0.23.4":
version "0.23.4"
resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite-for-matrix-bot-sdk/-/matrix-protection-suite-for-matrix-bot-sdk-0.23.4.tgz#7c5bafa045382a4d4c27f1c30a4420a32f05859e"
integrity sha512-P9jIj17aunodVZ7AghszKxR7zH+fLDaWZdWyFnKR9YRLIG5trMBh5rcCKPUpLnhTCe4apSFHyLXDnmb4zZW08w==
"matrix-protection-suite-for-matrix-bot-sdk@npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite-for-matrix-bot-sdk/-/matrix-protection-suite-for-matrix-bot-sdk-1.0.0.tgz#7d303359cd1d2a676c4968b7de4e5d9993405159"
integrity sha512-/vY0TjQEcupFqOZplLMCCwY24XRmkIYOEaYKrQeLmjj1aN1nniXwaLWwCd3aQHBDzcxsw8agRQuy46JcAhTPpw==
"matrix-protection-suite@npm:@gnuxie/matrix-protection-suite@0.23.4":
version "0.23.4"
resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite/-/matrix-protection-suite-0.23.4.tgz#1f4b1089888ad9d512b3eca8c4b9cb4c4111ec58"
integrity sha512-hC2DVGwgZLpYjKtPHCTxqap/8QeZ3W3KyHoic/9oWnlAx0FLaz7WLNGUqtTuFpmU+NWX6H0TmX2szaMHoTTqXw==
"matrix-protection-suite@npm:@gnuxie/matrix-protection-suite@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite/-/matrix-protection-suite-1.0.0.tgz#7e1eb2cd5df818c736d83b217998b77dc9667160"
integrity sha512-XoNRzJnRgU0qgdHhId2IMvrnvaW7jx884DEh/3NssKv0Bmyccbr0DBAq7aNbXWO2T0L88aYyPENYL+j9oZKmuQ==
dependencies:
"@gnuxie/typescript-result" "^0.2.0"
await-lock "^2.2.2"
crypto-js "^4.2.0"
glob-to-regexp "^0.4.1"