Skip to content

Commit

Permalink
feat: have the bot self react with and X and delete its own message o…
Browse files Browse the repository at this point in the history
…n reaction add
  • Loading branch information
Karitham committed Apr 9, 2021
1 parent 66ec31d commit 0537ce9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions bot/discordPages.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bot

import (
"fmt"
"log"
"time"

"github.com/bwmarrin/discordgo"
Expand Down Expand Up @@ -69,6 +70,13 @@ func formatForMessage(page *ReactionListener) string {

// ReactionListen listens for the reactions for a previously sent embed.
func ReactionListen(session *discordgo.Session, reaction *discordgo.MessageReactionAdd) {
// Shortcut to delete self embed
if reaction.UserID != session.State.Ready.User.ID && reaction.Emoji.Name == destroyEmoji {
if err := session.ChannelMessageDelete(reaction.ChannelID, reaction.MessageID); err != nil {
log.Printf("could not delete message: %s", err)
}
}

// if the message being reacted to is in the reaction map
if _, ok := pageListeners[reaction.MessageID]; ok {
// validating that the user reacting is indeed the user that owns the listener
Expand Down
11 changes: 10 additions & 1 deletion bot/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bot

import (
"fmt"
"log"
"strings"
"time"

Expand Down Expand Up @@ -42,7 +43,15 @@ func HandleDoc(s *discordgo.Session, m *discordgo.MessageCreate, prefix string)
if msg == nil {
msg = errResponse("No results found, possibly an internal error.")
}
s.ChannelMessageSendEmbed(m.ChannelID, msg)
new_m, err := s.ChannelMessageSendEmbed(m.ChannelID, msg)
if err != nil {
log.Printf("could not send message: %s", err)
}

err = s.MessageReactionAdd(new_m.ChannelID, new_m.ID, destroyEmoji)
if err != nil {
log.Printf("could not send message: %s", err)
}
}

// queryResponse generates the response for a query.
Expand Down

0 comments on commit 0537ce9

Please sign in to comment.