Skip to content

Commit

Permalink
Merge pull request #2 from usaginc/patch-3
Browse files Browse the repository at this point in the history
Update main.go
  • Loading branch information
e-lliot authored Mar 20, 2024
2 parents 792a4c4 + dd85c35 commit e0ea42c
Showing 1 changed file with 37 additions and 39 deletions.
76 changes: 37 additions & 39 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (


var (
variable string
endpoint string
gid string
variable string
endpoint string
gid string
TOKEN_AUTH string
logo = `
M""""""'YMM oo 8P
Expand All @@ -42,28 +42,36 @@ M MMMMM M M MMMMM M MMMMMMM. M
M MMMM' .M M. 'MMM' .M M. .MMM' M
M .MM MMb dMM Mb. .dM
MMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMM
`
blue = color.New(color.Bold, color.FgHiBlue)
red = color.New(color.Bold, color.FgHiRed)
yellow = color.New(color.Bold, color.FgHiYellow)
green = color.New(color.Bold, color.FgHiGreen)
`
blue = color.New(color.Bold, color.FgHiBlue)
red = color.New(color.Bold, color.FgHiRed)
yellow = color.New(color.Bold, color.FgHiYellow)
green = color.New(color.Bold, color.FgHiGreen)
)

func error_nil(err error) {
if err != nil {
panic(err)
}
}

func main() {
file, err := os.Open("token.txt")
if err != nil {
fmt.Println(err)
red.Println("ERROR: No token.txt file / read permission denied")
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
TOKEN_AUTH = scanner.Text()
}

if err := scanner.Err(); err != nil {
fmt.Println(err)

if scanner.Err() != nil {
red.Println("ERROR: token.txt read error")
return
}

clear()
red.Println(logo)
slow_print("by elliot")
Expand All @@ -73,14 +81,14 @@ func main() {
blue.Print("group id: ")
fmt.Scan(&gid)
test_body, test_code := make_request(gid)
if test_code == 401 {

red.Println("ERROR BAD TOKEN")
switch test_code {
case 401:
red.Println("ERROR: Bad token")
return
case 403:
red.Println("ERROR: Not in group")
}
if test_code == 403 {
red.Println("ERROR NOT IN GROUP")
}

if len(test_body) > 2 && gjson.Get(test_body, "message").String() == "You are being rate limited." {
if gjson.Get(test_body, "retry_after").Int() <= 500 {
green.Println("already locked")
Expand All @@ -107,29 +115,25 @@ func main() {
test_body, _ := make_request(gid)
clear()
if len(test_body) > 2 {
if gjson.Get(test_body, "retry_after").Int() <= 500 {
retry_after := gjson.Get(test_body, "retry_after")
switch {
case retry_after.Int() <= 1000:
yellow.Println("locking again")
spam(gid)
}else if gjson.Get(test_body, "retry_after").Int() <= 5000 {
case retry_after.Int() <= 3000:
clear()
blue.Println("locking soon")
spam(gid)
}else if gjson.Get(test_body, "message").String() != "You are being rate limited." {
yellow.Println("locking again")
spam(gid)
green.Println("locked")
}else {
case retry_after.String() != "You are being rate limited.":
green.Println("locked")
blue.Print("remaining time: ")
fmt.Println(gjson.Get(test_body, "retry_after").String())
fmt.Println(retry_after.String())
}
}else{
spam(gid)
}
}
}


func slow_print(s string){
for c := 0; c < len(s);c++ {
f := bufio.NewWriter(os.Stdout)
Expand All @@ -139,7 +143,6 @@ func slow_print(s string){
}
}


func clear() {
cmd := exec.Command("clear")
cmd.Stdout = os.Stdout
Expand All @@ -153,17 +156,14 @@ func sleep(t time.Duration){
time.Sleep(t * time.Millisecond)
}


func make_request(gid string) (string, int) {
gid = fmt.Sprintf(gid)
httpputturl := "https://discord.com/api/v7/channels/" + gid + "/recipients/1337"

empty, _ := json.Marshal("")

request, err := http.NewRequest(http.MethodPut, httpputturl, bytes.NewBuffer(empty))
if err != nil {
panic(err)
}
error_nil(err)

request.Header.Set("Content-Type", "application/json; charset=UTF-8")
request.Header.Set("authorization", TOKEN_AUTH)
Expand All @@ -172,9 +172,8 @@ func make_request(gid string) (string, int) {
client := &http.Client{}

response, err := client.Do(request)
if err != nil {
panic(err)
}
error_nil(err)

defer response.Body.Close()
body_bytes, _ := ioutil.ReadAll(response.Body)
body := string(body_bytes)
Expand All @@ -183,10 +182,9 @@ func make_request(gid string) (string, int) {
}

func spam(gid string) {
for i := 1; i <= 50; i++ {
for i := 1; i <= 100; i++ {
go make_request(gid)
}
sleep(4600)
sleep(1000)
return
}

0 comments on commit e0ea42c

Please sign in to comment.