Skip to content

Commit

Permalink
3.1.3
Browse files Browse the repository at this point in the history
- added settings!
- delete unused functions when in offline mode
- fix settings.json implementation

Former-commit-id: 1b1b26b
  • Loading branch information
SirDank authored Sep 25, 2023
1 parent e371da6 commit e3985a2
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 37 deletions.
2 changes: 1 addition & 1 deletion __modules__/dank.minecraft-server-scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def main():

cls(); print(align(clr(banner,4,colours=[white, white_normal, red, red_normal, red_dim])))
print(clr(f"\n > Java Server List: https://dank-site.onrender.com/minecraft-java-servers\n\n > Bedrock Server List: https://dank-site.onrender.com/minecraft-bedrock-servers\n\n > {translate('You can use the above links to get a list of servers that have been found by the users of this tool!')}"))
choice = input(clr("\n > 1: Open Java Server List | 2: Open Bedrock Server List | ENTER: Continue\n\n > Choice [1/2/ENTER]: ") + red)
choice = input(clr("\n > 1: Open Java Server List | 2: Open Bedrock Server List | ENTER: Skip\n\n > Choice [1/2/ENTER]: ") + red)

if choice == "1":
os.system("start https://dank-site.onrender.com/minecraft-java-servers")
Expand Down
61 changes: 53 additions & 8 deletions __src__/dank.tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def download_offline_scripts(project):

def print_modules():

print_banner(); print(clr(f"\n - Modules:{stats}") + red + ('' if ONLINE_MODE else ' OFFLINE') + ('' if not OFFLINE_DEV else ' DEBUG') + ('' if not ONLINE_DEV else ' ONLINE DEBUG') + "\n")
print_banner(); print(clr(f"\n - Modules:{stats}") + red + ('' if ONLINE_MODE else ' OFFLINE') + ('' if not OFFLINE_SRC else ' DEBUG') + ('' if not DEV_BRANCH else ' ONLINE DEBUG') + "\n")
user_renderables = []
console = Console()
counter = 1
Expand All @@ -131,14 +131,14 @@ def print_modules():

def set_globals_one():

global ONLINE_MODE, OFFLINE_DEV, ONLINE_DEV, DANK_TOOL_VERSION, DANK_TOOL_LANG, TRANSLATOR_ENABLED, branch, headers
global ONLINE_MODE, OFFLINE_SRC, DEV_BRANCH, DANK_TOOL_VERSION, DANK_TOOL_LANG, TRANSLATOR_ENABLED, branch, headers

OFFLINE_DEV = int(os.environ['DANK_TOOL_OFFLINE_DEV'])
ONLINE_DEV = int(os.environ['DANK_TOOL_ONLINE_DEV'])
OFFLINE_SRC = int(os.environ['DANK_TOOL_OFFLINE_SRC'])
DEV_BRANCH = int(os.environ['DANK_TOOL_DEV_BRANCH'])
DANK_TOOL_VERSION = os.environ['DANK_TOOL_VERSION']
ONLINE_MODE = int(os.environ['DANK_TOOL_ONLINE'])
DANK_TOOL_LANG = os.environ['DANK_TOOL_LANG']
branch = ("main" if not ONLINE_DEV else "dev")
branch = ("main" if not DEV_BRANCH else "dev")
headers = {"User-Agent": "dank.tool"}
TRANSLATOR_ENABLED = (False if DANK_TOOL_LANG == "en" else True)

Expand All @@ -160,6 +160,13 @@ def set_globals_two():
'title': "𝚍𝚊𝚗𝚔.𝚋𝚛𝚘𝚠𝚜𝚎𝚛-𝚋𝚊𝚌𝚔𝚞𝚙",
'project': "dank.browser-backup",
'rpc': "backing up a browser"
},

'Settings': {
'req_resp': '',
'title': "𝚍𝚊𝚗𝚔.𝚝𝚘𝚘𝚕 𝚜𝚎𝚝𝚝𝚒𝚗𝚐𝚜",
'project': "dank.tool settings",
'rpc': "changing dank.tool settings"
}
}

Expand Down Expand Up @@ -262,6 +269,13 @@ def set_globals_three():
'Discord Server': {
'req_resp': '[bright_green]Join Now!',
'project': "Dankware Inc. Discord Server",
},

'Settings': {
'req_resp': '',
'title': "𝚍𝚊𝚗𝚔.𝚝𝚘𝚘𝚕 𝚜𝚎𝚝𝚝𝚒𝚗𝚐𝚜",
'project': "dank.tool settings",
'rpc': "changing dank.tool settings"
}
}

Expand Down Expand Up @@ -310,6 +324,12 @@ def _translate(text):
break
except:
input(clr(f"\n > {_translate('Failed to get request responses! Make sure you are connected to the internet! Press [ENTER] to try again')}... ",2))

else:

del updated_on
del download_offline_scripts
del get_menu_request_responses

# main

Expand All @@ -336,7 +356,7 @@ def _translate(text):

local_modules = {}

if not os.path.exists('__local_modules__'):
if not os.path.isdir('__local_modules__'):
os.mkdir('__local_modules__')

for module in os.listdir("__local_modules__"):
Expand Down Expand Up @@ -386,12 +406,37 @@ def _translate(text):

if "Discord" in choice['project']:
os.system(f'start https://allmylinks.com/link/out?id=kdib4s-nu8b-1e19god'); continue

else:
title(choice['title'])
project = choice['project']
os.environ['DISCORD_RPC'] = choice['rpc']

if "dank.tool settings" in choice['project']:

while True:

cls(); print(clr(f"\n - Settings: [ {_translate('restart for changes to take effect')} ]\n"))

settings = json.loads(open("settings.json", "r", encoding="utf-8").read())

counter = 1
for name, value in settings.items():
print(clr(f" - [{counter}] {name}: {'True' if int(value) else 'False'}"))
counter += 1

choice = input(clr("\n - Choice [num/exit]: ") + red).lower()

if choice.isdigit() and int(choice) >= 1 and int(choice) <= int(len(settings)):
settings = list(settings.items())
settings[int(choice) - 1] = (settings[int(choice) - 1][0], str(int(not int(settings[int(choice) - 1][1]))))
settings = dict(settings)
open("settings.json", "w", encoding="utf-8").write(json.dumps(settings, indent=4))

elif choice == 'exit': break

continue

if LOCAL_MODULE:

# get src from local_module
Expand All @@ -407,7 +452,7 @@ def _translate(text):

# get src from github if not debug mode else get src locally

if not OFFLINE_DEV and ( ONLINE_MODE or not os.path.exists(f'__modules__/{project}.py') ): # OFFLINE_DEV / ONLINE_MODE defined in executor.py
if not OFFLINE_SRC and ( ONLINE_MODE or not os.path.exists(f'__modules__/{project}.py') ): # OFFLINE_DEV / ONLINE_MODE defined in executor.py
while True:
try: code = requests.get(f"https://raw.githubusercontent.com/SirDank/dank.tool/{branch}/__modules__/{project}.py", headers=headers).content.decode(); break
except: input(clr(f"\n > {_translate(f'Failed to get code for {project}! Make sure you are connected to the internet! Press [ENTER] to try again')}... ",2))
Expand Down
90 changes: 65 additions & 25 deletions __src__/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

# variables

DANK_TOOL_VERSION = "3.1.2"
DANK_TOOL_VERSION = "3.1.3"
session = requests.Session()
executor = ThreadPoolExecutor(10)
headers = {"User-Agent": "dank.tool"}
Expand All @@ -69,11 +69,40 @@

# debug env variables

os.environ['DANK_TOOL_OFFLINE_DEV'] = ("1" if os.path.isfile('debug') else "0")
os.environ['DANK_TOOL_ONLINE_DEV'] = ("1" if os.path.isfile('debug-online') else "0")
ONLINE_DEV = int(os.environ['DANK_TOOL_ONLINE_DEV'])
OFFLINE_DEV = int(os.environ['DANK_TOOL_OFFLINE_DEV'])
branch = ("main" if not ONLINE_DEV else "dev")
def settings_json():

overwrite = False

default_settings = {
"offline-src": "0",
"offline-mode": "0",
"dev-branch": "0",
"force-update": "0",
"force-audio": "0",
"disable-audio": "0",
}

if not os.path.isfile('settings.json'):
overwrite = True
else:
_ = tuple(json.loads(open('settings.json', 'r', encoding='utf-8').read()).keys())
for key in default_settings:
if not key in _:
overwrite = True
break

if overwrite:
open('settings.json', 'w', encoding='utf-8').write(json.dumps(default_settings, indent=4))

settings_json()
del settings_json

DANK_TOOL_SETTINGS = json.loads(open('settings.json', 'r', encoding='utf-8').read())
os.environ['DANK_TOOL_OFFLINE_SRC'] = DANK_TOOL_SETTINGS['offline-src']
os.environ['DANK_TOOL_DEV_BRANCH'] = DANK_TOOL_SETTINGS['dev-branch']
OFFLINE_SRC = int(DANK_TOOL_SETTINGS['offline-src'])
DEV_BRANCH = int(DANK_TOOL_SETTINGS['dev-branch'])
BRANCH = ("main" if not DEV_BRANCH else "dev")

# handle KeyboardInterrupt

Expand All @@ -86,27 +115,32 @@ def print_warning_symbol():

def latest_dank_tool_version():

try:
LATEST_VERSION = session.get(f"https://raw.githubusercontent.com/SirDank/dank.tool/{branch}/__src__/executor_version.txt", headers=headers).content.decode()
os.environ['DANK_TOOL_ONLINE'] = "1"
except:
if int(DANK_TOOL_SETTINGS['offline-mode']):
LATEST_VERSION = "0"
os.environ['DANK_TOOL_ONLINE'] = "0"
os.environ['DANK_TOOL_ONLINE_DEV'] = "0"
os.environ['DANK_TOOL_DEV_BRANCH'] = "0"
else:
try:
LATEST_VERSION = session.get(f"https://raw.githubusercontent.com/SirDank/dank.tool/{BRANCH}/__src__/executor_version.txt", headers=headers).content.decode()
os.environ['DANK_TOOL_ONLINE'] = "1"
except:
LATEST_VERSION = "0"
os.environ['DANK_TOOL_ONLINE'] = "0"
os.environ['DANK_TOOL_DEV_BRANCH'] = "0"
return LATEST_VERSION

LATEST_VERSION = latest_dank_tool_version()
ONLINE_MODE = int(os.environ['DANK_TOOL_ONLINE'])
ONLINE_DEV = int(os.environ['DANK_TOOL_ONLINE_DEV'])
branch = ("main" if not ONLINE_DEV else "dev")
DEV_BRANCH = int(os.environ['DANK_TOOL_DEV_BRANCH'])
BRANCH = ("main" if not DEV_BRANCH else "dev")

# version checker / updater

def dank_tool_installer():

while True:
try:
code = session.get(f"https://raw.githubusercontent.com/SirDank/dank.tool/{branch}/__src__/updater.py", headers=headers).content.decode()
code = session.get(f"https://raw.githubusercontent.com/SirDank/dank.tool/{BRANCH}/__src__/updater.py", headers=headers).content.decode()
break
except: input(clr("\n > Failed to get code! Make sure you are connected to the internet! Press [ENTER] to try again... ",2))

Expand All @@ -122,15 +156,15 @@ def dank_tool_installer():

# update environment variables

if parse(LATEST_VERSION) > parse(DANK_TOOL_VERSION) or os.path.isfile('force-update'):
print(clr(f"\n > Update Found: {LATEST_VERSION}" + ("" if not os.path.isfile('force-update') else " [ FORCED ]")))
if parse(LATEST_VERSION) > parse(DANK_TOOL_VERSION) or int(DANK_TOOL_SETTINGS['force-update']):
print(clr(f"\n > Update Found: {LATEST_VERSION}" + ("" if not int(DANK_TOOL_SETTINGS['force-update']) else " [ FORCED ]")))
dank_tool_installer()

elif LATEST_VERSION == DANK_TOOL_VERSION:
if not ONLINE_DEV:
if not DEV_BRANCH:
print(clr(f"\n > Latest Version!"))
else:
print(clr(f"\n > Online Development Mode!"))
print(clr(f"\n > Development Branch!"))

elif LATEST_VERSION == "0":
print(clr("\n > Offline Mode!"))
Expand Down Expand Up @@ -174,13 +208,13 @@ def check_windows_language():

# get and save dank.tool.py

if not os.path.exists('__src__'): os.mkdir('__src__')
if not os.path.exists('__modules__'): os.mkdir('__modules__')
if not os.path.exists('__local_modules__'): os.mkdir('__local_modules__')
if not os.path.isdir('__src__'): os.mkdir('__src__')
if not os.path.isdir('__modules__'): os.mkdir('__modules__')
if not os.path.isdir('__local_modules__'): os.mkdir('__local_modules__')

if not OFFLINE_DEV and ( ONLINE_MODE or not os.path.exists('__src__/dank.tool.py') ):
if not OFFLINE_SRC and ( ONLINE_MODE or not os.path.isfile('__src__/dank.tool.py') ):
while True:
try: code = session.get(f"https://raw.githubusercontent.com/SirDank/dank.tool/{branch}/__src__/dank.tool.py", headers=headers).content.decode(); break
try: code = session.get(f"https://raw.githubusercontent.com/SirDank/dank.tool/{BRANCH}/__src__/dank.tool.py", headers=headers).content.decode(); break
except: input(clr("\n > Failed to get code! Make sure you are connected to the internet! Press [ENTER] to try again... ",2))
open('__src__/dank.tool.py', 'w', encoding='utf-8').write(code)
else:
Expand Down Expand Up @@ -213,6 +247,8 @@ def dank_tool_discord_rpc():
RPC.connect()
executor.submit(dank_tool_discord_rpc)
except: pass
else:
del dank_tool_discord_rpc

# update counter

Expand All @@ -228,6 +264,8 @@ def dank_tool_runs_counter():

if ONLINE_MODE:
executor.submit(dank_tool_runs_counter)
else:
del dank_tool_runs_counter

# chatroom user validator

Expand All @@ -243,13 +281,15 @@ def dank_tool_chatroom():

if ONLINE_MODE:
executor.submit(dank_tool_chatroom)
else:
del dank_tool_chatroom

# execute, catch errors if any

title(f"𝚍𝚊𝚗𝚔.𝚝𝚘𝚘𝚕 {DANK_TOOL_VERSION}")

if not ONLINE_MODE:
time.sleep(5)
time.sleep(4)

try: exec(code)
except:
Expand All @@ -270,7 +310,7 @@ def dank_tool_chatroom():
elif ONLINE_MODE:
while True:
try:
session.post("https://dank-site.onrender.com/dank-tool-errors", headers=headers, data={"text": f"```<--- 🚨🚨🚨 ---> Version: {DANK_TOOL_VERSION}\n\n{err_message}```"})
requests.post("https://dank-site.onrender.com/dank-tool-errors", headers=headers, data={"text": f"```<--- 🚨🚨🚨 ---> Version: {DANK_TOOL_VERSION}\n\n{err_message}```"})
break
except: input(clr(f"\n > Failed to post error report! Make sure you are connected to the internet! Press [ENTER] to try again... ",2))
print(clr("\n > Error Reported! If it is an OS error, Please run as admin and try again!\n\n > If it is a logic error, it will be fixed soon!"))
Expand Down
2 changes: 1 addition & 1 deletion __src__/executor_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.2
3.1.3
1 change: 0 additions & 1 deletion __src__/updater.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import sys
import time
import requests
import pyminizip
from dankware import cls, clr, green
Expand Down
2 changes: 1 addition & 1 deletion dank.tool.zip.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f803d4fc8e2ded0d4d6e100b1f89b1649b72dc36
d10fefe86b9c688311e5b08916878d1ed9b194ff

0 comments on commit e3985a2

Please sign in to comment.