Skip to content

Commit

Permalink
Add messageIsForkOf, which given a message reports if it's a fork of …
Browse files Browse the repository at this point in the history
…another message. Part of #34.
  • Loading branch information
jkomoros committed Jun 14, 2021
1 parent 4a59268 commit 7003474
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,22 @@ func urlForMessage(message *discordgo.Message) string {
return "https://discord.com/channels/" + message.GuildID + "/" + message.ChannelID + "/" + message.ID
}

//messageIsForkOf returns a non-zero-length string of the original message ID if
//the given message appears to be a forked message
func messageIsForkOf(message *discordgo.Message) string {
if len(message.Embeds) == 0 {
return ""
}
for _, embed := range message.Embeds {
if embed.Description != FORKED_MESSAGE_LINK_TEXT {
continue
}
urlPieces := strings.Split(embed.URL, "/")
return urlPieces[len(urlPieces)-1]
}
return ""
}

func messageEmbedAuthorForMessage(message *discordgo.Message) *discordgo.MessageEmbedAuthor {
if message.Author == nil {
return nil
Expand All @@ -187,7 +203,8 @@ func (b *bot) forkMessage(sourceChannelID, sourceMessageID, targetChannelID stri
if err != nil {
return fmt.Errorf("couldn't fetch message: %v", err)
}

//Note: if you change this, also change messageIsFork to be able to detect
//it!
embed := &discordgo.MessageEmbed{
Title: FORKED_MESSAGE_LINK_TEXT,
Description: msg.Content,
Expand Down

0 comments on commit 7003474

Please sign in to comment.