-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewMsg.go
More file actions
78 lines (63 loc) · 1.58 KB
/
newMsg.go
File metadata and controls
78 lines (63 loc) · 1.58 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"strings"
"github.com/bwmarrin/discordgo"
"github.com/rs/zerolog/log"
)
func newMsg(s *discordgo.Session, m *discordgo.MessageCreate) {
proceed := false
channelID := m.ChannelID
channel, err := s.State.Channel(m.ChannelID)
if err != nil {
s.ChannelMessageSendReply(m.ChannelID, "Error getting channel: "+err.Error(), m.Reference())
return
}
if channel.IsThread() {
channelID = channel.ParentID
}
for _, channel := range k.Strings("discord.msgChan") {
if channelID == channel {
proceed = true
}
}
if !proceed {
return
}
if m.Author.ID == s.State.User.ID {
return
}
if m.Content == "lsckpt!" {
lsCkpt(s, m)
}
if len(m.Content) < 8 {
return
}
if m.Content[:8] == "diffuse!" {
for _, user := range k.Strings("discord.bannedUsers") {
if m.Author.ID == user {
s.ChannelMessageSendReply(m.ChannelID, "Banned user detected, dropping request", m.Reference())
log.Info().Str("user", m.Author.Username).Msg("Banned user detected, dropping request")
return
}
}
msg := m.Content[8:]
if msg[0] == ' ' {
msg = msg[1:]
}
user := m.Author.Username + "#" + m.Author.Discriminator
for _, word := range k.Strings("discord.bannedWords") {
if strings.Contains(msg, word) {
log.Warn().
Str("user", user).
Str("msg", msg).
Str("word", word).
Msg("Banned word detected")
if _, err := s.ChannelMessageSendReply(m.ChannelID, "Banned word detected, dropping request", m.Reference()); err != nil {
log.Error().Err(err).Msg("Failed to send message")
}
return
}
}
draw(s, m, msg)
}
}