From 1a660806cb1e2915eba0934fa04483a3df552255 Mon Sep 17 00:00:00 2001 From: Gary Kramlich Date: Mon, 2 May 2022 12:40:19 -0500 Subject: [PATCH] Fix a crash caused uncached open graphs previews If the discord open graph stuff has a cached preview it'll pass it along on the initial MessageCreate message. However, if it doesn't, it'll later send a MessageUpdate with the new embed and a message that doesn't have an author set as it's coming from the server. --- bridge/portal.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bridge/portal.go b/bridge/portal.go index 36f0e28..6eb7c42 100644 --- a/bridge/portal.go +++ b/bridge/portal.go @@ -487,6 +487,23 @@ func (p *Portal) handleDiscordMessagesUpdate(user *User, msg *discordgo.Message) return } + // There's a few scenarios where the author is nil but I haven't figured + // them all out yet. + if msg.Author == nil { + // If the server has to lookup opengraph previews it'll send the + // message through without the preview and then add the preview later + // via a message update. However, when it does this there is no author + // as it's just the server, so for the moment we'll ignore this to + // avoid a crash. + if len(msg.Embeds) > 0 { + p.log.Debugln("ignoring update for opengraph attachment") + + return + } + + p.log.Errorfln("author is nil: %#v", msg) + } + intent := p.bridge.GetPuppetByID(msg.Author.ID).IntentFor(p) existing := p.bridge.db.Message.GetByDiscordID(p.Key, msg.ID)