-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblacklist.go
45 lines (39 loc) · 1.08 KB
/
blacklist.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
package main
import (
"encoding/json"
"io/ioutil"
"log"
"strings"
"github.com/bwmarrin/discordgo"
)
type Blacklist struct {
Roles []string `json:"roles"`
}
func selfEsteem(s *discordgo.Session, e *discordgo.GuildRoleUpdate) {
// Check if enabled / file exists
if config.Modules.SelfEsteem != true || config.BlacklistData == "" {
return
}
// Read from JSON list file
data, err := ioutil.ReadFile(config.BlacklistData)
if err != nil {
log.Println("[Error][Self Esteem] Failed to open file:", err)
return
}
// Convert to go native type
var blacklist Blacklist
err = json.Unmarshal(data, &blacklist)
if err != nil {
log.Println("[Error][Self Esteem] Could not unmarshal JSON data:", err)
return
}
// Iterate through entries in blacklist. If the role in event matches, delete.
for _, role := range blacklist.Roles {
if strings.Contains(strings.ToLower(e.Role.Name), role) {
err := s.GuildRoleDelete(e.GuildID, e.Role.ID)
if err != nil {
log.Println("[Error][Self Esteem] Could not delete role:", err)
}
}
}
}