-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreactionAdd.go
64 lines (50 loc) · 1.34 KB
/
reactionAdd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"github.com/bwmarrin/discordgo"
"github.com/rs/zerolog/log"
)
func reactionAdd(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
if r.Emoji.Name != "🗑️" {
return
}
proceed := false
channelID := r.ChannelID
channel, err := s.State.Channel(r.ChannelID)
msg, err := s.ChannelMessage(r.ChannelID, r.MessageID)
if err != nil {
s.ChannelMessageSendReply(r.ChannelID, "Error getting channel: "+err.Error(), msg.Reference())
return
}
if channel.IsThread() {
channelID = channel.ParentID
}
for _, channel := range k.Strings("discord.msgChan") {
if channelID == channel {
proceed = true
}
}
if !proceed {
return
}
if err != nil {
log.Error().Err(err).Msg("Failed to get message")
return
}
originalMsg, err := s.ChannelMessage(r.ChannelID, msg.MessageReference.MessageID)
if err != nil {
log.Error().Err(err).Msg("Failed to get original message")
return
}
if r.UserID == originalMsg.Author.ID {
log.Info().
Str("user", originalMsg.Author.Username).
Str("msgID", originalMsg.ID).
Str("channel", originalMsg.ChannelID).
Msg("User deleted message")
err = s.ChannelMessageDelete(msg.ChannelID, msg.ID)
s.ChannelMessageSendReply(msg.ChannelID, "Deleted per your request", originalMsg.Reference())
if err != nil {
log.Error().Err(err).Msg("Failed to delete message")
}
}
}