From ff80362ffedfd9199ad7ffe70f614ba5e82a896d Mon Sep 17 00:00:00 2001
From: quentinvezzani <quentin.vezzani@epitech.eu>
Date: Wed, 31 Mar 2021 18:25:08 +0200
Subject: [PATCH] Add global sniper blacklist

---
 README.md     | 34 ++++++++++++++++++++++------------
 settings.json |  3 ++-
 sniper.go     | 38 ++++++++++++++++++++++----------------
 3 files changed, 46 insertions(+), 29 deletions(-)

diff --git a/README.md b/README.md
index fe0a157..340dc3a 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,8 @@ Discord Nitro sniper and Giveaway joiner in Go.
 
 ![Screenshot](screenshot.png)
 
-#### Features 
+#### Features
+
 * Multiple accounts support to claim on one main account
 * Optional Counter for max Nitro activations
 * Optional main account sniper to only claim code from alts
@@ -37,6 +38,7 @@ Discord Nitro sniper and Giveaway joiner in Go.
 #### Usage
 
 Edit `settings.json`
+
 ``` json5
 {
   "tokens": {
@@ -86,16 +88,18 @@ Edit `settings.json`
   "webhook": {
     "url": "",
     "good_only": false // Will trigger webhook only when you applied a Nitro code or won a giveaway
-  }
+  },
+  "blacklist_servers": [] // IDs of servers you don't want the sniper to work on
+
 }
 ```
 
-You have multiple choices to run the sniper : 
+You have multiple choices to run the sniper :
 
 - [Deploy on Heroku](https://heroku.com/deploy?template=https://github.com/Vedza/NitroSniperGo/tree/heroku) (Free 24/7)
-   * Deploy
-   * Resources -> enable sniper
-   * See logs in More -> View logs
+    * Deploy
+    * Resources -> enable sniper
+    * See logs in More -> View logs
 
 - Download the latest [release](https://github.com/Vedza/NitroSniperGo/releases)
 
@@ -105,21 +109,27 @@ You have multiple choices to run the sniper :
   go build
   ./NitroSniperGo
   ```
-  
+
  <!-- - [Deploy on Repl.it](https://repl.it/github/Vedza/NitroSniperGo) -->
 
- 
 #### How to obtain your token
+
 https://github.com/Tyrrrz/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs#how-to-get-a-user-token
 
 #### Known issues
+
 * `error unmarshalling READY event` is not a problem, it just happens because you're doing a self bot
-* `Already purchased` happens when the gift is a Xbox game pass plan, so if you already activated a discord game pass code you can't activate it anymore
-* It looks like Discord added a security feature where your token change every time but also expire with 2FA, that might be the reason why the sniper doesn't work after some time or if you get an unauthorized error when sniping Nitro
+* `Already purchased` happens when the gift is a Xbox game pass plan, so if you already activated a discord game pass
+  code you can't activate it anymore
+* It looks like Discord added a security feature where your token change every time but also expire with 2FA, that might
+  be the reason why the sniper doesn't work after some time or if you get an unauthorized error when sniping Nitro
 * Some welcome bots mention giveaways that might cause a false positive
-* Privnote sniper makes the program crash sometimes, disable it in settings if that happens to you until I find a solution
+* Privnote sniper makes the program crash sometimes, disable it in settings if that happens to you until I find a
+  solution
 
 #### Disclaimer
-This is against TOS and can get your account banned, especially if you run multiple instance at the same time and/or claim too many Nitros in a too short amount of time. Use it at your own risks.
+
+This is against TOS and can get your account banned, especially if you run multiple instance at the same time and/or
+claim too many Nitros in a too short amount of time. Use it at your own risks.
 
 > *If you like my sniper consider putting a star on this repo !*
diff --git a/settings.json b/settings.json
index a8c3a71..5b2934d 100644
--- a/settings.json
+++ b/settings.json
@@ -45,5 +45,6 @@
   "webhook": {
     "url": "",
     "good_only": false
-  }
+  },
+  "blacklist_servers": []
 }
\ No newline at end of file
diff --git a/sniper.go b/sniper.go
index 656911d..b67b198 100644
--- a/sniper.go
+++ b/sniper.go
@@ -69,6 +69,7 @@ type Settings struct {
 		URL      string `json:"url"`
 		GoodOnly bool   `json:"good_only"`
 	} `json:"webhook"`
+	BlacklistServers []string `json:"blacklist_servers"`
 }
 
 type Response struct {
@@ -536,22 +537,6 @@ func deleteEmpty(s []string) []string {
 }
 
 func main() {
-	c := exec.Command("clear")
-
-	c.Stdout = os.Stdout
-	_ = c.Run()
-	color.Red(`
-▓█████▄  ██▓  ██████  ▄████▄   ▒█████   ██▀███  ▓█████▄      ██████  ███▄    █  ██▓ ██▓███  ▓█████  ██▀███
-▒██▀ ██▌▓██▒▒██    ▒ ▒██▀ ▀█  ▒██▒  ██▒▓██ ▒ ██▒▒██▀ ██▌   ▒██    ▒  ██ ▀█   █ ▓██▒▓██░  ██▒▓█   ▀ ▓██ ▒ ██▒
-░██   █▌▒██▒░ ▓██▄   ▒▓█    ▄ ▒██░  ██▒▓██ ░▄█ ▒░██   █▌   ░ ▓██▄   ▓██  ▀█ ██▒▒██▒▓██░ ██▓▒▒███   ▓██ ░▄█ ▒
-░▓█▄   ▌░██░  ▒   ██▒▒▓▓▄ ▄██▒▒██   ██░▒██▀▀█▄  ░▓█▄   ▌     ▒   ██▒▓██▒  ▐▌██▒░██░▒██▄█▓▒ ▒▒▓█  ▄ ▒██▀▀█▄
-░▒████▓ ░██░▒██████▒▒▒ ▓███▀ ░░ ████▓▒░░██▓ ▒██▒░▒████▓    ▒██████▒▒▒██░   ▓██░░██░▒██▒ ░  ░░▒████▒░██▓ ▒██▒
-▒▒▓  ▒ ░▓  ▒ ▒▓▒ ▒ ░░ ░▒ ▒  ░░ ▒░▒░▒░ ░ ▒▓ ░▒▓░ ▒▒▓  ▒    ▒ ▒▓▒ ▒ ░░ ▒░   ▒ ▒ ░▓  ▒▓▒░ ░  ░░░ ▒░ ░░ ▒▓ ░▒▓░
-░ ▒  ▒  ▒ ░░ ░▒  ░ ░  ░  ▒     ░ ▒ ▒░   ░▒ ░ ▒░ ░ ▒  ▒    ░ ░▒  ░ ░░ ░░   ░ ▒░ ▒ ░░▒ ░      ░ ░  ░  ░▒ ░ ▒░
-░ ░  ░  ▒ ░░  ░  ░  ░        ░ ░ ░ ▒    ░░   ░  ░ ░  ░    ░  ░  ░     ░   ░ ░  ▒ ░░░          ░     ░░   ░
-░     ░        ░  ░ ░          ░ ░     ░        ░             ░           ░  ░              ░  ░   ░
-░                   ░                           ░
-	`)
 
 	if settings.Tokens.Main == "" {
 		_, _ = magenta.Print(time.Now().Format("15:04:05 "))
@@ -604,6 +589,23 @@ func main() {
 		<-finished
 	}
 
+	c := exec.Command("clear")
+
+	c.Stdout = os.Stdout
+	_ = c.Run()
+	color.Red(`
+▓█████▄  ██▓  ██████  ▄████▄   ▒█████   ██▀███  ▓█████▄      ██████  ███▄    █  ██▓ ██▓███  ▓█████  ██▀███
+▒██▀ ██▌▓██▒▒██    ▒ ▒██▀ ▀█  ▒██▒  ██▒▓██ ▒ ██▒▒██▀ ██▌   ▒██    ▒  ██ ▀█   █ ▓██▒▓██░  ██▒▓█   ▀ ▓██ ▒ ██▒
+░██   █▌▒██▒░ ▓██▄   ▒▓█    ▄ ▒██░  ██▒▓██ ░▄█ ▒░██   █▌   ░ ▓██▄   ▓██  ▀█ ██▒▒██▒▓██░ ██▓▒▒███   ▓██ ░▄█ ▒
+░▓█▄   ▌░██░  ▒   ██▒▒▓▓▄ ▄██▒▒██   ██░▒██▀▀█▄  ░▓█▄   ▌     ▒   ██▒▓██▒  ▐▌██▒░██░▒██▄█▓▒ ▒▒▓█  ▄ ▒██▀▀█▄
+░▒████▓ ░██░▒██████▒▒▒ ▓███▀ ░░ ████▓▒░░██▓ ▒██▒░▒████▓    ▒██████▒▒▒██░   ▓██░░██░▒██▒ ░  ░░▒████▒░██▓ ▒██▒
+▒▒▓  ▒ ░▓  ▒ ▒▓▒ ▒ ░░ ░▒ ▒  ░░ ▒░▒░▒░ ░ ▒▓ ░▒▓░ ▒▒▓  ▒    ▒ ▒▓▒ ▒ ░░ ▒░   ▒ ▒ ░▓  ▒▓▒░ ░  ░░░ ▒░ ░░ ▒▓ ░▒▓░
+░ ▒  ▒  ▒ ░░ ░▒  ░ ░  ░  ▒     ░ ▒ ▒░   ░▒ ░ ▒░ ░ ▒  ▒    ░ ░▒  ░ ░░ ░░   ░ ▒░ ▒ ░░▒ ░      ░ ░  ░  ░▒ ░ ▒░
+░ ░  ░  ▒ ░░  ░  ░  ░        ░ ░ ░ ▒    ░░   ░  ░ ░  ░    ░  ░  ░     ░   ░ ░  ▒ ░░░          ░     ░░   ░
+░     ░        ░  ░ ░          ░ ░     ░        ░             ░           ░  ░              ░  ░   ░
+░                   ░                           ░
+	`)
+
 	getPaymentSourceId()
 
 	t := time.Now()
@@ -819,6 +821,10 @@ func findHost(s *discordgo.Session, m *discordgo.MessageCreate) string {
 
 func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
 
+	if contains(settings.BlacklistServers, m.GuildID) {
+		return
+	}
+
 	if reGiftLink.Match([]byte(m.Content)) && SniperRunning {
 		checkGiftLink(s, m, m.Content, time.Now())
 	} else if settings.Giveaway.Enable && !contains(settings.Giveaway.BlacklistServers, m.GuildID) && (strings.Contains(strings.ToLower(m.Content), "**giveaway**") || (strings.Contains(strings.ToLower(m.Content), "react with") && strings.Contains(strings.ToLower(m.Content), "giveaway"))) && m.Author.Bot {