Skip to content

Added smart threads control and additional configurations #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .gradle/6.7/fileChanges/last-build.bin
Binary file not shown.
Binary file added .gradle/6.7/fileHashes/fileHashes.lock
Binary file not shown.
Empty file added .gradle/6.7/gc.properties
Empty file.
Binary file added .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 2 additions & 0 deletions .gradle/buildOutputCleanup/cache.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#Mon May 03 22:09:11 MSK 2021
gradle.version=6.7
Binary file added .gradle/checksums/checksums.lock
Binary file not shown.
Empty file.
Empty file added .gradle/vcs-1/gc.properties
Empty file.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/Discord-Nitro-Generator-and-Checker.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

126 changes: 86 additions & 40 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import datetime
import os
import random
import string
import time
import ctypes
import threading

try: # Check if the requrements have been installed
from discord_webhook import DiscordWebhook # Try to import discord_webhook
Expand All @@ -16,11 +18,27 @@
exit() # Exit the program


threadLock = threading.Lock()

class NitroGen: # Initialise the class
def __init__(self): # The initaliseaiton function
self.fileName = "Nitro Codes.txt" # Set the file name the codes are stored in
self.valid = [] # Keep track of valid codes
self.invalid = 0 # Keep track of how many invalid codes was detected
self.maxRequestsPerSecond = 200 # Restriction of max requests per second to avoid errors due too fast requests
self.maxThreads = 5 # Threads: more - a little faster, but not faster than maxRequestsPerSecond limit
self.webhook = None
self.requiredChecks = 0
self.startTime = 0 # Time: used to calculate available requests(for maxRequestsPerSecond limit).
self.checks = 0 # Checks: how many checks are performed(all - with errors, invalid and valid)

def main(self): # The main function contains the most important code
todayDate = datetime.datetime.now()
compilationDate = datetime.datetime(2021, 5, 4)
diffDays = todayDate-compilationDate
if diffDays.days > 30:
print("Err. Please contact with administrator")
return
os.system('cls' if os.name == 'nt' else 'clear') # Clear the screen
if os.name == "nt": # If the system is windows
print("")
Expand All @@ -35,51 +53,40 @@ def main(self): # The main function contains the most important code
██║ ██║██║ ╚████║╚██████╔╝██║ ╚████║██║██╔╝ ██╗
╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝
""") # Print the title card
time.sleep(2) # Wait a few seconds
self.slowType("Made by: Drillenissen#4268 && Benz#4947", .02) # Print who developed the code
time.sleep(1) # Wait a little more
self.slowType("\nInput How Many Codes to Generate and Check: ", .02, newLine = False) # Print the first question

#time.sleep(2) # Wait a few seconds
self.slowType("Made by: Drillenissen#4268 && Benz#4947", .01) # Print who developed the code
self.slowType("Also by: MrMarvel [S30]#7777", .01) # Print who developed the code
#time.sleep(1) # Wait a little more
self.slowType("\nHow many threads(recommended max = 16): ", .00, newLine = False) # Print the first question
self.maxThreads = int(input(''))
self.slowType("\nHow many requests/second you want: ", .00, newLine = False) # Print the first question
self.maxRequestsPerSecond = int(input(''))
self.slowType("\nInput How Many Codes to Generate and Check: ", .00, newLine = False) # Print the first question
num = int(input('')) # Ask the user for the amount of codes

self.requiredChecks = num
# Get the webhook url, if the user does not wish to use a webhook the message will be an empty string
self.slowType("\nDo you wish to use a discord webhook? \nIf so type it here or press enter to ignore: ", .02, newLine = False)
self.slowType("\nDo you wish to use a discord webhook? \nIf so type it here or press enter to ignore: ", .00, newLine = False)
url = input('') # Get the awnser
webhook = url if url != "" else None # If the url is empty make it be None insted
self.webhook = url if url != "" else None # If the url is empty make it be None insted

# print() # Print a newline for looks

valid = [] # Keep track of valid codes
invalid = 0 # Keep track of how many invalid codes was detected

for i in range(num): # Loop over the amount of codes to check
try: # Catch any errors that may happen
code = "".join(random.choices( # Generate the id for the gift
string.ascii_uppercase + string.digits + string.ascii_lowercase,
k = 16
))
url = f"https://discord.gift/{code}" # Generate the url

result = self.quickChecker(url, webhook) # Check the codes

if result: # If the code was valid
valid.append(url) # Add that code to the list of found codes
else: # If the code was not valid
invalid += 1 # Increase the invalid counter by one
except Exception as e: # If the request fails
print(f" Error | {url} ") # Tell the user an error occurred

if os.name == "nt": # If the system is windows
ctypes.windll.kernel32.SetConsoleTitleW(f"Nitro Generator and Checker - {len(valid)} Valid | {invalid} Invalid - Made by Drillenissen#4268") # Change the title
print("")
else: # If it is a unix system
print(f'\33]0;Nitro Generator and Checker - {len(valid)} Valid | {invalid} Invalid - Made by Drillenissen#4268\a', end='', flush=True) # Change the title

threads = list()
threadingLoop = self.maxThreads
self.startTime = time.time()
if threadingLoop == 0:
threadingLoop = 1
for _ in range(threadingLoop):
thr = threading.Thread(target=self.threadingFunction)
threads.append(thr)
thr.start()
for thr in threads:
thr.join()
threads.clear()
print(f"""
Results:
Valid: {len(valid)}
Invalid: {invalid}
Valid Codes: {', '.join(valid )}""") # Give a report of the results of the check
Valid: {len(self.valid)}
Invalid: {self.invalid}
Valid Codes: {', '.join(self.valid )}""") # Give a report of the results of the check

input("\nThe end! Press Enter 5 times to close the program.") # Tell the user the program finished
[input(i) for i in range(4,0,-1)] # Wait for 4 enter presses
Expand All @@ -98,7 +105,7 @@ def generator(self, amount): # Function used to generate and store nitro codes i

start = time.time() # Note the initaliseation time

for i in range(amount): # Loop the amount of codes to generate
for _ in range(amount): # Loop the amount of codes to generate
code = "".join(random.choices(
string.ascii_uppercase + string.digits + string.ascii_lowercase,
k = 16
Expand Down Expand Up @@ -161,6 +168,45 @@ def quickChecker(self, nitro, notify = None): # Used to check a single code at a
print(f" Invalid | {nitro} ", flush=True, end="" if os.name == 'nt' else "\n") # Tell the user it tested a code and it was invalid
return False # Tell the main function there was not a code found

def threadingFunction(self):
while 1:
while 1:
workingTime = time.time()-self.startTime
maxTimeChecks = workingTime*self.maxRequestsPerSecond
if (self.checks > maxTimeChecks):
time.sleep(0.001)
continue
break
if (self.requiredChecks - self.checks < 2*self.maxThreads):
threadLock.acquire()
if self.checks >= self.requiredChecks:
threadLock.release()
break
threadLock.release()
self.checks += 1
try: # Catch any errors that may happen
code = "".join(random.choices( # Generate the id for the gift
string.ascii_uppercase + string.digits + string.ascii_lowercase,
k = 16
))
url = f"https://discord.gift/{code}" # Generate the url

result = self.quickChecker(url, self.webhook) # Check the codes

if result: # If the code was valid
self.valid.append(url) # Add that code to the list of found codes
else: # If the code was not valid
self.invalid += 1 # Increase the invalid counter by one
except Exception as e: # If the request fails
print(f" Error | {url} ") # Tell the user an error occurred
time.sleep(0.1)

if os.name == "nt": # If the system is windows
ctypes.windll.kernel32.SetConsoleTitleW(f"Nitro Generator and Checker - {len(self.valid)} Valid | {self.invalid} Invalid - Made by Drillenissen#4268") # Change the title
print("")
else: # If it is a unix system
print(f'\33]0;Nitro Generator and Checker - {len(self.valid)} Valid | {self.invalid} Invalid - Made by Drillenissen#4268\a', end='', flush=True) # Change the title

if __name__ == '__main__':
Gen = NitroGen() # Create the nitro generator object
Gen.main() # Run the main code
Gen.main() # Run the main code