diff --git a/src/bot.ts b/src/bot.ts index bce64f7edf153fc12fcdb2dad191db7d59445563..dd92f86e7b9c0609583b70c134f299bb70b17f18 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -8,7 +8,7 @@ import { Util } from "./util"; import { DiscordMessageProcessor, DiscordMessageProcessorOpts, - DiscordMessageProcessorMatrixResult, + DiscordMessageProcessorResult, } from "./discordmessageprocessor"; import { MatrixEventProcessor, MatrixEventProcessorOpts } from "./matrixeventprocessor"; import { PresenceHandler } from "./presencehandler"; @@ -451,7 +451,7 @@ export class DiscordBot { return rooms.map((room) => room.matrix.getId()); } - private async SendMatrixMessage(matrixMsg: DiscordMessageProcessorMatrixResult, chan: Discord.Channel, + private async SendMatrixMessage(matrixMsg: DiscordMessageProcessorResult, chan: Discord.Channel, guild: Discord.Guild, author: Discord.User, msgID: string): Promise<boolean> { const rooms = await this.channelSync.GetRoomIdsFromChannel(chan); diff --git a/src/discordmessageprocessor.ts b/src/discordmessageprocessor.ts index 1d269ce5aa2a2f5b72a34fd38f62bcdcb7cee7ed..735d518ffbced586212a252a512a98d00ccf17f2 100644 --- a/src/discordmessageprocessor.ts +++ b/src/discordmessageprocessor.ts @@ -5,7 +5,7 @@ import * as escapeHtml from "escape-html"; import { Util } from "./util"; import { Log } from "./log"; -const log = new Log("MessageProcessor"); +const log = new Log("DiscordMessageProcessor"); const MATRIX_TO_LINK = "https://matrix.to/#/"; const MXC_INSERT_REGEX = /\x01(\w+)\x01([01])\x01([0-9]*)\x01/g; @@ -20,7 +20,7 @@ export class DiscordMessageProcessorOpts { } } -export class DiscordMessageProcessorMatrixResult { +export class DiscordMessageProcessorResult { public formattedBody: string; public body: string; public msgtype: string; @@ -46,8 +46,8 @@ export class DiscordMessageProcessor { } } - public async FormatMessage(msg: Discord.Message): Promise<DiscordMessageProcessorMatrixResult> { - const result = new DiscordMessageProcessorMatrixResult(); + public async FormatMessage(msg: Discord.Message): Promise<DiscordMessageProcessorResult> { + const result = new DiscordMessageProcessorResult(); let content = msg.content; @@ -78,7 +78,7 @@ export class DiscordMessageProcessor { public async FormatEdit( oldMsg: Discord.Message, newMsg: Discord.Message, - ): Promise<DiscordMessageProcessorMatrixResult> { + ): Promise<DiscordMessageProcessorResult> { // TODO: Produce a nice, colored diff between the old and new message content oldMsg.content = `*edit:* ~~${oldMsg.content}~~ -> ${newMsg.content}`; return this.FormatMessage(oldMsg); diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index 33d4bc8cf72f618efddf2ad91ae2fc9945b1dd6d..d0128e257e0274c1c99a85dacb20021a1a722ad3 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -95,9 +95,17 @@ export class MatrixEventProcessor { event: IMatrixEvent, channel: Discord.TextChannel, getReply: boolean = true, ): Promise<IMatrixEventProcessorResult> { const mxClient = this.bridge.getClientFactory().getClientAs(); - const profile = await mxClient.getStateEvent(event.room_id, "m.room.member", event.sender); - if (!profile) { - log.warn(`User ${event.sender} has no member state. That's odd.`); + let profile: IMatrixEvent | null = null; + try { + profile = await mxClient.getStateEvent(event.room_id, "m.room.member", event.sender); + if (!profile) { + profile = await mxClient.getProfileInfo(event.sender); + } + if (!profile) { + log.warn(`User ${event.sender} has no member state and no profile. That's odd.`); + } + } catch (err) { + log.warn(`Trying to fetch member state or profile for ${event.sender} failed`, err); } let body: string = "";