mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-04-27 19:35:22 +00:00
Update protections for new consequence provider descriptions
This commit is contained in:
+1
-2
@@ -37,7 +37,7 @@ import { DefaultStateTrackingMeta, ManagerManager, ManagerManagerForMatrixEmitte
|
||||
import { IConfig } from "./config";
|
||||
import { COMMAND_PREFIX, extractCommandFromMessageBody, handleCommand } from "./commands/CommandHandler";
|
||||
import { makeProtectedRoomsSet } from "./DraupnirBotMode";
|
||||
import { makeStandardConsequenceProvider, renderProtectionFailedToStart } from "./StandardConsequenceProvider";
|
||||
import { renderProtectionFailedToStart } from "./StandardConsequenceProvider";
|
||||
import { htmlEscape } from "./utils";
|
||||
import { LogLevel } from "matrix-bot-sdk";
|
||||
|
||||
@@ -130,7 +130,6 @@ export class Draupnir {
|
||||
)
|
||||
);
|
||||
const loadResult = await protectedRoomsSet.protections.loadProtections(
|
||||
makeStandardConsequenceProvider(client, draupnir.managementRoomID),
|
||||
protectedRoomsSet,
|
||||
draupnir,
|
||||
(error, description) => renderProtectionFailedToStart(
|
||||
|
||||
@@ -25,12 +25,13 @@ limitations under the License.
|
||||
* are NOT distributed, contributed, committed, or licensed under the Apache License.
|
||||
*/
|
||||
|
||||
import { ActionError, ActionException, ActionExceptionKind, ActionResult, ConsequenceProvider, Ok, Permalinks, ProtectionDescription, ProtectionDescriptionInfo, RoomUpdateError, RoomUpdateException, SetMemberBanResultMap, StringEventID, StringRoomID, StringUserID, Task, applyPolicyRevisionToSetMembership, isError } from "matrix-protection-suite";
|
||||
import { ActionError, ActionException, ActionExceptionKind, ActionResult, BasicConsequenceProvider, DEFAULT_CONSEQUENCE_PROVIDER, Ok, Permalinks, ProtectionDescription, ProtectionDescriptionInfo, RoomUpdateError, RoomUpdateException, SetMemberBanResultMap, StringEventID, StringRoomID, StringUserID, Task, applyPolicyRevisionToSetMembership, describeConsequenceProvider, isError } from "matrix-protection-suite";
|
||||
import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk";
|
||||
import { renderMatrixAndSend } from "./commands/interface-manager/DeadDocumentMatrix";
|
||||
import { JSXFactory } from "./commands/interface-manager/JSXFactory";
|
||||
import { DocumentNode } from "./commands/interface-manager/DeadDocument";
|
||||
import { printActionResult } from "./models/RoomUpdateError";
|
||||
import { Draupnir } from "./Draupnir";
|
||||
|
||||
interface ProviderContext {
|
||||
client: MatrixSendClient;
|
||||
@@ -49,7 +50,7 @@ async function renderConsequenceForEvent(client: MatrixSendClient, managementRoo
|
||||
return Ok(undefined);
|
||||
}
|
||||
|
||||
const consequenceForEvent: ConsequenceProvider['consequenceForEvent'] = async function(
|
||||
const consequenceForEvent: BasicConsequenceProvider['consequenceForEvent'] = async function(
|
||||
this: ProviderContext, protection, roomID, eventID, reason
|
||||
): Promise<ActionResult<void>> {
|
||||
Task(renderConsequenceForEvent(this.client, this.managementRoomID, protection, roomID, eventID, reason))
|
||||
@@ -86,7 +87,7 @@ function banUser(client: MatrixSendClient, protection: ProtectionDescriptionInfo
|
||||
)
|
||||
}
|
||||
|
||||
const consequenceForUserInRoom: ConsequenceProvider['consequenceForUserInRoom'] = async function(
|
||||
const consequenceForUserInRoom: BasicConsequenceProvider['consequenceForUserInRoom'] = async function(
|
||||
this: ProviderContext, protection, roomID, userID, reason
|
||||
): Promise<ActionResult<void>> {
|
||||
Task(renderConsequenceForUserInRoom(this.client, this.managementRoomID, protection, roomID, userID, reason));
|
||||
@@ -109,7 +110,7 @@ function renderSetMembershipBans(title: DocumentNode, map: SetMemberBanResultMap
|
||||
</fragment>
|
||||
}
|
||||
|
||||
const consequenceForUsersInRevision: ConsequenceProvider['consequenceForUsersInRevision'] = async function(
|
||||
const consequenceForUsersInRevision: BasicConsequenceProvider['consequenceForUsersInRevision'] = async function(
|
||||
this: ProviderContext, description, setMembership, revision
|
||||
) {
|
||||
const results = await applyPolicyRevisionToSetMembership(
|
||||
@@ -130,14 +131,14 @@ const consequenceForUsersInRevision: ConsequenceProvider['consequenceForUsersInR
|
||||
return Ok(undefined);
|
||||
}
|
||||
|
||||
const consequenceForServerACL: ConsequenceProvider['consequenceForServerACL'] = async function(
|
||||
const consequenceForServerACL: BasicConsequenceProvider['consequenceForServerACL'] = async function(
|
||||
this: ProviderContext, aclContent
|
||||
): Promise<ActionResult<void>> {
|
||||
// nothing to do
|
||||
return Ok(undefined)
|
||||
}
|
||||
|
||||
const consequenceForServerACLInRoom: ConsequenceProvider['consequenceForServerACLInRoom'] = async function(
|
||||
const consequenceForServerACLInRoom: BasicConsequenceProvider['consequenceForServerACLInRoom'] = async function(
|
||||
this: ProviderContext, _protection, roomID, aclContent
|
||||
): Promise<ActionResult<void>> {
|
||||
return this.client.sendStateEvent(roomID, 'm.room.server_acl', '', aclContent).then(
|
||||
@@ -149,12 +150,12 @@ const consequenceForServerACLInRoom: ConsequenceProvider['consequenceForServerAC
|
||||
)
|
||||
}
|
||||
|
||||
const consequenceForServerInRoom: ConsequenceProvider['consequenceForServerInRoom'] = async function(
|
||||
const consequenceForServerInRoom: BasicConsequenceProvider['consequenceForServerInRoom'] = async function(
|
||||
) {
|
||||
return Ok(undefined);
|
||||
}
|
||||
|
||||
const unbanUserFromRoomsInSet: ConsequenceProvider['unbanUserFromRoomsInSet'] = async function(
|
||||
const unbanUserFromRoomsInSet: BasicConsequenceProvider['unbanUserFromRoomsInSet'] = async function(
|
||||
this: ProviderContext, _protection, userID, protectedRoomsSet
|
||||
): Promise<ActionResult<void>> {
|
||||
const errors: RoomUpdateError[] = [];
|
||||
@@ -181,10 +182,10 @@ const unbanUserFromRoomsInSet: ConsequenceProvider['unbanUserFromRoomsInSet'] =
|
||||
return Ok(undefined);
|
||||
}
|
||||
|
||||
export function makeStandardConsequenceProvider(
|
||||
export function makeStandardBasicConsequenceProvider(
|
||||
client: MatrixSendClient,
|
||||
managementRoomID: StringRoomID
|
||||
): ConsequenceProvider {
|
||||
): BasicConsequenceProvider {
|
||||
return {
|
||||
consequenceForEvent,
|
||||
consequenceForServerACL,
|
||||
@@ -195,9 +196,20 @@ export function makeStandardConsequenceProvider(
|
||||
unbanUserFromRoomsInSet,
|
||||
client,
|
||||
managementRoomID
|
||||
} as unknown as ConsequenceProvider;
|
||||
} as unknown as BasicConsequenceProvider;
|
||||
}
|
||||
|
||||
describeConsequenceProvider<Draupnir>({
|
||||
name: DEFAULT_CONSEQUENCE_PROVIDER,
|
||||
description: 'Does what it says on the tin',
|
||||
factory: function(draupnir) {
|
||||
return makeStandardBasicConsequenceProvider(
|
||||
draupnir.client,
|
||||
draupnir.managementRoomID
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
export async function renderProtectionFailedToStart(
|
||||
client: MatrixSendClient,
|
||||
managementRoomID: StringRoomID,
|
||||
|
||||
@@ -34,7 +34,7 @@ import { renderMentionPill } from "../commands/interface-manager/MatrixHelpRende
|
||||
import { UserID } from "matrix-bot-sdk";
|
||||
import { renderListRules } from "../commands/Rules";
|
||||
import { printActionResult } from "../models/RoomUpdateError";
|
||||
import { AbstractProtection, ActionResult, ConsequenceProvider, Logger, MatrixRoomID, MatrixRoomReference, MembershipChange, MembershipChangeType, Ok, PermissionError, PolicyRule, PolicyRuleType, ProtectedRoomsSet, ProtectionDescription, Recommendation, RoomActionError, RoomMembershipRevision, RoomUpdateError, StringRoomID, StringUserID, Task, describeProtection, isError, serverName } from "matrix-protection-suite";
|
||||
import { AbstractProtection, ActionResult, BasicConsequenceProvider, ConsequenceProvider, Logger, MatrixRoomID, MatrixRoomReference, MembershipChange, MembershipChangeType, Ok, PermissionError, PolicyRule, PolicyRuleType, ProtectedRoomsSet, ProtectionDescription, Recommendation, RoomActionError, RoomMembershipRevision, RoomUpdateError, StringRoomID, StringUserID, Task, describeProtection, isError, serverName } from "matrix-protection-suite";
|
||||
import { Draupnir } from "../Draupnir";
|
||||
import { resolveRoomReferenceSafe } from "matrix-protection-suite-for-matrix-bot-sdk";
|
||||
import { DraupnirProtection } from "./Protection";
|
||||
@@ -138,7 +138,7 @@ export class BanPropagationProtection extends AbstractProtection implements Drau
|
||||
|
||||
constructor(
|
||||
description: ProtectionDescription,
|
||||
consequenceProvider: ConsequenceProvider,
|
||||
consequenceProvider: BasicConsequenceProvider,
|
||||
protectedRoomsSet: ProtectedRoomsSet,
|
||||
private readonly draupnir: Draupnir,
|
||||
) {
|
||||
|
||||
@@ -28,7 +28,7 @@ limitations under the License.
|
||||
import { Draupnir } from "../Draupnir";
|
||||
import { DraupnirProtection } from "./Protection";
|
||||
import { LogLevel } from "matrix-bot-sdk";
|
||||
import { AbstractProtection, ActionResult, ConsequenceProvider, Logger, MatrixRoomID, Ok, ProtectedRoomsSet, ProtectionDescription, RoomEvent, SafeIntegerProtectionSetting, StandardProtectionSettings, StringEventID, StringRoomID, StringUserID, describeProtection, isError } from "matrix-protection-suite";
|
||||
import { AbstractProtection, ActionResult, BasicConsequenceProvider, Logger, MatrixRoomID, Ok, ProtectedRoomsSet, ProtectionDescription, RoomEvent, SafeIntegerProtectionSetting, StandardProtectionSettings, StringEventID, StringRoomID, StringUserID, describeProtection, isError } from "matrix-protection-suite";
|
||||
|
||||
const log = new Logger('BasicFloodingProtection');
|
||||
|
||||
@@ -78,7 +78,7 @@ export class BasicFloodingProtection extends AbstractProtection implements Draup
|
||||
|
||||
public constructor(
|
||||
description: ProtectionDescription,
|
||||
consequenceProvider: ConsequenceProvider,
|
||||
consequenceProvider: BasicConsequenceProvider,
|
||||
protectedRoomsSet: ProtectedRoomsSet,
|
||||
private readonly draupnir: Draupnir,
|
||||
private readonly settings: BasicFloodingProtectionSettings,
|
||||
|
||||
@@ -26,7 +26,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { LogLevel, LogService } from "matrix-bot-sdk";
|
||||
import { AbstractProtection, ActionResult, ConsequenceProvider, MatrixRoomID, MembershipChange, MembershipChangeType, Ok, ProtectedRoomsSet, Protection, ProtectionDescription, RoomEvent, RoomMembershipRevision, RoomMessage, StringRoomID, StringUserID, Value, describeProtection } from "matrix-protection-suite";
|
||||
import { AbstractProtection, ActionResult, BasicConsequenceProvider, MatrixRoomID, MembershipChange, MembershipChangeType, Ok, ProtectedRoomsSet, Protection, ProtectionDescription, RoomEvent, RoomMembershipRevision, RoomMessage, StringRoomID, StringUserID, Value, describeProtection } from "matrix-protection-suite";
|
||||
import { Draupnir } from "../Draupnir";
|
||||
|
||||
type FirstMessageIsImageProtectionSettings = {}
|
||||
@@ -54,7 +54,7 @@ export class FirstMessageIsImageProtection extends AbstractProtection implements
|
||||
|
||||
constructor(
|
||||
description: ProtectionDescription<Draupnir, FirstMessageIsImageProtectionSettings>,
|
||||
consequenceProvider: ConsequenceProvider,
|
||||
consequenceProvider: BasicConsequenceProvider,
|
||||
protectedRoomsSet: ProtectedRoomsSet,
|
||||
private readonly draupnir: Draupnir,
|
||||
) {
|
||||
|
||||
@@ -25,7 +25,7 @@ limitations under the License.
|
||||
* are NOT distributed, contributed, committed, or licensed under the Apache License.
|
||||
*/
|
||||
|
||||
import { AbstractProtection, ActionResult, ConsequenceProvider, Logger, MembershipChange, MembershipChangeType, Ok, ProtectedRoomsSet, ProtectionDescription, RoomMembershipRevision, SafeIntegerProtectionSetting, StandardProtectionSettings, StringRoomID, describeProtection, isError } from "matrix-protection-suite";
|
||||
import { AbstractProtection, ActionResult, BasicConsequenceProvider, Logger, MembershipChange, MembershipChangeType, Ok, ProtectedRoomsSet, ProtectionDescription, RoomMembershipRevision, SafeIntegerProtectionSetting, StandardProtectionSettings, StringRoomID, describeProtection, isError } from "matrix-protection-suite";
|
||||
import {LogLevel} from "matrix-bot-sdk";
|
||||
import { Draupnir } from "../Draupnir";
|
||||
import { DraupnirProtection } from "./Protection";
|
||||
@@ -85,7 +85,7 @@ export class JoinWaveShortCircuitProtection extends AbstractProtection implement
|
||||
|
||||
constructor(
|
||||
description: ProtectionDescription<Draupnir, JoinWaveShortCircuitProtectionSettings>,
|
||||
consequenceProvider: ConsequenceProvider,
|
||||
consequenceProvider: BasicConsequenceProvider,
|
||||
protectedRoomsSet: ProtectedRoomsSet,
|
||||
private readonly draupnir: Draupnir,
|
||||
public readonly settings: JoinWaveShortCircuitProtectionSettings
|
||||
|
||||
@@ -26,7 +26,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { LogLevel } from "matrix-bot-sdk";
|
||||
import { AbstractProtection, ActionResult, ConsequenceProvider, MatrixRoomID, Ok, Permalinks, ProtectedRoomsSet, Protection, ProtectionDescription, RoomEvent, RoomMessage, Value, describeProtection, serverName } from "matrix-protection-suite";
|
||||
import { AbstractProtection, ActionResult, BasicConsequenceProvider, MatrixRoomID, Ok, Permalinks, ProtectedRoomsSet, Protection, ProtectionDescription, RoomEvent, RoomMessage, Value, describeProtection, serverName } from "matrix-protection-suite";
|
||||
import { Draupnir } from "../Draupnir";
|
||||
|
||||
type MessageIsMediaProtectionSettings = {};
|
||||
@@ -49,7 +49,7 @@ describeProtection<Draupnir, MessageIsMediaProtectionSettings>({
|
||||
export class MessageIsMediaProtection extends AbstractProtection implements Protection {
|
||||
constructor(
|
||||
description: ProtectionDescription<Draupnir, MessageIsMediaProtectionSettings>,
|
||||
consequenceProvider: ConsequenceProvider,
|
||||
consequenceProvider: BasicConsequenceProvider,
|
||||
protectedRoomsSet: ProtectedRoomsSet,
|
||||
private readonly draupnir: Draupnir
|
||||
) {
|
||||
|
||||
@@ -26,7 +26,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import { LogLevel} from "matrix-bot-sdk";
|
||||
import { AbstractProtection, ActionResult, ConsequenceProvider, MatrixRoomID, Ok, Permalinks, ProtectedRoomsSet, Protection, ProtectionDescription, RoomEvent, RoomMessage, Value, describeProtection, serverName } from "matrix-protection-suite";
|
||||
import { AbstractProtection, ActionResult, BasicConsequenceProvider, MatrixRoomID, Ok, Permalinks, ProtectedRoomsSet, Protection, ProtectionDescription, RoomEvent, RoomMessage, Value, describeProtection, serverName } from "matrix-protection-suite";
|
||||
import { Draupnir } from "../Draupnir";
|
||||
|
||||
describeProtection<Draupnir>({
|
||||
@@ -47,7 +47,7 @@ describeProtection<Draupnir>({
|
||||
export class MessageIsVoiceProtection extends AbstractProtection implements Protection {
|
||||
constructor(
|
||||
description: ProtectionDescription<Draupnir>,
|
||||
consequenceProvider: ConsequenceProvider,
|
||||
consequenceProvider: BasicConsequenceProvider,
|
||||
protectedRoomsSet: ProtectedRoomsSet,
|
||||
private readonly draupnir: Draupnir,
|
||||
) {
|
||||
|
||||
@@ -25,7 +25,7 @@ limitations under the License.
|
||||
* are NOT distributed, contributed, committed, or licensed under the Apache License.
|
||||
*/
|
||||
|
||||
import { AbstractProtection, ActionResult, ConsequenceProvider, EventReport, Ok, ProtectedRoomsSet, Protection, ProtectionDescription, SafeIntegerProtectionSetting, StandardProtectionSettings, StringEventID, StringUserID, StringUserIDSetProtectionSettings, describeProtection, isError } from "matrix-protection-suite";
|
||||
import { AbstractProtection, ActionResult, BasicConsequenceProvider, EventReport, Ok, ProtectedRoomsSet, Protection, ProtectionDescription, SafeIntegerProtectionSetting, StandardProtectionSettings, StringEventID, StringUserID, StringUserIDSetProtectionSettings, describeProtection, isError } from "matrix-protection-suite";
|
||||
import { Draupnir } from "../Draupnir";
|
||||
|
||||
const MAX_REPORTED_EVENT_BACKLOG = 20;
|
||||
@@ -81,7 +81,7 @@ export class TrustedReporters extends AbstractProtection implements Protection
|
||||
|
||||
public constructor(
|
||||
description: ProtectionDescription<Draupnir, TrustedReportersProtectionSettings>,
|
||||
consequenceProvider: ConsequenceProvider,
|
||||
consequenceProvider: BasicConsequenceProvider,
|
||||
protectedRoomsSet: ProtectedRoomsSet,
|
||||
private readonly draupnir: Draupnir,
|
||||
public readonly settings: TrustedReportersProtectionSettings
|
||||
|
||||
@@ -25,7 +25,7 @@ limitations under the License.
|
||||
* are NOT distributed, contributed, committed, or licensed under the Apache License.
|
||||
*/
|
||||
|
||||
import { AbstractProtection, ActionResult, ConsequenceProvider, Logger, MatrixRoomID, MembershipChange, MembershipChangeType, Ok, ProtectedRoomsSet, Protection, ProtectionDescription, RoomEvent, RoomMembershipRevision, RoomMessage, StringRoomID, StringUserID, Value, describeProtection } from "matrix-protection-suite";
|
||||
import { AbstractProtection, ActionResult, BasicConsequenceProvider, Logger, MatrixRoomID, MembershipChange, MembershipChangeType, Ok, ProtectedRoomsSet, Protection, ProtectionDescription, RoomEvent, RoomMembershipRevision, RoomMessage, StringRoomID, StringUserID, Value, describeProtection } from "matrix-protection-suite";
|
||||
import { Draupnir } from "../Draupnir";
|
||||
|
||||
const log = new Logger('WordList');
|
||||
@@ -52,7 +52,7 @@ export class WordListProtection extends AbstractProtection implements Protection
|
||||
|
||||
constructor(
|
||||
description: ProtectionDescription<Draupnir>,
|
||||
consequenceProvider: ConsequenceProvider,
|
||||
consequenceProvider: BasicConsequenceProvider,
|
||||
protectedRoomsSet: ProtectedRoomsSet,
|
||||
private readonly draupnir: Draupnir,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user