Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
V4NSH4J
GitHub Repository: V4NSH4J/discord-mass-DM-GO
Path: blob/main/instance/extra.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 instance
8
9
import (
10
"bytes"
11
b64 "encoding/base64"
12
"encoding/json"
13
"fmt"
14
"io/ioutil"
15
"strings"
16
"time"
17
18
"net/url"
19
20
gohttp "net/http"
21
http "github.com/Danny-Dasilva/fhttp"
22
23
"github.com/V4NSH4J/discord-mass-dm-GO/utilities"
24
)
25
26
func GetReactions(channel string, message string, token string, emoji string, after string) ([]string, error) {
27
encodedID := url.QueryEscape(emoji)
28
site := "https://discord.com/api/v9/channels/" + channel + "/messages/" + message + "/reactions/" + encodedID + "?limit=100"
29
if after != "" {
30
site += "&after=" + after
31
}
32
33
req, err := gohttp.NewRequest("GET", site, nil)
34
if err != nil {
35
return nil, err
36
}
37
req.Header.Add("Authorization", token)
38
39
resp, err := gohttp.DefaultClient.Do(req)
40
if err != nil {
41
return nil, err
42
}
43
body, err := ioutil.ReadAll(resp.Body)
44
if err != nil {
45
return nil, err
46
}
47
48
var reactions []Reactionx
49
50
fmt.Println(string(body))
51
err = json.Unmarshal(body, &reactions)
52
if err != nil {
53
return nil, err
54
}
55
var UIDS []string
56
for i := 0; i < len(reactions); i++ {
57
UIDS = append(UIDS, reactions[i].ID)
58
}
59
60
return UIDS, nil
61
}
62
63
func (in *Instance) ContextProperties(invite, cookie string) (string, error) {
64
site := "https://discord.com/api/v9/invites/" + invite + "?inputValue=" + invite + "&with_counts=true&with_expiration=true"
65
req, err := http.NewRequest("GET", site, nil)
66
if err != nil {
67
return "", err
68
}
69
req = in.xContextPropertiesHeaders(req, cookie)
70
resp, err := in.Client.Do(req)
71
if err != nil {
72
return "", err
73
}
74
if resp.StatusCode != 200 {
75
return "", fmt.Errorf("Error while getting invite context %v", resp.StatusCode)
76
}
77
body, err := utilities.ReadBody(*resp)
78
if err != nil {
79
return "", err
80
}
81
if !strings.Contains(string(body), "guild") && !strings.Contains(string(body), "id") && !strings.Contains(string(body), "channel") && !strings.Contains(string(body), "code") {
82
return "", fmt.Errorf("Error while getting invite context %v", resp.StatusCode)
83
}
84
var guildInfo map[string]interface{}
85
err = json.Unmarshal(body, &guildInfo)
86
if err != nil {
87
return "", err
88
}
89
guildID := (guildInfo["guild"].(map[string]interface{}))["id"].(string)
90
channelID := (guildInfo["channel"].(map[string]interface{}))["id"].(string)
91
channelType := (guildInfo["channel"].(map[string]interface{}))["type"].(float64)
92
x, err := XContextGen(guildID, channelID, channelType)
93
if err != nil {
94
return "", err
95
}
96
return x, nil
97
98
}
99
100
func XContextGen(guildID string, channelID string, ChannelType float64) (string, error) {
101
xcontext := XContext{
102
Location: "Join Guild",
103
LocationGuildID: guildID,
104
LocationChannelID: channelID,
105
LocationChannelType: ChannelType,
106
}
107
jsonData, err := json.Marshal(xcontext)
108
if err != nil {
109
return "", err
110
}
111
Enc := b64.StdEncoding.EncodeToString(jsonData)
112
return Enc, nil
113
114
}
115
116
func Bypass(client *http.Client, serverid string, token string, invite string) error {
117
// First we require to get all the rules to send in the request
118
site := "https://discord.com/api/v9/guilds/" + serverid + "/member-verification?with_guild=false&invite_code=" + invite
119
req, err := http.NewRequest("GET", site, nil)
120
if err != nil {
121
return err
122
}
123
req.Header.Add("Authorization", token)
124
resp, err := client.Do(CommonHeaders(req))
125
if err != nil {
126
return err
127
}
128
129
body, err := utilities.ReadBody(*resp)
130
if err != nil {
131
return err
132
}
133
var bypassInfo bypassInformation
134
err = json.Unmarshal(body, &bypassInfo)
135
if err != nil {
136
return err
137
}
138
139
// Now we have all the rules, we can send the request along with our response
140
for i := 0; i < len(bypassInfo.FormFields); i++ {
141
// We set the response to true because we accept the terms as the good TOS followers we are
142
bypassInfo.FormFields[i].Response = true
143
}
144
145
jsonData, err := json.Marshal(bypassInfo)
146
if err != nil {
147
return err
148
}
149
url := "https://discord.com/api/v9/guilds/" + serverid + "/requests/@me"
150
151
req, err = http.NewRequest("PUT", url, strings.NewReader(string(jsonData)))
152
if err != nil {
153
utilities.LogErr("Error while making http request %v \n", err)
154
return err
155
}
156
157
req.Header.Set("authorization", token)
158
resp, err = client.Do(CommonHeaders(req))
159
if err != nil {
160
utilities.LogErr("Error while sending HTTP request bypass %v \n", err)
161
return err
162
}
163
body, err = utilities.ReadBody(*resp)
164
if err != nil {
165
utilities.LogErr("[%v] Error while reading body %v \n", time.Now().Format("15:04:05"), err)
166
return err
167
}
168
169
if resp.StatusCode == 201 || resp.StatusCode == 204 {
170
utilities.LogSuccess("[%v] Successfully bypassed token %v", time.Now().Format("15:04:05"), token)
171
} else {
172
utilities.LogErr("[%v] Failed to bypass Token %v %v %v", time.Now().Format("15:04:05"), token, resp.StatusCode, string(body))
173
}
174
return nil
175
}
176
177
func (in *Instance) Invite(Code string) error {
178
var solvedKey string
179
var payload invitePayload
180
var rqData string
181
var rqToken string
182
var j int
183
var reported []string
184
for i := 0; i < in.Config.CaptchaSettings.MaxCaptchaInv; i++ {
185
if solvedKey == "" || in.Config.CaptchaSettings.CaptchaAPI == "" {
186
payload = invitePayload{}
187
} else {
188
payload = invitePayload{
189
CaptchaKey: solvedKey,
190
RqToken: rqToken,
191
}
192
}
193
payload, err := json.Marshal(payload)
194
if err != nil {
195
utilities.LogErr("error while marshalling payload %v", err)
196
continue
197
}
198
199
cookie, err := in.GetCookieString()
200
if err != nil {
201
utilities.LogErr("[%v] Error while Getting cookies: %v", time.Now().Format("15:04:05"), err)
202
continue
203
}
204
XContext, err := in.ContextProperties(Code, cookie)
205
if err != nil {
206
XContext = ""
207
}
208
url := fmt.Sprintf("https://discord.com/api/v9/invites/%s", Code)
209
req, err := http.NewRequest("POST", url, strings.NewReader(string(payload)))
210
if err != nil {
211
utilities.LogErr("Error while making http request %v \n", err)
212
continue
213
}
214
215
req = in.inviteHeaders(req, cookie, XContext)
216
217
resp, err := in.Client.Do(req)
218
if err != nil {
219
utilities.LogErr("Error while sending HTTP request %v \n", err)
220
continue
221
}
222
223
body, err := utilities.ReadBody(*resp)
224
if err != nil {
225
utilities.LogErr("Error while reading body %v \n", err)
226
continue
227
}
228
if strings.Contains(string(body), "captcha_sitekey") {
229
if j > 1 {
230
if in.Config.CaptchaSettings.CaptchaAPI == "anti-captcha.com" && in.LastID != 0 && !utilities.Contains(reported, string(in.LastID)) {
231
reported = append(reported, string(in.LastID))
232
err := in.ReportIncorrectRecaptcha()
233
if err != nil {
234
utilities.LogErr("[%v] Error while reporting incorrect hcaptcha: %v", time.Now().Format("15:04:05"), err)
235
} else {
236
utilities.LogSuccess("[%v] Succesfully reported incorrect hcaptcha [%v]", time.Now().Format("15:04:05"), in.LastID)
237
}
238
}
239
}
240
var resp map[string]interface{}
241
err = json.Unmarshal(body, &resp)
242
if err != nil {
243
utilities.LogErr("[%v] Error while Unmarshalling body: %v", time.Now().Format("15:04:05"), err)
244
continue
245
}
246
cap := resp["captcha_sitekey"].(string)
247
if strings.Contains(string(body), "captcha_rqdata") {
248
rqData = resp["captcha_rqdata"].(string)
249
}
250
if strings.Contains(string(body), "captcha_rqtoken") {
251
rqToken = resp["captcha_rqtoken"].(string)
252
}
253
if in.Config.CaptchaSettings.CaptchaAPI == "" && in.Config.CaptchaSettings.CaptchaAPI != "invisifox.com"{
254
utilities.LogErr("Captcha detected but no API key provided %v", in.CensorToken())
255
break
256
} else {
257
utilities.CaptchaDetected(in.CensorToken(), cap)
258
}
259
solvedKey, err = in.SolveCaptcha(cap, cookie, rqData, rqToken, "https://discord.com/channels/@me")
260
if err != nil {
261
utilities.LogErr("[%v] Error while Solving Captcha: %v", time.Now().Format("15:04:05"), err)
262
continue
263
}
264
j++
265
continue
266
}
267
if resp.StatusCode == 429 && strings.Contains(string(body), "1015") {
268
utilities.LogErr("Cloudflare Error 1015 - Your IP is being Rate Limited. Use proxies. If you already are, make sure proxy_from_file is enabled in your config")
269
break
270
}
271
272
var Join joinresponse
273
err = json.Unmarshal(body, &Join)
274
if err != nil {
275
utilities.LogErr("Error while unmarshalling body %v %v\n", err, string(body))
276
return err
277
}
278
if resp.StatusCode == 200 {
279
utilities.LogSuccess("%v joined guild %v", in.CensorToken(), Code)
280
if Join.VerificationForm {
281
if len(Join.GuildObj.ID) != 0 {
282
Bypass(in.Client, Join.GuildObj.ID, in.Token, Code)
283
}
284
}
285
}
286
if resp.StatusCode != 200 {
287
utilities.LogErr("[%v] %v Failed to join guild %v", time.Now().Format("15:04:05"), resp.StatusCode, string(body))
288
}
289
return nil
290
291
}
292
return fmt.Errorf("max retries exceeded")
293
294
}
295
296
func (in *Instance) Leave(serverid string) int {
297
url := "https://discord.com/api/v9/users/@me/guilds/" + serverid
298
json_data := "{\"lurking\":false}"
299
req, err := http.NewRequest(http.MethodDelete, url, bytes.NewBuffer([]byte(json_data)))
300
if err != nil {
301
utilities.LogErr("Error: %s", err)
302
return 0
303
}
304
cookie, err := in.GetCookieString()
305
if err != nil {
306
return 0
307
}
308
req.Header.Set("authorization", in.Token)
309
req.Header.Set("Cookie", cookie)
310
resp, errq := in.Client.Do(CommonHeaders(req))
311
if errq != nil {
312
fmt.Println(errq)
313
return 0
314
}
315
return resp.StatusCode
316
}
317
318
func (in *Instance) React(channelID string, MessageID string, Emoji string) error {
319
encodedID := url.QueryEscape(Emoji)
320
site := "https://discord.com/api/v9/channels/" + channelID + "/messages/" + MessageID + "/reactions/" + encodedID + "/@me"
321
req, err := http.NewRequest("PUT", site, nil)
322
if err != nil {
323
return err
324
}
325
cookie, err := in.GetCookieString()
326
if err != nil {
327
return fmt.Errorf("error while getting cookie %v", err)
328
}
329
resp, err := in.Client.Do(in.AtMeHeaders(req, cookie))
330
if err != nil {
331
return err
332
}
333
if resp.StatusCode == 204 {
334
return nil
335
}
336
337
return fmt.Errorf("%s", resp.Status)
338
}
339
340
func (in *Instance) Friend(Username string, Discrim int) (*http.Response, error) {
341
342
url := "https://discord.com/api/v9/users/@me/relationships"
343
344
fr := friendRequest{Username, Discrim}
345
jsonx, err := json.Marshal(&fr)
346
if err != nil {
347
return &http.Response{}, err
348
}
349
350
req, err := http.NewRequest("POST", url, strings.NewReader(string(jsonx)))
351
if err != nil {
352
return &http.Response{}, err
353
}
354
cookie, err := in.GetCookieString()
355
if err != nil {
356
return &http.Response{}, fmt.Errorf("error while getting cookie %v", err)
357
}
358
359
resp, err := in.Client.Do(in.AtMeHeaders(req, cookie))
360
361
if err != nil {
362
return &http.Response{}, err
363
}
364
return resp, nil
365
366
}
367
368
func FindMessage(channel string, messageid string, token string) (string, error) {
369
url := "https://discord.com/api/v9/channels/" + channel + "/messages?limit=1&around=" + messageid
370
req, err := gohttp.NewRequest("GET", url, nil)
371
if err != nil {
372
return "", err
373
}
374
375
req.Header.Set("Authorization", token)
376
377
client := gohttp.DefaultClient
378
resp, err := client.Do(req)
379
if err != nil {
380
return "", err
381
}
382
defer resp.Body.Close()
383
var message []Message
384
body, err := ioutil.ReadAll(resp.Body)
385
if err != nil {
386
return "", err
387
}
388
389
err = json.Unmarshal(body, &message)
390
if err != nil {
391
fmt.Println(string(body))
392
return "", err
393
}
394
msg, err := json.Marshal(message[0])
395
if err != nil {
396
fmt.Println(string(body))
397
return "", err
398
}
399
return string(msg), nil
400
}
401
402
func GetRxn(channel string, messageid string, token string) (Message, error) {
403
url := "https://discord.com/api/v9/channels/" + channel + "/messages?limit=1&around=" + messageid
404
req, err := gohttp.NewRequest("GET", url, nil)
405
if err != nil {
406
return Message{}, err
407
}
408
409
req.Header.Set("Authorization", token)
410
411
client := gohttp.DefaultClient
412
resp, err := client.Do(req)
413
if err != nil {
414
return Message{}, err
415
}
416
defer resp.Body.Close()
417
418
var message []Message
419
body, err := ioutil.ReadAll(resp.Body)
420
fmt.Println(string(body))
421
if err != nil {
422
return Message{}, err
423
}
424
425
err = json.Unmarshal(body, &message)
426
if err != nil {
427
return Message{}, err
428
}
429
430
return message[0], nil
431
}
432
433
func (in *Instance) ServerCheck(serverid string) (int, error) {
434
url := "https://discord.com/api/v9/guilds/" + serverid
435
req, err := http.NewRequest("GET", url, nil)
436
if err != nil {
437
return -1, err
438
}
439
440
req.Header.Set("Authorization", in.Token)
441
442
client := in.Client
443
resp, err := client.Do(req)
444
if err != nil {
445
return -1, err
446
}
447
defer resp.Body.Close()
448
449
return resp.StatusCode, nil
450
}
451
452
func (in *Instance) EndRelation(snowflake string) (int, error) {
453
link := fmt.Sprintf("https://discord.com/api/v9/users/@me/relationships/%s", snowflake)
454
req, err := http.NewRequest("DELETE", link, nil)
455
if err != nil {
456
return -1, err
457
}
458
cookies, err := in.GetCookieString()
459
if err != nil {
460
return -1, err
461
}
462
req = in.AtMeHeaders(req, cookies)
463
resp, err := in.Client.Do(req)
464
if err != nil {
465
return -1, err
466
}
467
return resp.StatusCode, nil
468
}
469
470
func (in *Instance) PressButton(actionRow, button int, guildID string, msg Message) (int, error) {
471
site := "https://discord.com/api/v9/interactions"
472
data := map[string]interface{}{"component_type": msg.Components[actionRow].Buttons[button].Type, "custom_id": msg.Components[actionRow].Buttons[button].CustomID, "hash": msg.Components[actionRow].Buttons[button].Hash}
473
values := map[string]interface{}{"application_id": msg.Author.ID, "channel_id": msg.ChannelID, "type": 3, "data": data, "guild_id": guildID, "message_flags": msg.Flags, "message_id": msg.MessageId, "nonce": utilities.Snowflake(), "session_id": in.Ws.sessionID}
474
jsonData, err := json.Marshal(values)
475
if err != nil {
476
return -1, err
477
}
478
req, err := http.NewRequest("POST", site, strings.NewReader(string(jsonData)))
479
if err != nil {
480
return -1, err
481
}
482
cookies, err := in.GetCookieString()
483
if err != nil {
484
return -1, err
485
}
486
req = in.AtMeHeaders(req, cookies)
487
resp, err := in.Client.Do(req)
488
if err != nil {
489
return -1, err
490
}
491
defer resp.Body.Close()
492
body, err := ioutil.ReadAll(resp.Body)
493
if err != nil {
494
return -1, err
495
}
496
fmt.Println(string(body))
497
return resp.StatusCode, nil
498
499
}
500
501