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.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user