Skip to content

Commit

Permalink
feat(handler): change to return a copy of the embed if the message co…
Browse files Browse the repository at this point in the history
…ntains only the embed (#18)
  • Loading branch information
aqyuki authored Dec 24, 2024
1 parent fc3066a commit 38f974d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
30 changes: 19 additions & 11 deletions internal/app/handler/message_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,27 @@ func (srv *CitationService) On(ctx context.Context, session *discordgo.Session,
Wrapf(err, "error occurred while fetching message information (channel_id = %s, message_id = %s)", ids.channelID, ids.messageID)
}

if !isExpandable(citationMessage) {
logger.Debug("skip processing message because it was not expandable", zap.String("message_id", message.ID))
return nil
}
var embed *discordgo.MessageEmbed

embed := emptyEmbed(citationChannel, citationMessage)
if hasContent(citationMessage) {
embed.Description = citationMessage.Content
}
if hasImage(citationMessage) {
embed.Image = &discordgo.MessageEmbedImage{
URL: citationMessage.Attachments[0].URL,
if isExpandable(citationMessage) {
logger.Debug("expandable content detected.", zap.String("message_id", message.ID))
embed = emptyEmbed(citationChannel, citationMessage)
if hasContent(citationMessage) {
embed.Description = citationMessage.Content
}
if hasImage(citationMessage) {
embed.Image = &discordgo.MessageEmbedImage{
URL: citationMessage.Attachments[0].URL,
}
}
} else if hasEmbed(citationMessage) {
logger.Debug("embed content detected.", zap.String("message_id", message.ID))
embed = citationMessage.Embeds[0]
}

if embed == nil {
logger.Debug("skip processing message because it was not contains expandable content", zap.String("message_id", message.ID))
return nil
}

replyMsg := &discordgo.MessageSend{
Expand Down
4 changes: 4 additions & 0 deletions internal/app/handler/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ func hasContent(message *discordgo.Message) bool {
func hasImage(message *discordgo.Message) bool {
return len(message.Attachments) != 0
}

func hasEmbed(message *discordgo.Message) bool {
return len(message.Embeds) != 0
}

0 comments on commit 38f974d

Please sign in to comment.