diff --git a/README.md b/README.md index 4ab85de..52f8975 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,26 @@ -**you can go in webhook.go and change the name where it says "username :=" of the bot and add ur own icon, put the webhook in config.txt. then run "go build webhook.go" and u will be set, you dont have to re-complie to add a new webhook just close the application and put a new webhook in config.txt and start it back up and it will work** +# Discord Webhook Messenger -*if u want to add a avatar url just add where it says ""avatar_url" :"* +# Setup +* Open Config.json +* Input Webhook URL +* Avatar URL & Webhook Username are **optional** + +# Usage +``` +usage: Webhook Sender [-h|--help] -m|--message "" [-t|--timeout + ] [-a|--amount ] + + Spam a webhook with a message + +Arguments: + + -h --help Print help information + -m --message Message to Send Through Webhook + -t --timeout Time Between Messages In Seconds + -a --amount Amount Of Times To Send Message +``` + +# Example +``go run webhook.go -m hello -t 5 -a 50`` **Send the message "hello" every 5 seconds 50 times** **MADE BY cookie#0003 ON DISCORD** \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..5c42038 --- /dev/null +++ b/config.json @@ -0,0 +1,5 @@ +{ + "webhook_url": "Webhook Here", + "webhook_username": "", + "avatar_url": "" +} \ No newline at end of file diff --git a/config.txt b/config.txt deleted file mode 100644 index 64bc1b3..0000000 --- a/config.txt +++ /dev/null @@ -1 +0,0 @@ -webhook goes here \ No newline at end of file diff --git a/webhook.go b/webhook.go index 245b118..d6bc8fa 100644 --- a/webhook.go +++ b/webhook.go @@ -1,31 +1,120 @@ package main import ( + "bytes" + "encoding/json" "fmt" - "net/http" - "net/url" "io/ioutil" + "net/http" + "os" + "strconv" + "time" + + "github.com/akamensky/argparse" ) -func main() { - - webhook, err := ioutil.ReadFile("config.txt") - if err == nil { - fmt.Println("Webhook message sender | Made by: cookie#0003") +//JSONConfig struct for config.json file +type JSONConfig struct { + WebhookURL string `json:"webhook_url"` + WebhookUsername string `json:"webhook_username"` + AvatarURL string `json:"avatar_url"` +} + +//ErrorResponse struct for Discord Ratelimit response +type ErrorResponse struct { + Message string `json:"message"` + RetryAfter int `json:"retry_after"` +} + +var ( + webhook string + avatar string + message *string + timeout *int + amount *int + client *http.Client = &http.Client{} +) + +func readConfig() (string, string, string) { + file, err := ioutil.ReadFile("config.json") + if err != nil { + fmt.Println(err) + } + + data := JSONConfig{} + + err = json.Unmarshal([]byte(file), &data) + if err != nil { + fmt.Println(err) + } + return data.WebhookURL, data.WebhookUsername, data.AvatarURL +} + +func spamWebhook(webhook string, avatar string, message *string, username string, timeout *int, amount *int) { + if *amount == 0 { + for { + var e ErrorResponse + jsonStr := []byte(fmt.Sprintf(`{"content": "%s", "username": "%s", "avatar_url": "%s"}`, *message, username, avatar)) + + req, err := http.NewRequest("POST", webhook, bytes.NewBuffer(jsonStr)) + req.Header.Set("Content-Type", "application/json") + + res, err := client.Do(req) + if err != nil { + fmt.Println(err) + } + + body, err := ioutil.ReadAll(res.Body) + if err != nil { + fmt.Println(err) + } + err = json.Unmarshal(body, &e) + if err == nil { + fmt.Println("You Are Being Ratelimited Waiting " + strconv.Itoa(e.RetryAfter) + " Milliseconds") + time.Sleep(time.Duration(e.RetryAfter+5) * time.Millisecond) + } + time.Sleep(time.Duration(*timeout) * time.Second) } - - for { - fmt.Printf("\nMessage: ") - var MESSAGE string - fmt.Scanln(&MESSAGE) - - username := "cookie v2" - data := url.Values{ - "content": {MESSAGE}, - "username": {username}, - "avatar_url": {""}, + } else { + for i := 0; i < *amount; i++ { + var e ErrorResponse + jsonStr := []byte(fmt.Sprintf(`{"content": "%s", "username": "%s", "avatar_url": "%s"}`, *message, username, avatar)) + + req, err := http.NewRequest("POST", webhook, bytes.NewBuffer(jsonStr)) + req.Header.Set("Content-Type", "application/json") + + res, err := client.Do(req) + if err != nil { + fmt.Println(err) + } + + body, err := ioutil.ReadAll(res.Body) + if err != nil { + fmt.Println(err) + } + err = json.Unmarshal(body, &e) + if err == nil { + fmt.Println("You Are Being Ratelimited Waiting " + strconv.Itoa(e.RetryAfter) + " Milliseconds") + time.Sleep(time.Duration(e.RetryAfter+5) * time.Millisecond) + } + time.Sleep(time.Duration(*timeout) * time.Second) } - http.PostForm(string(webhook), data) } +} + +func main() { + + parser := argparse.NewParser("Webhook Sender", "Spam a webhook with a message") + message = parser.String("m", "message", &argparse.Options{Required: true, Help: "Message to Send Through Webhook"}) + timeout = parser.Int("t", "timeout", &argparse.Options{Required: false, Help: "Time Between Messages In Seconds"}) + amount = parser.Int("a", "amount", &argparse.Options{Required: false, Help: "Amount Of Times To Send Message"}) + err := parser.Parse(os.Args) + if err != nil { + fmt.Println(parser.Usage(err)) + os.Exit(0) + } + fmt.Println("Webhook message sender | Made by: cookie#0003") + webhook, username, avatar := readConfig() -} \ No newline at end of file + spamWebhook(webhook, avatar, message, username, timeout, amount) +}