diff --git a/config/config.sample.yaml b/config/config.sample.yaml index d000b2d3902c8bcc25326d68c1ac6426b613a4f1..554e511860a1fd7bf07f8ff78cae48352584e432 100644 --- a/config/config.sample.yaml +++ b/config/config.sample.yaml @@ -29,6 +29,8 @@ bridge: disableReadReceipts: false # Disable Join Leave echos from matrix disableJoinLeaveNotifications: false + # Disable Invite echos from matrix + disableInviteNotifications: false # Authentication configuration for the discord bot. auth: # This MUST be a string (wrapped in quotes) diff --git a/config/config.schema.yaml b/config/config.schema.yaml index 7439ef2852c7af065ee69f2d91c8a476420b01da..860f1310100ee6e686486d8e841fa0ea3fab3a5f 100644 --- a/config/config.schema.yaml +++ b/config/config.schema.yaml @@ -22,6 +22,10 @@ properties: type: "boolean" disableReadReceipts: type: "boolean" + disableJoinLeaveNotifications: + type: "boolean" + disableInviteNotifications: + type: "boolean" auth: type: "object" required: ["botToken", "clientID"] diff --git a/src/config.ts b/src/config.ts index 9d966b544b8f4dee85f80121e30da15c1bec477b..de777b812d1d0f7b4784b792869eaab1af2e1672 100644 --- a/src/config.ts +++ b/src/config.ts @@ -90,6 +90,7 @@ class DiscordBridgeConfigBridge { public disableEveryoneMention: boolean = false; public disableHereMention: boolean = false; public disableJoinLeaveNotifications: boolean = false; + public disableInviteNotifications: boolean = false; public enableMetrics: boolean = false; } diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index 5e6428ab0bb6aebc23345c2f8a07d16c358eae50..cb5f87aaaee184e86fd630d268457cbf10f2cf59 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -231,6 +231,7 @@ export class MatrixEventProcessor { let msg = `\`${event.sender}\` `; const allowJoinLeave = !this.config.bridge.disableJoinLeaveNotifications; + const allowInvite = !this.config.bridge.disableInviteNotifications; if (event.type === "m.room.name") { msg += `set the name to \`${event.content!.name}\``; @@ -255,7 +256,7 @@ export class MatrixEventProcessor { } if (membership === "join" && isNewJoin && allowJoinLeave) { msg += "joined the room"; - } else if (membership === "invite") { + } else if (membership === "invite" && allowInvite) { msg += `invited \`${event.state_key}\` to the room`; } else if (membership === "leave" && event.state_key !== event.sender) { msg += `kicked \`${event.state_key}\` from the room`; diff --git a/test/test_config.ts b/test/test_config.ts index badb662a5c4a9929bfdfacb22c45faeef09a965d..270eb085a774584a9c62f37eca7ecd2f5ca6ef2f 100644 --- a/test/test_config.ts +++ b/test/test_config.ts @@ -30,6 +30,7 @@ describe("DiscordBridgeConfig.applyConfig", () => { disableDeletionForwarding: true, disableDiscordMentions: false, disableJoinLeaveNotifications: true, + disableInviteNotifications: true, disableTypingNotifications: true, enableSelfServiceBridging: false, homeserverUrl: "blah", @@ -44,6 +45,7 @@ describe("DiscordBridgeConfig.applyConfig", () => { expect(config.bridge.disableDeletionForwarding).to.be.true; expect(config.bridge.enableSelfServiceBridging).to.be.false; expect(config.bridge.disableJoinLeaveNotifications).to.be.true; + expect(config.bridge.disableInviteNotifications).to.be.true; expect(config.logging.console).to.equal("warn"); }); it("should merge environment overrides correctly", () => { @@ -61,9 +63,11 @@ describe("DiscordBridgeConfig.applyConfig", () => { config.applyEnvironmentOverrides({ APPSERVICE_DISCORD_BRIDGE_DISABLE_DELETION_FORWARDING: false, APPSERVICE_DISCORD_BRIDGE_DISABLE_JOIN_LEAVE_NOTIFICATIONS: true, + APPSERVICE_DISCORD_BRIDGE_DISABLE_INVITE_NOTIFICATIONS: true, APPSERVICE_DISCORD_LOGGING_CONSOLE: "debug", }); expect(config.bridge.disableJoinLeaveNotifications).to.be.true; + expect(config.bridge.disableInviteNotifications).to.be.true; expect(config.bridge.disableDeletionForwarding).to.be.false; expect(config.bridge.disableDiscordMentions).to.be.false; expect(config.bridge.homeserverUrl).to.equal("blah");