diff --git a/coldbrewcrew/iworkout/discord.go b/coldbrewcrew/iworkout/discord.go index 4fb0d78..665fb03 100644 --- a/coldbrewcrew/iworkout/discord.go +++ b/coldbrewcrew/iworkout/discord.go @@ -17,18 +17,6 @@ const botToken = "NzA5Nzk3NTE4MDMyMjQwNzUx.XryNQQ.vx4n9mcdsJr8bFCz8pOgrr2YD0A" const iworkoutChannelID = "492391546411417620" -// In-memory caches of data retrieved through the API. -var ( - // users is a map of user ID to user. - users = map[string]discordgo.User{} - - // messages is a two-dimensional map of channel ID to message ID to message. - messages = map[string]map[string]discordgo.Message{} - - // reactions is a map of message ID to a "set" of users who reacted to that message (with any reaction). - reactions = map[string]map[string]struct{}{} -) - // init is called automatically on boot. func init() { discord, err := discordgo.New(fmt.Sprintf("Bot %s", botToken)) @@ -57,7 +45,7 @@ func handleReactionAdd(s *discordgo.Session, r *discordgo.MessageReactionAdd) { reactions[m.ID][u.ID] = struct{}{} - fmt.Printf("%s reaction added: \"%s\" had a %s added by %v\n", logPrefix, m.Content, r.Emoji.Name, u) + fmt.Printf("%s reaction added: \"%s\" had a %s added by %v\n", logPrefix, m.Content, r.Emoji.Name, u.Username) } // handleReactionRemove is called by discordgo when an emoji reaction is removed from a message. @@ -67,7 +55,7 @@ func handleReactionRemove(s *discordgo.Session, r *discordgo.MessageReactionRemo delete(reactions[m.ID], u.ID) - fmt.Printf("%s reaction removed: \"%s\" had a %s removed by %v\n", logPrefix, m.Content, r.Emoji.Name, u) + fmt.Printf("%s reaction removed: \"%s\" had a %s removed by %v\n", logPrefix, m.Content, r.Emoji.Name, u.Username) } // fetchUser gets a user through the Discord API by ID and caches it, if it is not already stored in the local cache. @@ -130,6 +118,7 @@ func buildMessagesState(s *discordgo.Session, channelID string) { } messages[msg.ChannelID][msg.ID] = *msg + users[msg.Author.ID] = *msg.Author if earliest.ID == "" { earliest = *msg diff --git a/coldbrewcrew/iworkout/message.go b/coldbrewcrew/iworkout/message.go new file mode 100644 index 0000000..e086188 --- /dev/null +++ b/coldbrewcrew/iworkout/message.go @@ -0,0 +1,11 @@ +package iworkout + +import "github.com/bwmarrin/discordgo" + +// messages is a two-dimensional map of channel ID to message ID to message. +var messages = map[string]map[string]discordgo.Message{} + +// Messages returns all messages we've catalogued as a map of message ID to message. +func Messages() map[string]discordgo.Message { + return messages[iworkoutChannelID] +} diff --git a/coldbrewcrew/iworkout/reaction.go b/coldbrewcrew/iworkout/reaction.go new file mode 100644 index 0000000..0843f45 --- /dev/null +++ b/coldbrewcrew/iworkout/reaction.go @@ -0,0 +1,9 @@ +package iworkout + +// reactions is a map of message ID to a "set" of user IDs who reacted to that message (with any reaction). +var reactions = map[string]map[string]struct{}{} + +// Reactions returns all reactions we've catalogued as a map of message ID to a "set" of user IDs who have reacted to that message (with any emoji). +func Reactions() map[string]map[string]struct{} { + return reactions +} diff --git a/coldbrewcrew/iworkout/user.go b/coldbrewcrew/iworkout/user.go new file mode 100644 index 0000000..49cb72c --- /dev/null +++ b/coldbrewcrew/iworkout/user.go @@ -0,0 +1,11 @@ +package iworkout + +import "github.com/bwmarrin/discordgo" + +// users is a map of user ID to user. +var users = map[string]discordgo.User{} + +// Users returns all users we've catalogued as a map of user ID to user. +func Users() map[string]discordgo.User { + return users +} diff --git a/html/iworkout.html b/html/iworkout.html new file mode 100644 index 0000000..39c794a --- /dev/null +++ b/html/iworkout.html @@ -0,0 +1,109 @@ + + +
+2020-05
+ ++ Calculated from reaction emojis in Discord. +
+ +| + {{range .Users}} | {{.Username}} | {{end}} + +
|---|---|
| {{(index $.Messages $messageID).Content}} | + {{range $.Users}} ++ {{if (index $userIDSet .ID)}} + X + {{end}} + | + {{end}} +