-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexecutor.py
431 lines (355 loc) · 16.4 KB
/
executor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
###################################################################################
# https://github.com/SirDank
###################################################################################
'''
[NOTE]
- executor.py is meant to be executed only as an executable, not as a python script!
- the below packages are not required by the executor.py script but are required by the various __modules__ run by the dank.tool.exe
- they are listed here to be included in the final build of dank.tool.exe
'''
import os
import sys
# rediect stderr to a file
os.chdir(os.path.dirname(__file__))
if os.path.isdir('__logs__'):
if os.path.isfile('__logs__/dank.tool.log'):
os.remove('__logs__/dank.tool.log')
file = open('__logs__/dank.tool.log', 'w', encoding='utf-8')
sys.stdout = file
sys.stderr = file
import time
import json
import requests
import websocket
import pyminizip
import tkinter as tk
from socketio import Client
from locale import getlocale
from rich.align import Align
from psutil import process_iter
from playsound import playsound
from rich.console import Console
from translatepy import Translator
from dateutil.tz import tzlocal, tzutc
from mcstatus import JavaServer, BedrockServer
from concurrent.futures import ThreadPoolExecutor
from dankware import cls, clr, title, err, rm_line, cyan
from dankware.tkinter import file_selector, folder_selector
# required packages for dank.game.py
import numpy
from ursina import *
from ursina.scripts import *
from ursina.shaders import *
from ursina.prefabs.first_person_controller import FirstPersonController
# required packages for executor.py
from packaging.version import parse
# windows specific
WINDOWS = (os.name == "nt" and 'WINELOADER' not in os.environ)
if WINDOWS:
from pypresence import Presence
from win11toast import notify
# debug env variables
def settings_json():
overwrite = False
settings = {
"offline-src": "0",
"offline-mode": "0",
"dev-branch": "0",
"force-update": "0",
"force-translate": "0",
"disable-translate": "0",
"compatibility-mode": "0",
"force-startup-audio": "0",
"disable-startup-audio": "0",
}
# wine support
if (os.name == 'posix') or ('WINELOADER' in os.environ) or os.getlogin() == 'xuser' or ('USERNAME' in os.environ and os.environ['USERNAME'] == 'xuser') or ('NO_COLOR' in os.environ):
settings['compatibility-mode'] = "1"
os.environ['COMPATIBILITY-MODE'] = "1"
if not os.path.isfile('settings.json'):
overwrite = True
else:
with open('settings.json', 'r', encoding='utf-8') as file:
data = json.loads(file.read())
for key in settings:
if key not in data:
overwrite = True
else:
settings[key] = data[key]
if settings != data:
overwrite = True
if overwrite:
with open('settings.json', 'w', encoding='utf-8') as file:
file.write(json.dumps(settings, indent=4))
settings_json()
del settings_json
with open('settings.json', 'r', encoding='utf-8') as _:
DANK_TOOL_SETTINGS = json.loads(_.read())
OFFLINE_SRC = int(DANK_TOOL_SETTINGS['offline-src'])
DEV_BRANCH = int(DANK_TOOL_SETTINGS['dev-branch'])
BRANCH = ("main" if not DEV_BRANCH else "dev")
# compatability mode
if int(DANK_TOOL_SETTINGS['compatibility-mode']):
# https://no-color.org/
os.environ['NO_COLOR'] = '1'
import dankware
dankware.reset = ''
dankware.black = ''
dankware.blue = ''
dankware.cyan = ''
dankware.green = ''
dankware.magenta = ''
dankware.red = ''
dankware.white = ''
dankware.yellow = ''
dankware.black_bright = ''
dankware.blue_bright = ''
dankware.cyan_bright = ''
dankware.green_bright = ''
dankware.magenta_bright = ''
dankware.red_bright = ''
dankware.white_bright = ''
dankware.yellow_bright = ''
dankware.black_normal = ''
dankware.blue_normal = ''
dankware.cyan_normal = ''
dankware.green_normal = ''
dankware.magenta_normal = ''
dankware.red_normal = ''
dankware.white_normal = ''
dankware.yellow_normal = ''
dankware.black_dim = ''
dankware.blue_dim = ''
dankware.cyan_dim = ''
dankware.green_dim = ''
dankware.magenta_dim = ''
dankware.red_dim = ''
dankware.white_dim = ''
dankware.yellow_dim = ''
dankware.clr = lambda text, preset=None, colour_one=None, colour_two=None, colours=None: text
from dankware import clr, reset, black, blue, cyan, green, magenta, red, white, yellow, black_bright, blue_bright, cyan_bright, green_bright, magenta_bright, red_bright, white_bright, yellow_bright, black_normal, blue_normal, cyan_normal, green_normal, magenta_normal, red_normal, white_normal, yellow_normal, black_dim, blue_dim, cyan_dim, green_dim, magenta_dim, red_dim, white_dim, yellow_dim # pylint: disable=reimported
# variables
DANK_TOOL_VERSION = "3.2.8"
session = requests.Session()
_executor = ThreadPoolExecutor(10)
headers = {"User-Agent": f"dank.tool {DANK_TOOL_VERSION}"}
os.environ['DANK_TOOL_VERSION'] = DANK_TOOL_VERSION
title("𝚍𝚊𝚗𝚔.𝚝𝚘𝚘𝚕 [ 𝚒𝚗𝚒𝚝𝚒𝚊𝚕𝚒𝚣𝚒𝚗𝚐 ]")
print(clr(f"\n - Version: {DANK_TOOL_VERSION}"))
# handle KeyboardInterrupt
def print_warning_symbol():
cls()
banner = '\n\n[red] ██ \n[red] ██ ██ \n[red] ██ ██ \n[red] ██ ██ \n[red] ██ ██ \n[red] ██ ██ \n[red] ██ [bright_white]██████[red] ██ \n[red] ██ [bright_white]██████[red] ██ \n[red] ██ [bright_white]██████[red] ██ \n[red] ██ [bright_white]██████[red] ██ \n[red] ██ [bright_white]██████[red] ██ \n[red] ██ [bright_white]██████[red] ██ \n[red] ██ [bright_white]██████[red] ██ \n[red] ██ [bright_white]██████[red] ██ \n[red] ██ ██ \n[red] ██ [bright_white]██████[red] ██ \n[red] ██ [bright_white]██████[red] ██ \n[red]██ [bright_white]██████[red] ██\n[red]██ ██\n[red] ██████████████████████████████████████████ \n\n'
Console().print(Align.center(banner), style="blink", highlight=False)
# get latest version number
def latest_dank_tool_version():
global BRANCH
if int(DANK_TOOL_SETTINGS['offline-mode']):
LATEST_VERSION = "0"
os.environ['DANK_TOOL_ONLINE'] = "0"
else:
try:
while True:
LATEST_VERSION = session.get(f"https://raw.githubusercontent.com/SirDank/dank.tool/{BRANCH}/__src__/executor_version.txt", headers=headers, timeout=3).content.decode()
if 'Not Found' in LATEST_VERSION:
print(clr("\n - Please do not use the dev-branch, it is meant for testing/debugging only!",2))
BRANCH = "main"
with open('settings.json', 'r', encoding='utf-8') as file:
tmp = file.read().replace('"dev-branch": "1"', '"dev-branch": "0"')
with open('settings.json', 'w', encoding='utf-8') as file:
file.write(tmp); del tmp
else:
break
os.environ['DANK_TOOL_ONLINE'] = "1"
except:
LATEST_VERSION = "0"
os.environ['DANK_TOOL_ONLINE'] = "0"
return LATEST_VERSION
LATEST_VERSION = latest_dank_tool_version()
ONLINE_MODE = int(os.environ['DANK_TOOL_ONLINE'])
with open('settings.json', 'r', encoding='utf-8') as file:
DEV_BRANCH = int(json.loads(file.read())['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, timeout=3).content.decode()
break
except Exception as exc:
input(clr(f"\n > Failed to get code! {exc} | Press [ENTER] to try again... ",2))
rm_line(); rm_line()
try: exec(code)
except Exception as exc:
error = err((type(exc), exc, exc.__traceback__),'mini')
try: session.post("https://dankware.onrender.com/dank-tool-errors", headers=headers, timeout=3, data={"text": f"```<--- 🚨🚨🚨 ---> Version: {DANK_TOOL_VERSION}\n\n{error}```"})
except: pass
input(clr(f"{error}\n\n > Press [ENTER] to EXIT... ",2))
sys.exit(error)
# update environment variables
if parse(LATEST_VERSION) > parse(DANK_TOOL_VERSION) or (ONLINE_MODE and int(DANK_TOOL_SETTINGS['force-update'])):
print(clr(f"\n - Update Found: {LATEST_VERSION}" + ("" if not int(DANK_TOOL_SETTINGS['force-update']) else " [ FORCED ]")))
if int(DANK_TOOL_SETTINGS['force-update']):
with open('settings.json', 'r', encoding='utf-8') as _:
settings = json.loads(_.read())
settings['force-update'] = "0"
with open('settings.json', 'w', encoding='utf-8') as _:
_.write(json.dumps(settings, indent=4))
dank_tool_installer()
elif LATEST_VERSION == DANK_TOOL_VERSION:
if not DEV_BRANCH:
print(clr("\n - Latest Version!"))
else:
print(clr("\n - Development Branch!"))
elif LATEST_VERSION == "0":
print(clr("\n - Offline Mode!"))
else: # LATEST VERSION IS LOWER THAN CURRENT VERSION
print(clr("\n - Development Version!"))
if OFFLINE_SRC:
print(clr("\n - Offline SRC!"))
# check windows language
def check_system_language():
locale_name = str(getlocale()[0])
if '-' in locale_name and '_' not in locale_name:
locale_name = locale_name.split('-',1)[0]
elif '_' in locale_name and '-' not in locale_name:
locale_name = locale_name.split('_',1)[0]
else:
for _ in locale_name:
if _ == '-':
locale_name = locale_name.split('-',1)[0]
break
if _ == '_':
locale_name = locale_name.split('_',1)[0]
break
if not locale_name.lower().startswith('en'):
if int(DANK_TOOL_SETTINGS['force-translate']):
os.environ['DANK_TOOL_LANG'] = locale_name
elif not int(DANK_TOOL_SETTINGS['disable-translate']):
translator = Translator()
result = translator.translate("Would you like to enable the translate feature?", locale_name, 'en').result
print(clr(f"\n - Your system language is set to '{cyan}{locale_name}'!"))
if input(clr(f"\n > {result} [y/n]: ", colour_one=cyan) + cyan).lower() == 'y':
result = translator.translate("You can force enable the translate feature in the settings menu", locale_name, 'en').result
print(clr(f"\n > {result}!"))
os.environ['DANK_TOOL_LANG'] = locale_name
time.sleep(6.5)
else:
os.environ['DANK_TOOL_LANG'] = "en"
else:
os.environ['DANK_TOOL_LANG'] = "en"
if ONLINE_MODE:
check_system_language()
else:
os.environ['DANK_TOOL_LANG'] = "en"
del check_system_language
# get and save dank.tool.py
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_SRC and ONLINE_MODE:
while True:
try: code = session.get(f"https://raw.githubusercontent.com/SirDank/dank.tool/{BRANCH}/__src__/dank.tool.py", headers=headers, timeout=3).content.decode(); break
except Exception as exc:
input(clr(f"\n > Failed to get code! {exc} | Press [ENTER] to try again... ",2))
rm_line(); rm_line()
with open('__src__/dank.tool.py', 'w', encoding='utf-8') as _:
_.write(code)
else:
while True:
try:
with open('__src__/dank.tool.py', 'r', encoding='utf-8') as _:
code = _.read(); break
except:
input(clr("\n > Failed to get code! Unable to read '__src__/dank.tool.py'! Press [ENTER] to try again... ",2))
rm_line(); rm_line()
# start discord rpc
def dank_tool_discord_rpc():
os.environ['DISCORD_RPC'] = "on the main menu"
fail_counter = 0
while True:
if fail_counter >= 3: break
try:
RPC = Presence("1028269752386326538")
RPC.connect()
fail_counter = 0
start = int(time.time())
while True:
try:
RPC.update(
large_image = "dankware",
large_text = "dankware",
details = f"[ dank.tool {DANK_TOOL_VERSION} ]",
state = os.environ['DISCORD_RPC'],
start = start,
buttons = [{"label": "Download", "url": "https://github.com/SirDank/dank.tool"}, {"label": "Discord", "url": "https://allmylinks.com/link/out?id=kdib4s-nu8b-1e19god"}]
)
time.sleep(15)
except: break
except:
fail_counter += 1
time.sleep(60)
if ONLINE_MODE and WINDOWS:
_executor.submit(dank_tool_discord_rpc)
else:
del dank_tool_discord_rpc
# update counter
def dank_tool_runs_counter():
fail_counter = 0
session = requests.Session()
while True:
if fail_counter >= 3: break
try: session.get("https://dankware.onrender.com/counter?id=dank.tool&hit=true", headers=headers, timeout=3); break
except: fail_counter += 1
time.sleep(60)
del globals()['dank_tool_runs_counter']
if ONLINE_MODE:
_executor.submit(dank_tool_runs_counter)
else:
del dank_tool_runs_counter
# chatroom user validator
def dank_tool_chatroom():
fail_counter = 0
session = requests.Session()
while True:
if fail_counter >= 3: break
try: session.post("https://dankware.onrender.com/chatroom-users", headers=headers, timeout=3); fail_counter = 0 # do not add a break here! (keeps user validated)
except: fail_counter += 1
time.sleep(240)
del globals()['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 and not OFFLINE_SRC:
time.sleep(2)
try: exec(code)
except Exception as exc:
cls()
error = err((type(exc), exc, exc.__traceback__),'mini')
print(clr(error, 2))
LATEST_VERSION = latest_dank_tool_version()
if "- SystemExit" in error:
os.system("taskkill /f /t /im dank.tool.exe")
elif "- EOFError" in error:
print_warning_symbol()
print(clr("\n - No input provided!"))
elif "- KeyboardInterrupt" in error:
print_warning_symbol()
print(clr("\n - Please select text first and then use [ CTRL + C ]!"))
elif parse(LATEST_VERSION) > parse(DANK_TOOL_VERSION):
print(clr(f"\n - Update Found: {LATEST_VERSION}"))
dank_tool_installer()
elif ONLINE_MODE:
while True:
try:
requests.post("https://dankware.onrender.com/dank-tool-errors", headers=headers, timeout=3, data={"text": f"```<--- 🚨🚨🚨 ---> v{DANK_TOOL_VERSION}{' OFFLINE_SRC' if OFFLINE_SRC else ''} BRANCH: {BRANCH}\n\n{error}```"})
break
except Exception as exc:
input(clr(f"\n > Failed to post error report! {exc} | Press [ENTER] to try again... ",2))
rm_line(); rm_line()
print(clr("\n - Error Reported! If it is a logic error, it will be fixed soon!"))
input(clr("\n > Press [ENTER] to EXIT... "))
os.system("taskkill /f /t /im dank.tool.exe")