diff --git a/src/commands/StatusCommand.tsx b/src/commands/StatusCommand.tsx index d425fc44..a8399db3 100644 --- a/src/commands/StatusCommand.tsx +++ b/src/commands/StatusCommand.tsx @@ -36,7 +36,7 @@ import { CommandError, CommandResult } from "./interface-manager/Validation"; import { defineMatrixInterfaceAdaptor, MatrixContext, MatrixInterfaceAdaptor } from "./interface-manager/MatrixInterfaceAdaptor"; import { MatrixSendClient } from "../MatrixEmitter"; import { JSXFactory } from "./interface-manager/JSXFactory"; -import { Protection } from "../protections/IProtection"; +import { Protection } from "../protections/Protection"; import { tickCrossRenderer } from "./interface-manager/MatrixHelpRenderer"; import { renderMatrixAndSend } from "./interface-manager/DeadDocumentMatrix"; diff --git a/src/protections/BanPropagation.tsx b/src/protections/BanPropagation.tsx index d23453b7..4f7e1d00 100644 --- a/src/protections/BanPropagation.tsx +++ b/src/protections/BanPropagation.tsx @@ -25,7 +25,7 @@ limitations under the License. * are NOT distributed, contributed, committed, or licensed under the Apache License. */ -import { Protection } from "./IProtection"; +import { Protection } from "./Protection"; import { Mjolnir } from "../Mjolnir"; import { LogService } from "matrix-bot-sdk"; import { JSXFactory } from "../commands/interface-manager/JSXFactory"; diff --git a/src/protections/BasicFlooding.ts b/src/protections/BasicFlooding.ts index a30d6466..89cc7a4c 100644 --- a/src/protections/BasicFlooding.ts +++ b/src/protections/BasicFlooding.ts @@ -25,7 +25,7 @@ limitations under the License. * are NOT distributed, contributed, committed, or licensed under the Apache License. */ -import { Protection } from "./IProtection"; +import { Protection } from "./Protection"; import { NumberProtectionSetting } from "./ProtectionSettings"; import { Mjolnir } from "../Mjolnir"; import { LogLevel, LogService } from "matrix-bot-sdk"; diff --git a/src/protections/DetectFederationLag.ts b/src/protections/DetectFederationLag.ts index 0d7785bf..944eac91 100644 --- a/src/protections/DetectFederationLag.ts +++ b/src/protections/DetectFederationLag.ts @@ -25,7 +25,7 @@ limitations under the License. * are NOT distributed, contributed, committed, or licensed under the Apache License. */ -import { Protection } from "./IProtection"; +import { Protection } from "./Protection"; import { DurationMSProtectionSetting, NumberProtectionSetting, StringSetProtectionSetting } from "./ProtectionSettings"; import { Mjolnir } from "../Mjolnir"; import { LogLevel, UserID } from "matrix-bot-sdk"; diff --git a/src/protections/FirstMessageIsImage.ts b/src/protections/FirstMessageIsImage.ts index ab3a993e..915f6b88 100644 --- a/src/protections/FirstMessageIsImage.ts +++ b/src/protections/FirstMessageIsImage.ts @@ -25,7 +25,7 @@ limitations under the License. * are NOT distributed, contributed, committed, or licensed under the Apache License. */ -import { Protection } from "./IProtection"; +import { Protection } from "./Protection"; import { Mjolnir } from "../Mjolnir"; import { LogLevel, LogService } from "matrix-bot-sdk"; import { isTrueJoinEvent } from "../utils"; diff --git a/src/protections/JoinWaveShortCircuit.ts b/src/protections/JoinWaveShortCircuit.ts index 204f060e..733441d5 100644 --- a/src/protections/JoinWaveShortCircuit.ts +++ b/src/protections/JoinWaveShortCircuit.ts @@ -25,7 +25,7 @@ limitations under the License. * are NOT distributed, contributed, committed, or licensed under the Apache License. */ -import {Protection} from "./IProtection"; +import {Protection} from "./Protection"; import {Mjolnir} from "../Mjolnir"; import {NumberProtectionSetting} from "./ProtectionSettings"; import {LogLevel} from "matrix-bot-sdk"; diff --git a/src/protections/MessageIsMedia.ts b/src/protections/MessageIsMedia.ts index 4f5fb006..7b31e8ab 100644 --- a/src/protections/MessageIsMedia.ts +++ b/src/protections/MessageIsMedia.ts @@ -25,7 +25,7 @@ limitations under the License. * are NOT distributed, contributed, committed, or licensed under the Apache License. */ -import { Protection } from "./IProtection"; +import { Protection } from "./Protection"; import { Mjolnir } from "../Mjolnir"; import { LogLevel, UserID } from "matrix-bot-sdk"; import { Permalinks } from "../commands/interface-manager/Permalinks"; diff --git a/src/protections/MessageIsVoice.ts b/src/protections/MessageIsVoice.ts index 3aeea867..aa13485e 100644 --- a/src/protections/MessageIsVoice.ts +++ b/src/protections/MessageIsVoice.ts @@ -25,7 +25,7 @@ limitations under the License. * are NOT distributed, contributed, committed, or licensed under the Apache License. */ -import { Protection } from "./IProtection"; +import { Protection } from "./Protection"; import { Mjolnir } from "../Mjolnir"; import { LogLevel, UserID } from "matrix-bot-sdk"; import { Permalinks } from "../commands/interface-manager/Permalinks"; diff --git a/src/protections/IProtection.ts b/src/protections/Protection.ts similarity index 100% rename from src/protections/IProtection.ts rename to src/protections/Protection.ts diff --git a/src/protections/ProtectionManager.ts b/src/protections/ProtectionManager.ts index 2d34f47f..7a44c0ee 100644 --- a/src/protections/ProtectionManager.ts +++ b/src/protections/ProtectionManager.ts @@ -26,7 +26,7 @@ limitations under the License. */ import { FirstMessageIsImage } from "./FirstMessageIsImage"; -import { Protection } from "./IProtection"; +import { Protection } from "./Protection"; import { BasicFlooding } from "./BasicFlooding"; import { DetectFederationLag } from "./DetectFederationLag"; import { WordList } from "./WordList"; diff --git a/src/protections/TrustedReporters.ts b/src/protections/TrustedReporters.ts index 6707e56b..01b4bd15 100644 --- a/src/protections/TrustedReporters.ts +++ b/src/protections/TrustedReporters.ts @@ -25,7 +25,7 @@ limitations under the License. * are NOT distributed, contributed, committed, or licensed under the Apache License. */ -import { Protection } from "./IProtection"; +import { Protection } from "./Protection"; import { MXIDListProtectionSetting, NumberProtectionSetting } from "./ProtectionSettings"; import { Mjolnir } from "../Mjolnir"; diff --git a/src/protections/WordList.ts b/src/protections/WordList.ts index 4e9f633c..80e26cb4 100644 --- a/src/protections/WordList.ts +++ b/src/protections/WordList.ts @@ -25,7 +25,7 @@ limitations under the License. * are NOT distributed, contributed, committed, or licensed under the Apache License. */ -import { Protection } from "./IProtection"; +import { Protection } from "./Protection"; import { ConsequenceBan, ConsequenceRedact } from "./consequence"; import { Mjolnir } from "../Mjolnir"; import { LogLevel, LogService } from "matrix-bot-sdk"; diff --git a/test/integration/acceptInvitesFromSpaceTest.ts b/test/integration/acceptInvitesFromSpaceTest.ts index 3f581a58..d2157e3e 100644 --- a/test/integration/acceptInvitesFromSpaceTest.ts +++ b/test/integration/acceptInvitesFromSpaceTest.ts @@ -9,7 +9,7 @@ describe("Test: Accept Invites From Space", function() { await client.start(); }) this.afterEach(async function () { - await client.stop(); + await client?.stop(); }) it("Mjolnir should accept an invite from a user in a nominated Space", async function() { this.timeout(20000); @@ -17,7 +17,7 @@ describe("Test: Accept Invites From Space", function() { const mjolnir: Mjolnir = this.mjolnir!; const mjolnirUserId = await mjolnir.client.getUserId(); - const space = await client.createSpace({ + const space = await client!.createSpace({ name: "mjolnir space invite test", invites: [mjolnirUserId], isPublic: false @@ -30,8 +30,8 @@ describe("Test: Accept Invites From Space", function() { mjolnir.config.acceptInvitesFromSpace = space.roomId; const promise = new Promise(async resolve => { - const newRoomId = await client.createRoom({ invite: [mjolnirUserId] }); - client.on("room.event", (roomId, event) => { + const newRoomId = await client!.createRoom({ invite: [mjolnirUserId] }); + client!.on("room.event", (roomId, event) => { if ( roomId === newRoomId && event.type === "m.room.member" diff --git a/test/integration/protectionSettingsTest.ts b/test/integration/protectionSettingsTest.ts index 26495e08..bc764024 100644 --- a/test/integration/protectionSettingsTest.ts +++ b/test/integration/protectionSettingsTest.ts @@ -1,17 +1,18 @@ import { strict as assert } from "assert"; -import { Protection } from "../../src/protections/IProtection"; +import { MatrixClient } from "matrix-bot-sdk"; +import { Protection } from "../../src/protections/Protection"; import { ProtectionSettingValidationError } from "../../src/protections/ProtectionSettings"; import { NumberProtectionSetting, StringProtectionSetting, StringListProtectionSetting } from "../../src/protections/ProtectionSettings"; import { newTestUser, noticeListener } from "./clientHelper"; describe("Test: Protection settings", function() { - let client; + let syncingUser: MatrixClient|undefined; this.beforeEach(async function () { - client = await newTestUser(this.config.homeserverUrl, { name: { contains: "protection-settings" }}); - await client.start(); + syncingUser = await newTestUser(this.config.homeserverUrl, { name: { contains: "protection-settings" }}); + await syncingUser.start(); }) this.afterEach(async function () { - await client.stop(); + await syncingUser?.stop(); }) it("Mjolnir refuses to save invalid protection setting values", async function() { this.timeout(20000); @@ -55,6 +56,7 @@ describe("Test: Protection settings", function() { }); it("Mjolnir responds to !set correctly", async function() { this.timeout(20000); + const client = (assert.notEqual(undefined, syncingUser), syncingUser!); await client.joinRoom(this.config.managementRoom); await this.mjolnir.protectionManager.registerProtection(new class extends Protection { @@ -80,6 +82,7 @@ describe("Test: Protection settings", function() { }); it("Mjolnir adds a value to a list setting", async function() { this.timeout(20000); + const client = (assert.notEqual(undefined, syncingUser), syncingUser!); await client.joinRoom(this.config.managementRoom); await this.mjolnir.protectionManager.registerProtection(new class extends Protection { @@ -104,6 +107,7 @@ describe("Test: Protection settings", function() { }); it("Mjolnir removes a value from a list setting", async function() { this.timeout(20000); + const client = (assert.notEqual(undefined, syncingUser), syncingUser!); await client.joinRoom(this.config.managementRoom); await this.mjolnir.protectionManager.registerProtection(new class extends Protection { @@ -129,6 +133,7 @@ describe("Test: Protection settings", function() { }); it("Mjolnir will change a protection setting in-place", async function() { this.timeout(20000); + const client = (assert.notEqual(undefined, syncingUser), syncingUser!); await client.joinRoom(this.config.managementRoom); await this.mjolnir.protectionManager.registerProtection(new class extends Protection { @@ -141,7 +146,7 @@ describe("Test: Protection settings", function() { let i = 0; client.on('room.message', noticeListener(this.mjolnir.managementRoomId, (event) => { if (event.content.body.includes("Changed d0sNrt.test ")) { - if (++i == 2) { + if (++i === 2) { resolve(event); } } diff --git a/test/integration/reportPollingTest.ts b/test/integration/reportPollingTest.ts index 03aba82b..a4aa89e9 100644 --- a/test/integration/reportPollingTest.ts +++ b/test/integration/reportPollingTest.ts @@ -1,5 +1,5 @@ import { Mjolnir } from "../../src/Mjolnir"; -import { IProtection } from "../../src/protections/IProtection"; +import { Protection } from "../../src/protections/Protection"; import { newTestUser } from "./clientHelper"; describe("Test: Report polling", function() { @@ -16,12 +16,12 @@ describe("Test: Report polling", function() { const eventId = await client.sendMessage(protectedRoomId, {msgtype: "m.text", body: "uwNd3q"}); await new Promise(async resolve => { - await this.mjolnir.protectionManager.registerProtection(new class implements IProtection { + await this.mjolnir.protectionManager.registerProtection(new class extends Protection { name = "jYvufI"; description = "A test protection"; settings = { }; handleEvent = async (mjolnir: Mjolnir, roomId: string, event: any) => { }; - handleReport = (mjolnir: Mjolnir, roomId: string, reporterId: string, event: any, reason?: string) => { + handleReport = async (mjolnir: Mjolnir, roomId: string, reporterId: string, event: any, reason?: string) => { if (reason === "x5h1Je") { resolve(null); } diff --git a/test/integration/standardConsequenceTest.ts b/test/integration/standardConsequenceTest.ts index f762f4c3..ba541573 100644 --- a/test/integration/standardConsequenceTest.ts +++ b/test/integration/standardConsequenceTest.ts @@ -1,9 +1,6 @@ -import { strict as assert } from "assert"; - import { Mjolnir } from "../../src/Mjolnir"; -import { IProtection } from "../../src/protections/IProtection"; +import { Protection } from "../../src/protections/Protection"; import { newTestUser, noticeListener } from "./clientHelper"; -import { matrixClient, mjolnir } from "./mjolnirSetupUtils"; import { ConsequenceBan, ConsequenceRedact } from "../../src/protections/consequence"; describe("Test: standard consequences", function() { @@ -27,7 +24,7 @@ describe("Test: standard consequences", function() { await badUser.joinRoom(protectedRoomId); await this.mjolnir.addProtectedRoom(protectedRoomId); - await this.mjolnir.protectionManager.registerProtection(new class implements IProtection { + await this.mjolnir.protectionManager.registerProtection(new class extends Protection { name = "JY2TPN"; description = "A test protection"; settings = { }; @@ -71,7 +68,7 @@ describe("Test: standard consequences", function() { await badUser.joinRoom(protectedRoomId); await this.mjolnir.addProtectedRoom(protectedRoomId); - await this.mjolnir.protectionManager.registerProtection(new class implements IProtection { + await this.mjolnir.protectionManager.registerProtection(new class extends Protection { name = "0LxMTy"; description = "A test protection"; settings = { }; @@ -118,7 +115,7 @@ describe("Test: standard consequences", function() { await goodUser.joinRoom(protectedRoomId); await this.mjolnir.addProtectedRoom(protectedRoomId); - await this.mjolnir.protectionManager.registerProtection(new class implements IProtection { + await this.mjolnir.protectionManager.registerProtection(new class extends Protection { name = "95B1Cr"; description = "A test protection"; settings = { }; diff --git a/tsconfig.json b/tsconfig.json index 42282d1b..a931511a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -30,5 +30,6 @@ "./test/integration/banListTest.ts", "./test/integration/reportPollingTest", "./test/integration/policyConsumptionTest.ts", + "./test/integration/protectionSettingsTest.ts" ] }