Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
V4NSH4J
GitHub Repository: V4NSH4J/discord-mass-DM-GO
Path: blob/main/discord/guild_leaver.go
310 views
1
// Copyright (C) 2021 github.com/V4NSH4J
2
//
3
// This source code has been released under the GNU Affero General Public
4
// License v3.0. A copy of this license is available at
5
// https://www.gnu.org/licenses/agpl-3.0.en.html
6
7
package discord
8
9
import (
10
"fmt"
11
"os"
12
"os/exec"
13
"time"
14
15
"github.com/V4NSH4J/discord-mass-dm-GO/instance"
16
"github.com/V4NSH4J/discord-mass-dm-GO/utilities"
17
"github.com/zenthangplus/goccm"
18
)
19
20
func LaunchGuildLeaver() {
21
cfg, instances, err := instance.GetEverything()
22
if err != nil {
23
utilities.LogErr("Error while getting instances or config %s", err)
24
return
25
}
26
var LeftCount, TotalCount, FailedCount int
27
title := make(chan bool)
28
go func() {
29
Out:
30
for {
31
select {
32
case <-title:
33
break Out
34
default:
35
cmd := exec.Command("cmd", "/C", "title", fmt.Sprintf(`DMDGO [%v Successfully Left, %v Failed, %v Unprocessed]`, LeftCount, FailedCount, TotalCount-LeftCount-FailedCount))
36
_ = cmd.Run()
37
}
38
39
}
40
}()
41
var tokenFile, successFile, failedFile string
42
if cfg.OtherSettings.Logs {
43
path := fmt.Sprintf(`logs/guild_leaver/DMDGO-GL-%s-%s`, time.Now().Format(`2006-01-02 15-04-05`), utilities.RandStringBytes(5))
44
err := os.MkdirAll(path, 0755)
45
if err != nil && !os.IsExist(err) {
46
utilities.LogErr("Error creating logs directory: %s", err)
47
utilities.ExitSafely()
48
}
49
tokenFileX, err := os.Create(fmt.Sprintf(`%s/token.txt`, path))
50
if err != nil {
51
utilities.LogErr("Error creating token file: %s", err)
52
utilities.ExitSafely()
53
}
54
tokenFileX.Close()
55
successFileX, err := os.Create(fmt.Sprintf(`%s/success.txt`, path))
56
if err != nil {
57
utilities.LogErr("Error creating success file: %s", err)
58
utilities.ExitSafely()
59
}
60
successFileX.Close()
61
failedFileX, err := os.Create(fmt.Sprintf(`%s/failed.txt`, path))
62
if err != nil {
63
utilities.LogErr("Error creating failed file: %s", err)
64
utilities.ExitSafely()
65
}
66
failedFileX.Close()
67
tokenFile, successFile, failedFile = tokenFileX.Name(), successFileX.Name(), failedFileX.Name()
68
for i := 0; i < len(instances); i++ {
69
instances[i].WriteInstanceToFile(tokenFile)
70
}
71
}
72
threads := utilities.UserInputInteger("Enter number of threads (0 for unlimited):")
73
if threads > len(instances) {
74
threads = len(instances)
75
}
76
if threads == 0 {
77
threads = len(instances)
78
}
79
delay := utilities.UserInputInteger("Enter delay between leaves on each thread (in seconds):")
80
serverid := utilities.UserInput("Enter server ID:")
81
c := goccm.New(threads)
82
for i := 0; i < len(instances); i++ {
83
time.Sleep(time.Duration(cfg.DirectMessage.Offset) * time.Millisecond)
84
c.Wait()
85
TotalCount++
86
go func(i int) {
87
p := instances[i].Leave(serverid)
88
if p == 0 {
89
utilities.LogFailed("Error while leaving on token %v", instances[i].CensorToken())
90
if cfg.OtherSettings.Logs {
91
instances[i].WriteInstanceToFile(failedFile)
92
}
93
FailedCount++
94
}
95
if p == 200 || p == 204 {
96
utilities.LogSuccess("Successfully left on token %v", instances[i].CensorToken())
97
if cfg.OtherSettings.Logs {
98
instances[i].WriteInstanceToFile(successFile)
99
}
100
LeftCount++
101
} else {
102
utilities.LogFailed("Invalid Status code %v while leaving on token %v", p, instances[i].CensorToken())
103
if cfg.OtherSettings.Logs {
104
instances[i].WriteInstanceToFile(failedFile)
105
}
106
FailedCount++
107
}
108
time.Sleep(time.Duration(delay) * time.Second)
109
c.Done()
110
}(i)
111
}
112
c.WaitAllDone()
113
title <- true
114
utilities.LogSuccess("All Threads Completed!")
115
}
116
117