Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more configs to disable various Matrix state changes #867

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/867.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement config values, in order to disable forwarding room name changes, bans and kicks from Matrix to Discord.
6 changes: 6 additions & 0 deletions config/config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ bridge:
disableReadReceipts: false
# Disable Join Leave echos from matrix
disableJoinLeaveNotifications: false
# Disable Ban echos from matrix
disableBanNotifications: false
# Disable Kick echos from matrix
disableKickNotifications: false
# Disable Invite echos from matrix
disableInviteNotifications: false
# Disable Room Name change echos from matrix
disableRoomNameNotifications: false
# Disable Room Topic echos from matrix
disableRoomTopicNotifications: false
# Auto-determine the language of code blocks (this can be CPU-intensive)
Expand Down
6 changes: 6 additions & 0 deletions config/config.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ properties:
type: "boolean"
disableJoinLeaveNotifications:
type: "boolean"
disableBanNotifications:
type: "boolean"
disableKickNotifications:
type: "boolean"
disableInviteNotifications:
type: "boolean"
disableRoomNameNotifications:
type: "boolean"
disableRoomTopicNotifications:
type: "boolean"
userActivity:
Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ export class DiscordBridgeConfigBridge {
public disableEveryoneMention: boolean = false;
public disableHereMention: boolean = false;
public disableJoinLeaveNotifications: boolean = false;
public disableBanNotifications: boolean = false;
public disableKickNotifications: boolean = false;
public disableInviteNotifications: boolean = false;
public disableRoomNameNotifications: boolean = false;
public disableRoomTopicNotifications: boolean = false;
public determineCodeLanguage: boolean = false;
public activityTracker: UserActivityTrackerConfig = UserActivityTrackerConfig.DEFAULT;
Expand Down
11 changes: 7 additions & 4 deletions src/matrixeventprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,12 @@ export class MatrixEventProcessor {

const allowJoinLeave = !this.config.bridge.disableJoinLeaveNotifications;
const allowInvite = !this.config.bridge.disableInviteNotifications;
const allowRoomName = !this.config.bridge.disableRoomNameNotifications;
const allowRoomTopic = !this.config.bridge.disableRoomTopicNotifications;
const allowBan = !this.config.bridge.disableBanNotifications;
const allowKick = !this.config.bridge.disableKickNotifications;

if (event.type === "m.room.name") {
if (event.type === "m.room.name" && allowRoomName) {
msg += `set the name to \`${event.content!.name}\``;
} else if (event.type === "m.room.topic" && allowRoomTopic) {
msg += `set the topic to \`${event.content!.topic}\``;
Expand All @@ -263,11 +266,11 @@ export class MatrixEventProcessor {
msg += "joined the room";
} else if (membership === "invite" && allowInvite) {
msg += `invited \`${event.state_key}\` to the room`;
} else if (membership === "leave" && event.state_key !== event.sender) {
} else if (membership === "leave" && event.state_key !== event.sender && allowKick) {
msg += `kicked \`${event.state_key}\` from the room`;
} else if (membership === "leave" && allowJoinLeave) {
} else if (membership === "leave" && event.state_key === event.sender && allowJoinLeave) {
msg += "left the room";
} else if (membership === "ban") {
} else if (membership === "ban" && allowBan) {
msg += `banned \`${event.state_key}\` from the room`;
} else {
// Ignore anything else
Expand Down
44 changes: 44 additions & 0 deletions test/test_matrixeventprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,20 @@ describe("MatrixEventProcessor", () => {
await processor.ProcessStateEvent(event);
expect(STATE_EVENT_MSG).to.equal("`@user:localhost` set the name to `Test Name` on Matrix.");
});
it("Should not echo name changes", async () => {
const bridge = new DiscordBridgeConfigBridge();
bridge.disableRoomNameNotifications = true;
const {processor} = createMatrixEventProcessor(0, bridge);
const event = {
content: {
name: "Test Name",
},
sender: "@user:localhost",
type: "m.room.name",
} as IMatrixEvent;
await processor.ProcessStateEvent(event);
expect(STATE_EVENT_MSG).to.equal("");
});
it("Should echo topic changes", async () => {
const {processor} = createMatrixEventProcessor();
const event = {
Expand Down Expand Up @@ -438,6 +452,21 @@ describe("MatrixEventProcessor", () => {
await processor.ProcessStateEvent(event);
expect(STATE_EVENT_MSG).to.equal("`@user:localhost` kicked `@user2:localhost` from the room on Matrix.");
});
it("Should not echo kicks", async () => {
const bridge = new DiscordBridgeConfigBridge();
bridge.disableKickNotifications = true;
const {processor} = createMatrixEventProcessor(0, bridge);
const event = {
content: {
membership: "leave",
},
sender: "@user:localhost",
state_key: "@user2:localhost",
type: "m.room.member",
} as IMatrixEvent;
await processor.ProcessStateEvent(event);
expect(STATE_EVENT_MSG).to.equal("");
});
it("Should echo leaves", async () => {
const {processor} = createMatrixEventProcessor();
const event = {
Expand Down Expand Up @@ -480,6 +509,21 @@ describe("MatrixEventProcessor", () => {
await processor.ProcessStateEvent(event);
expect(STATE_EVENT_MSG).to.equal("`@user:localhost` banned `@user2:localhost` from the room on Matrix.");
});
it("Should not echo bans", async () => {
const bridge = new DiscordBridgeConfigBridge();
bridge.disableBanNotifications = true;
const {processor} = createMatrixEventProcessor(0, bridge);
const event = {
content: {
membership: "ban",
},
sender: "@user:localhost",
state_key: "@user2:localhost",
type: "m.room.member",
} as IMatrixEvent;
await processor.ProcessStateEvent(event);
expect(STATE_EVENT_MSG).to.equal("");
});
});
describe("EventToEmbed", () => {
it("Should contain a profile.", async () => {
Expand Down