-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.go
104 lines (82 loc) · 2.62 KB
/
handlers.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"fmt"
"github.com/bwmarrin/discordgo"
)
func getCurrentMembers(s *discordgo.Session, event *discordgo.Ready) {
for _, guilds := range event.Guilds {
err := s.RequestGuildMembers(guilds.ID, "", 0, "", false)
if err != nil {
fmt.Println("Error requesting guild members:", err)
}
}
}
func checkCurrentMembers(s *discordgo.Session, event *discordgo.GuildMembersChunk) {
real, err := s.GuildMember(event.GuildID, doNotImpersonateID)
if err != nil {
fmt.Println("Error finding the user who must not be impersonated:", err)
return
}
guild, err := s.Guild(event.GuildID)
if err != nil {
fmt.Println("Error finding guild:", err)
return
}
fmt.Printf("Searching server %q for impersonators of %v\n", guild.Name, real.User.String())
var count int
for _, member := range event.Members {
if !isCaseInsensitiveNameMatch(member, real) {
continue
}
if member.User.ID == doNotImpersonateID {
continue
}
err := s.GuildBanCreate(event.GuildID, member.User.ID, 7) // bans user and deletes the last 7 (max) days of comments from this user
if err != nil {
fmt.Println("Error banning impersonator:", err)
continue
}
fmt.Println("Banned ", member.User.String())
count++
}
fmt.Printf("Initial search complete. Banned %d users.\n\n", count)
fmt.Printf("Listening for name changes and new joins...\n")
}
func checkMemberUpdateEvent(s *discordgo.Session, event *discordgo.GuildMemberUpdate) {
real, err := s.GuildMember(event.GuildID, doNotImpersonateID)
if err != nil {
fmt.Println("Error finding the user who must not be impersonated:", err)
return
}
if !isCaseInsensitiveNameMatch(event.Member, real) {
return
}
if event.Member.User.ID == doNotImpersonateID {
return
}
err = s.GuildBanCreate(event.GuildID, event.Member.User.ID, 7) // bans user and deletes the last 7 (max) days of comments from this user
if err != nil {
fmt.Println("Error banning impersonator:", err)
return
}
fmt.Println("Banned", event.Member.User.String())
}
func checkNewMemberJoin(s *discordgo.Session, event *discordgo.GuildMemberAdd) {
real, err := s.GuildMember(event.GuildID, doNotImpersonateID)
if err != nil {
fmt.Println("Error finding the user who must not be impersonated:", err)
return
}
if !isCaseInsensitiveNameMatch(event.Member, real) {
return
}
if event.Member.User.ID == doNotImpersonateID {
return
}
err = s.GuildBanCreate(event.GuildID, event.Member.User.ID, 7) // bans user and deletes the last 7 (max) days of comments from this user
if err != nil {
fmt.Println("Error banning impersonator:", err)
return
}
fmt.Println("Banned", event.Member.User.String())
}