diff --git a/discord.go b/discord.go index 60aae23..721423b 100644 --- a/discord.go +++ b/discord.go @@ -133,3 +133,31 @@ func startDiscordBot() { } defer dg.Close() } + +func refreshLatestUpdate(dg *discordgo.Session) { + updateMessages, err := dg.ChannelMessages(discordUpdateChannel, 1, "", "", "") + if err != nil { + log.Printf("failed to fetch the latest update: %s", err) + return + } + + if len(updateMessages) > 0 { + m := updateMessages[0] + if len(m.Attachments) > 0 { + currentUpdate = Update{ + ID: m.ID, + GuildID: m.GuildID, + ChannelID: m.ChannelID, + CreatedTs: m.Timestamp.UnixMilli(), + EditedTs: m.Timestamp.UnixMilli(), + AuthorID: m.Author.ID, + AuthorName: m.Author.Username, + AuthorImage: m.Author.AvatarURL(""), + Content: m.Content, + CleanContent: m.ContentWithMentionsReplaced(), + Image: m.Attachments[0].URL, + } + log.Printf("updated latest update: %s", currentUpdate.Content) + } + } +} diff --git a/main.go b/main.go index 8cc3a62..d992194 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ func backgroundTask() { for { time.Sleep(15 * time.Minute) getRecentsCommits() + refreshLatestUpdate(dg) } }