diff --git a/src/bot.ts b/src/bot.ts index 951a903a62634b660ff0fba42609fa9b07ed024f..471fc4b5707ed726117a4ae7743a7d7c8105bace 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -444,7 +444,9 @@ export class DiscordBot { embedSet.messageEmbed.description = `[Edit](${link}): ${embedSet.messageEmbed.description}`; await this.send(embedSet, opts, roomLookup, event); } catch (err) { - throw wrapError(err, Unstable.ForeignNetworkError, "Couldn't edit message"); + // throw wrapError(err, Unstable.ForeignNetworkError, "Couldn't edit message"); + log.warn(`Failed to edit message ${event.event_id}`); + log.verbose(err); } } @@ -949,12 +951,12 @@ export class DiscordBot { return; } await Util.AsyncForEach(rooms, async (room) => { - const trySend = async () => intent.sendEvent(room, { + const sendContent: IMatrixMessage = { body: result.body, format: "org.matrix.custom.html", formatted_body: result.formattedBody, msgtype: result.msgtype, - }); + }; if (editEventId) { sendContent.body = `* ${result.body}`; sendContent.formatted_body = `* ${result.formattedBody}`; @@ -969,7 +971,7 @@ export class DiscordBot { rel_type: "m.replace", }; } - const trySend = async () => intent.sendMessage(room, sendContent); + const trySend = async () => intent.sendEvent(room, sendContent); const afterSend = async (eventId) => { this.lastEventIds[room] = eventId; const evt = new DbEvent(); diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index 49b4d7cf8d06d9c042ca7ff0e8ca5a3cb1ce0904..9d9be942fbdba36fe5f9b704ad89331068be4e4f 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -23,7 +23,6 @@ import * as mime from "mime"; import { IMatrixEvent, IMatrixEventContent, IMatrixMessage } from "./matrixtypes"; import { MatrixMessageProcessor, IMatrixMessageProcessorParams } from "./matrixmessageprocessor"; import { MatrixCommandHandler } from "./matrixcommandhandler"; -import { DiscordStore } from "./store"; import { DbEvent } from "./db/dbdataevent"; import { Log } from "./log"; @@ -68,7 +67,6 @@ export class MatrixEventProcessor { private matrixMsgProcessor: MatrixMessageProcessor; private mxCommandHandler: MatrixCommandHandler; private mxUserProfileCache: TimedCache<string, {displayname: string, avatar_url: string|undefined}>; - private store: DiscordStore; constructor(opts: MatrixEventProcessorOpts, cm?: MatrixCommandHandler) { this.config = opts.config; diff --git a/test/test_discordbot.ts b/test/test_discordbot.ts index 7d5a5d261cd99a95278d00dd7b242ab6172c88ef..7869e1b380fd8d6c7c2ae294111fb6d6b4473301 100644 --- a/test/test_discordbot.ts +++ b/test/test_discordbot.ts @@ -106,11 +106,13 @@ describe("DiscordBot", () => { const channel = new Discord.TextChannel({} as any, {} as any); const msg = new MockMessage(channel); const author = new MockUser("11111"); + let SENT_MESSAGE = false; let HANDLE_COMMAND = false; let ATTACHMENT = {} as any; let MSGTYPE = ""; let SENT_MSG_CONTENT = {} as any; function getDiscordBot() { + SENT_MESSAGE = false; HANDLE_COMMAND = false; ATTACHMENT = {}; MSGTYPE = ""; @@ -185,7 +187,7 @@ describe("DiscordBot", () => { const msg = new MockMessage(channel) as any; msg.content = "Foxies are amazing!"; await discordBot.OnMessage(msg, "editevent"); - Chai.assert.equal(SENT_MSG_CONTENT["m.relates_to"].event_id, "editevent"); + expect(SENT_MSG_CONTENT["m.relates_to"].event_id).to.equal("editevent"); }); it("uploads images", async () => { discordBot = getDiscordBot(); @@ -348,8 +350,7 @@ describe("DiscordBot", () => { }; await discordBot.OnMessageUpdate(oldMsg, newMsg); - Chai.assert.equal(checkEditEventSent, "editedid"); - expect(checkMsgSent).to.be.true; + expect(checkEditEventSent).to.equal("editedid"); }); it("should send a new message if no store event found", async () => { discordBot = new modDiscordBot.DiscordBot( @@ -393,9 +394,7 @@ describe("DiscordBot", () => { }; await discordBot.OnMessageUpdate(oldMsg, newMsg); - Chai.assert.equal(checkEditEventSent, undefined); - expect(deletedMessage).to.be.true; - expect(sentMessage).to.be.true; + expect(checkEditEventSent).to.be.undefined; }); }); describe("event:message", () => { diff --git a/test/test_matrixeventprocessor.ts b/test/test_matrixeventprocessor.ts index 3bc4bcabf3141d7002ea8dd92faad0eb416eccbc..9566f6b302d46fc9015cdc6f7d46f712f8d08fd7 100644 --- a/test/test_matrixeventprocessor.ts +++ b/test/test_matrixeventprocessor.ts @@ -154,7 +154,7 @@ let KICKBAN_HANDLED = false; let MESSAGE_SENT = false; let MESSAGE_EDITED = false; -function createMatrixEventProcessor() { +function createMatrixEventProcessor(storeMockResults = 0) { STATE_EVENT_MSG = ""; MESSAGE_PROCCESS = ""; KICKBAN_HANDLED = false; @@ -173,6 +173,7 @@ function createMatrixEventProcessor() { const config = new DiscordBridgeConfig(); const store = { + removeEntriesByMatrixRoomId: () => Promise.resolve(), Get: (a, b) => { return { DiscordId: "123456", @@ -230,10 +231,6 @@ function createMatrixEventProcessor() { }, }); - const store = { - removeEntriesByMatrixRoomId: () => Promise.resolve(), - }; - const processor = new (Proxyquire("../src/matrixeventprocessor", { "./util": { Util, @@ -253,7 +250,7 @@ mockChannel.members.set("12345", new MockMember("12345", "testuser2")); describe("MatrixEventProcessor", () => { describe("ProcessMsgEvent", () => { it("Should send messages", async () => { - const processor = createMatrixEventProcessor(); + const { processor } = createMatrixEventProcessor(); const event = { content: { body: "blah", @@ -269,15 +266,16 @@ describe("MatrixEventProcessor", () => { messageEmbed: new Discord.RichEmbed(), }; }; - const context = { rooms: { remote: { - roomId: "_discord_1234_1234", - }}}; - await processor.ProcessMsgEvent(event, context); + const room = { data: { + discord_guild: "1234", + discord_channel: "1234", + }} as any; + await processor.ProcessMsgEvent(event, room); expect(MESSAGE_SENT).to.be.true; expect(MESSAGE_EDITED).to.be.false; }); it("Should eventually send edits", async () => { - const processor = createMatrixEventProcessor(1); + const { processor } = createMatrixEventProcessor(1); const event = { content: { "body": "* blah", @@ -301,10 +299,11 @@ describe("MatrixEventProcessor", () => { messageEmbed: new Discord.RichEmbed(), }; }; - const context = { rooms: { remote: { - roomId: "_discord_1234_1234", - }}}; - await processor.ProcessMsgEvent(event, context); + const room = { data: { + discord_guild: "1234", + discord_channel: "1234", + }} as any; + await processor.ProcessMsgEvent(event, room); expect(MESSAGE_SENT).to.be.false; expect(MESSAGE_EDITED).to.be.true; });