Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
V4NSH4J
GitHub Repository: V4NSH4J/discord-mass-DM-GO
Path: blob/main/discord/reaction_adder.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
"math/rand"
12
"os"
13
"os/exec"
14
"strconv"
15
"strings"
16
"sync"
17
"time"
18
19
"github.com/V4NSH4J/discord-mass-dm-GO/instance"
20
"github.com/V4NSH4J/discord-mass-dm-GO/utilities"
21
)
22
23
func LaunchReactionAdder() {
24
utilities.PrintMenu([]string{"From Message", "Manually"})
25
choice := utilities.UserInputInteger("Select an option: ")
26
if choice != 1 && choice != 2 {
27
utilities.LogErr("Invalid option")
28
return
29
}
30
cfg, instances, err := instance.GetEverything()
31
if err != nil {
32
utilities.LogErr("Error while getting instances or config %s", err)
33
return
34
}
35
var tokenFile, successFile, failedFile string
36
if cfg.OtherSettings.Logs {
37
path := fmt.Sprintf(`logs/reaction_adder/DMDGO-RA-%s-%s`, time.Now().Format(`2006-01-02 15-04-05`), utilities.RandStringBytes(5))
38
err := os.MkdirAll(path, 0755)
39
if err != nil && !os.IsExist(err) {
40
utilities.LogErr("Error creating logs directory: %s", err)
41
utilities.ExitSafely()
42
}
43
tokenFileX, err := os.Create(fmt.Sprintf(`%s/token.txt`, path))
44
if err != nil {
45
utilities.LogErr("Error creating token file: %s", err)
46
utilities.ExitSafely()
47
}
48
tokenFileX.Close()
49
successFileX, err := os.Create(fmt.Sprintf(`%s/success.txt`, path))
50
if err != nil {
51
utilities.LogErr("Error creating success file: %s", err)
52
utilities.ExitSafely()
53
}
54
successFileX.Close()
55
failedFileX, err := os.Create(fmt.Sprintf(`%s/failed.txt`, path))
56
if err != nil {
57
utilities.LogErr("Error creating failed file: %s", err)
58
utilities.ExitSafely()
59
}
60
failedFileX.Close()
61
tokenFile, successFile, failedFile = tokenFileX.Name(), successFileX.Name(), failedFileX.Name()
62
for i := 0; i < len(instances); i++ {
63
instances[i].WriteInstanceToFile(tokenFile)
64
}
65
}
66
var TotalCount, SuccessCount, FailedCount int
67
title := make(chan bool)
68
go func() {
69
Out:
70
for {
71
select {
72
case <-title:
73
break Out
74
default:
75
cmd := exec.Command("cmd", "/C", "title", fmt.Sprintf(`DMDGO [%v Success, %v Failed, %v Unprocessed]`, SuccessCount, FailedCount, TotalCount-SuccessCount-FailedCount))
76
_ = cmd.Run()
77
}
78
79
}
80
}()
81
var wg sync.WaitGroup
82
wg.Add(len(instances))
83
if choice == 1 {
84
token := utilities.UserInput("Enter a token which can see the message: ")
85
id := utilities.UserInput("Enter the message ID: ")
86
channel := utilities.UserInput("Enter the channel ID: ")
87
msg, err := instance.GetRxn(channel, id, token)
88
if err != nil {
89
utilities.LogErr("Error while getting message %s", err)
90
return
91
}
92
var selection []string
93
if len(msg.Reactions) == 0 {
94
utilities.LogErr("Message has no reactions. React to the message to select it or use the manual option.")
95
return
96
}
97
for i := 0; i < len(msg.Reactions); i++ {
98
var j string
99
if msg.Reactions[i].Emojis.ID == "" {
100
j = msg.Reactions[i].Emojis.Name
101
} else {
102
j = fmt.Sprintf("<:%s:%s>", msg.Reactions[i].Emojis.Name, msg.Reactions[i].Emojis.ID)
103
}
104
selection = append(selection, fmt.Sprintf(`%v [%v Reacts]`, j, msg.Reactions[i].Count))
105
}
106
utilities.PrintMenu2(selection)
107
108
var emojis []int
109
x := utilities.UserInput("Select Emoji, seperate them by commas to select multiple:")
110
if !strings.Contains(x, ",") {
111
index, err := strconv.Atoi(x)
112
if err != nil {
113
utilities.LogErr("Error while converting %s to int %s", x, err)
114
return
115
}
116
emojis = append(emojis, index)
117
} else {
118
for _, v := range strings.Split(x, ",") {
119
index, err := strconv.Atoi(v)
120
if err != nil {
121
utilities.LogErr("Error while converting %s to int %s", v, err)
122
} else {
123
emojis = append(emojis, index)
124
}
125
126
}
127
}
128
var DelayBetweenReacts int
129
var RandomDelayBetweenReacts int
130
if len(emojis) > 1 {
131
DelayBetweenReacts = utilities.UserInputInteger("Enter the delay between reacts for each token in seconds: ")
132
RandomDelayBetweenReacts = utilities.UserInputInteger("Enter the random delay between reacts for each token in seconds: ")
133
} else {
134
DelayBetweenReacts = 0
135
}
136
TotalCount = len(instances) * len(emojis)
137
for i := 0; i < len(instances); i++ {
138
time.Sleep(time.Duration(cfg.DirectMessage.Offset) * time.Millisecond)
139
go func(i int) {
140
defer wg.Done()
141
for j := 0; j < len(emojis); j++ {
142
var send string
143
if msg.Reactions[emojis[j]].Emojis.ID == "" {
144
send = msg.Reactions[emojis[j]].Emojis.Name
145
146
} else if msg.Reactions[emojis[j]].Emojis.ID != "" {
147
send = msg.Reactions[emojis[j]].Emojis.Name + ":" + msg.Reactions[emojis[j]].Emojis.ID
148
}
149
err := instances[i].React(channel, id, send)
150
if err != nil {
151
utilities.LogFailed("Token %v failed to react to emoji %v %v", instances[i].CensorToken(), send, err)
152
if cfg.OtherSettings.Logs {
153
utilities.WriteLinesPath(failedFile, fmt.Sprintf(`Token %v Emoji %v Channel %v Message %v Error %v`, instances[i].CensorToken(), send, channel, id, err))
154
}
155
FailedCount++
156
} else {
157
utilities.LogSuccess("Token %v successfully reacted to emoji %v", instances[i].CensorToken(), send)
158
if cfg.OtherSettings.Logs {
159
utilities.WriteLinesPath(successFile, fmt.Sprintf(`Token %v Emoji %v Channel %v Message %v`, instances[i].CensorToken(), send, channel, id))
160
}
161
SuccessCount++
162
}
163
if DelayBetweenReacts != 0 {
164
utilities.LogInfo("Token %v sleeping for %v seconds (Base Delay)", instances[i].CensorToken(), DelayBetweenReacts)
165
time.Sleep(time.Duration(DelayBetweenReacts) * time.Second)
166
}
167
if RandomDelayBetweenReacts != 0 {
168
x := rand.Intn(RandomDelayBetweenReacts)
169
utilities.LogInfo("Token %v sleeping for %v seconds (Random Delay)", instances[i].CensorToken(), x)
170
time.Sleep(time.Second * time.Duration(x))
171
}
172
}
173
}(i)
174
}
175
wg.Wait()
176
utilities.LogSuccess("Finished All threads")
177
}
178
if choice == 2 {
179
id := utilities.UserInput("Enter the message ID: ")
180
channel := utilities.UserInput("Enter the channel ID: ")
181
var emojis []string
182
x := utilities.UserInput("Enter the emoji, seperate them by commas to select multiple. Format is emojiName or emojiName:emojiID for nitro emojis: ")
183
if !strings.Contains(x, ",") {
184
emojis = append(emojis, x)
185
} else {
186
emojis = append(emojis, strings.Split(x, ",")...)
187
}
188
var DelayBetweenReacts int
189
var RandomDelayBetweenReacts int
190
if len(emojis) > 1 {
191
DelayBetweenReacts = utilities.UserInputInteger("Enter the delay between reacts for each token in seconds: ")
192
RandomDelayBetweenReacts = utilities.UserInputInteger("Enter the random delay between reacts for each token in seconds: ")
193
} else {
194
DelayBetweenReacts = 0
195
}
196
TotalCount = len(instances) * len(emojis)
197
for i := 0; i < len(instances); i++ {
198
time.Sleep(time.Duration(cfg.DirectMessage.Offset) * time.Millisecond)
199
go func(i int) {
200
defer wg.Done()
201
for j := 0; j < len(emojis); j++ {
202
err := instances[i].React(channel, id, emojis[j])
203
if err != nil {
204
utilities.LogFailed("Token %v failed to react to emoji %v %v", instances[i].CensorToken(), emojis[j], err)
205
if cfg.OtherSettings.Logs {
206
utilities.WriteLinesPath(failedFile, fmt.Sprintf(`Token %v Emoji %v Channel %v Message %v Error %v`, instances[i].CensorToken(), emojis[j], channel, id, err))
207
}
208
FailedCount++
209
} else {
210
utilities.LogSuccess("Token %v successfully reacted to emoji %v", instances[i].CensorToken(), emojis[j])
211
if cfg.OtherSettings.Logs {
212
utilities.WriteLinesPath(successFile, fmt.Sprintf(`Token %v Emoji %v Channel %v Message %v`, instances[i].CensorToken(), emojis[j], channel, id))
213
}
214
SuccessCount++
215
}
216
if DelayBetweenReacts != 0 {
217
utilities.LogInfo("Token %v sleeping for %v seconds (Base Delay)", instances[i].CensorToken(), DelayBetweenReacts)
218
time.Sleep(time.Duration(DelayBetweenReacts) * time.Second)
219
}
220
if RandomDelayBetweenReacts != 0 {
221
x := rand.Intn(RandomDelayBetweenReacts)
222
utilities.LogInfo("Token %v sleeping for %v seconds (Random Delay)", instances[i].CensorToken(), x)
223
time.Sleep(time.Second * time.Duration(x))
224
}
225
}
226
}(i)
227
}
228
wg.Wait()
229
title <- true
230
utilities.LogSuccess("Finished All threads")
231
}
232
233
}
234
235