Skip to content

Commit c068313

Browse files
committed
don't send filenames in discord message bodies
Signed-off-by: chayleaf <chayleaf-git@pavluk.org>
1 parent 8ae61dd commit c068313

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

changelog.d/918.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Don't send filenames in message body when bridging Matrix -> Discord.

src/matrixeventprocessor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export class MatrixEventProcessor {
299299
}
300300

301301
let body: string = "";
302-
if (event.type !== "m.sticker") {
302+
if (!this.HasAttachment(event)) {
303303
const content = event.content!["m.new_content"] ? event.content!["m.new_content"] : event.content;
304304
body = await this.matrixMsgProcessor.FormatMessage(content as IMatrixMessage, channel.guild, params);
305305
}

test/test_matrixeventprocessor.ts

+30-1
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,35 @@ describe("MatrixEventProcessor", () => {
638638
} as IMatrixEvent, mockChannel as any);
639639
expect(embeds.messageEmbed.description).to.equal("Bunnies\n(<@1234>)");
640640
});
641+
it("Should not send filename in body", async () => {
642+
const {processor} = createMatrixEventProcessor();
643+
const embeds = await processor.EventToEmbed({
644+
content: {
645+
body: "filename.zip",
646+
msgtype: "m.file",
647+
url: "mxc://file",
648+
},
649+
sender: "@test:localhost",
650+
type: "m.room.member",
651+
} as IMatrixEvent, mockChannel as any);
652+
expect(embeds.messageEmbed.description).to.equal("");
653+
});
654+
it("Should not send image filename in body", async () => {
655+
const {processor} = createMatrixEventProcessor();
656+
const embeds = await processor.EventToEmbed({
657+
content: {
658+
body: "filename.jpg",
659+
info: {
660+
mimetype: "image/jpeg",
661+
},
662+
msgtype: "m.image",
663+
url: "mxc://image",
664+
},
665+
sender: "@test:localhost",
666+
type: "m.room.member",
667+
} as IMatrixEvent, mockChannel as any);
668+
expect(embeds.messageEmbed.description).to.equal("");
669+
});
641670
});
642671
describe("HandleAttachment", () => {
643672
const SMALL_FILE = 200;
@@ -939,7 +968,7 @@ This is the reply`,
939968
type: "m.room.message",
940969
} as IMatrixEvent, mockChannel as any);
941970
expect(result!.image!.url!).to.be.equal("https://fox/localhost");
942-
expect(result!.description).to.be.equal("fox.jpg");
971+
expect(result!.description).to.be.equal("");
943972
});
944973
it("should handle replies to files", async () => {
945974
const {processor} = createMatrixEventProcessor();

0 commit comments

Comments
 (0)