Add files via upload

This commit is contained in:
brostos 2023-08-01 03:31:00 +03:00 committed by GitHub
parent 8dfb81111c
commit 037ee6e25c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -45,9 +45,14 @@ if ANDROID: # !can add ios in future
path = Path(f"{install_path}/websocket.tar.gz") path = Path(f"{install_path}/websocket.tar.gz")
file_path = Path(f"{install_path}/websocket") file_path = Path(f"{install_path}/websocket")
source_dir = Path(f"{install_path}/websocket-client-1.6.1/websocket") source_dir = Path(f"{install_path}/websocket-client-1.6.1/websocket")
if not file_path.exists(): if not f"{file_path}/__init__.py".exists():
url = "https://files.pythonhosted.org/packages/b1/34/3a5cae1e07d9566ad073fa6d169bf22c03a3ba7b31b3c3422ec88d039108/websocket-client-1.6.1.tar.gz" url = "https://files.pythonhosted.org/packages/b1/34/3a5cae1e07d9566ad073fa6d169bf22c03a3ba7b31b3c3422ec88d039108/websocket-client-1.6.1.tar.gz"
try: try:
# fix issue where the file delete themselves
try:
shutil.rmtree(file_path)
except:
pass
filename, headers = urlretrieve(url, filename=path) filename, headers = urlretrieve(url, filename=path)
with open(filename, "rb") as f: with open(filename, "rb") as f:
content = f.read() content = f.read()
@ -66,6 +71,7 @@ if ANDROID: # !can add ios in future
from websocket import WebSocketConnectionClosedException from websocket import WebSocketConnectionClosedException
import websocket import websocket
start_time = time.time() start_time = time.time()
class PresenceUpdate: class PresenceUpdate:
@ -221,6 +227,9 @@ if ANDROID: # !can add ios in future
self.ws.close() self.ws.close()
if not ANDROID: if not ANDROID:
# installing pypresence # installing pypresence
def get_module(): def get_module():
@ -235,7 +244,7 @@ if not ANDROID:
with open(filename, "rb") as f: with open(filename, "rb") as f:
content = f.read() content = f.read()
assert hashlib.md5(content).hexdigest() == "f7c163cdd001af2456c09e241b90bad7" assert hashlib.md5(content).hexdigest() == "f7c163cdd001af2456c09e241b90bad7"
shutil.unpack_archive(filename, install_path) shutil.unpack_archive( filename, install_path)
shutil.copytree(source_dir, file_path) shutil.copytree(source_dir, file_path)
shutil.rmtree(Path(f"{install_path}/pypresence-4.3.0")) shutil.rmtree(Path(f"{install_path}/pypresence-4.3.0"))
remove(path) remove(path)
@ -265,12 +274,21 @@ def get_event_loop(force_fresh=False):
return running return running
else: else:
return loop""" return loop"""
# Thanks Loup #Thanks Loup
with open(Path(f"{getcwd()}/ba_data/python/pypresence/utils.py"), "w") as file: with open(Path(f"{getcwd()}/ba_data/python/pypresence/utils.py"), "w") as file:
for number, line in enumerate(data): for number, line in enumerate(data):
if number not in range(46, 56): if number not in range(46,56):
file.write(line) file.write(line)
#fix the mess i did with the previous
elif file_path.exists():
with open(Path(f"{getcwd()}/ba_data/python/pypresence/utils.py"), "r") as file:
data = file.readlines()
first_line = data[0].rstrip("\n")
if not first_line == '"""Util functions that are needed but messy."""':
shutil.rmtree(file_path)
get_module() get_module()
get_module()
from pypresence import PipeClosed, DiscordError, DiscordNotFound from pypresence import PipeClosed, DiscordError, DiscordNotFound
from pypresence.utils import get_event_loop from pypresence.utils import get_event_loop
@ -339,7 +357,7 @@ def get_event_loop(force_fresh=False):
@staticmethod @staticmethod
def is_discord_running(): def is_discord_running():
for i in range(6463, 6473): for i in range(6463,6473):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.01) s.settimeout(0.01)
try: try:
@ -347,10 +365,10 @@ def get_event_loop(force_fresh=False):
s.close() s.close()
if (conn == 0): if (conn == 0):
s.close() s.close()
return (True) return(True)
except: except:
s.close() s.close()
return (False) return(False)
def _generate_join_secret(self): def _generate_join_secret(self):
# resp = requests.get('https://legacy.ballistica.net/bsAccessCheck').text # resp = requests.get('https://legacy.ballistica.net/bsAccessCheck').text
@ -418,6 +436,7 @@ def get_event_loop(force_fresh=False):
# except Exception: # except Exception:
# print_error("failed to update presence", include_exception= True) # print_error("failed to update presence", include_exception= True)
def _reconnect(self) -> None: def _reconnect(self) -> None:
self.rpc.connect() self.rpc.connect()
self._subscribe_events() self._subscribe_events()
@ -501,8 +520,7 @@ def get_event_loop(force_fresh=False):
babase.pushcall( babase.pushcall(
babase.Call( babase.Call(
bui.screenmessage, bui.screenmessage,
"Discord: {}{} wants to join!".format( "Discord: {}{} wants to join!".format(username, discriminator if discriminator != "#0" else ""),
username, discriminator if discriminator != "#0" else ""),
color=(0.0, 1.0, 0.0), color=(0.0, 1.0, 0.0),
), ),
from_other_thread=True, from_other_thread=True,
@ -530,6 +548,8 @@ class Discordlogin(PopupWindow):
'content-type': "application/json", 'content-type': "application/json",
} }
# creates our _root_widget # creates our _root_widget
PopupWindow.__init__(self, PopupWindow.__init__(self,
position=(0.0, 0.0), position=(0.0, 0.0),
@ -538,6 +558,7 @@ class Discordlogin(PopupWindow):
if _uiscale is babase.UIScale.MEDIUM else 1.0), if _uiscale is babase.UIScale.MEDIUM else 1.0),
bg_color=bg_color) bg_color=bg_color)
self._cancel_button = bui.buttonwidget( self._cancel_button = bui.buttonwidget(
parent=self.root_widget, parent=self.root_widget,
position=(25, self._height - 40), position=(25, self._height - 40),
@ -550,12 +571,16 @@ class Discordlogin(PopupWindow):
icon=bui.gettexture('crossOut'), icon=bui.gettexture('crossOut'),
iconscale=1.2) iconscale=1.2)
bui.imagewidget(parent=self.root_widget, bui.imagewidget(parent=self.root_widget,
position=(180, self._height - 55), position=(180, self._height - 55),
size=(32 * s, 32 * s), size=(32 * s, 32 * s),
texture=bui.gettexture("discordLogo"), texture=bui.gettexture("discordLogo"),
color=(10 - 0.32, 10 - 0.39, 10 - 0.96)) color=(10 - 0.32, 10 - 0.39, 10 - 0.96))
self.email_widget = bui.textwidget(parent=self.root_widget, self.email_widget = bui.textwidget(parent=self.root_widget,
text="Email/Phone Number", text="Email/Phone Number",
size=(400, 70), size=(400, 70),
@ -567,6 +592,7 @@ class Discordlogin(PopupWindow):
autoselect=True, autoselect=True,
maxwidth=220) maxwidth=220)
self.password_widget = bui.textwidget(parent=self.root_widget, self.password_widget = bui.textwidget(parent=self.root_widget,
text="Password", text="Password",
size=(400, 70), size=(400, 70),
@ -578,6 +604,7 @@ class Discordlogin(PopupWindow):
autoselect=True, autoselect=True,
maxwidth=220) maxwidth=220)
bui.containerwidget(edit=self.root_widget, bui.containerwidget(edit=self.root_widget,
cancel_button=self._cancel_button) cancel_button=self._cancel_button)
@ -603,6 +630,7 @@ class Discordlogin(PopupWindow):
maxwidth=200, maxwidth=200,
color=(1.00, 0.15, 0.15)) color=(1.00, 0.15, 0.15))
self._login_button = bui.buttonwidget( self._login_button = bui.buttonwidget(
parent=self.root_widget, parent=self.root_widget,
position=(120, 65), position=(120, 65),
@ -625,6 +653,8 @@ class Discordlogin(PopupWindow):
bui.getsound('swish').play() bui.getsound('swish').play()
self._transition_out() self._transition_out()
def backup_2fa_code(self, tickt): def backup_2fa_code(self, tickt):
if babase.do_once(): if babase.do_once():
self.email_widget.delete() self.email_widget.delete()
@ -641,6 +671,8 @@ class Discordlogin(PopupWindow):
autoselect=True, autoselect=True,
maxwidth=220) maxwidth=220)
json_data_2FA = { json_data_2FA = {
"code": bui.textwidget(query=self.backup_2fa_widget), "code": bui.textwidget(query=self.backup_2fa_widget),
"gift_code_sku_id": None, "gift_code_sku_id": None,
@ -687,6 +719,8 @@ class Discordlogin(PopupWindow):
conn.request("POST", "/api/v9/auth/login", payload, self.headers) conn.request("POST", "/api/v9/auth/login", payload, self.headers)
res = conn.getresponse().read() res = conn.getresponse().read()
try: try:
token = json.loads(res)['token'].encode().hex().encode() token = json.loads(res)['token'].encode().hex().encode()
with open(self.path, 'wb') as f: with open(self.path, 'wb') as f:
@ -698,8 +732,7 @@ class Discordlogin(PopupWindow):
except KeyError: except KeyError:
try: try:
ticket = json.loads(res)['ticket'] ticket = json.loads(res)['ticket']
bui.screenmessage("Input your 2FA or Discord Backup code", bui.screenmessage("Input your 2FA or Discord Backup code", (0.21, 1.0, 0.20))
(0.21, 1.0, 0.20))
bui.getsound('error').play() bui.getsound('error').play()
self.resp = ticket self.resp = ticket
self.backup_2fa_code(tickt=ticket) self.backup_2fa_code(tickt=ticket)
@ -716,6 +749,7 @@ class Discordlogin(PopupWindow):
elif self.code == True: elif self.code == True:
self.backup_2fa_code(tickt=self.resp) self.backup_2fa_code(tickt=self.resp)
else: else:
self.email_widget.delete() self.email_widget.delete()
self.password_widget.delete() self.password_widget.delete()
@ -723,12 +757,10 @@ class Discordlogin(PopupWindow):
bui.getsound('shieldDown').play() bui.getsound('shieldDown').play()
bui.screenmessage("Account successfully removed!!", (0.10, 0.10, 1.00)) bui.screenmessage("Account successfully removed!!", (0.10, 0.10, 1.00))
self.on_bascenev1libup_cancel() self.on_bascenev1libup_cancel()
PresenceUpdate().ws.close() PresenceUpdate().close()
run_once = False run_once = False
def get_once_asset(): def get_once_asset():
global run_once global run_once
if run_once: if run_once:
@ -756,7 +788,6 @@ def get_once_asset():
pass pass
run_once = True run_once = True
def get_class(): def get_class():
if ANDROID: if ANDROID:
return PresenceUpdate() return PresenceUpdate()
@ -895,7 +926,7 @@ class DiscordRP(babase.Plugin):
self.rpc_thread.state = servername[slice(19)] self.rpc_thread.state = servername[slice(19)]
if connection_info == {}: if connection_info == {}:
self.rpc_thread.details = "Local" # ! replace with something like ballistica github cause self.rpc_thread.details = "Local" #! replace with something like ballistica github cause
self.rpc_thread.state = self._get_current_activity_name() self.rpc_thread.state = self._get_current_activity_name()
self.rpc_thread.party_size = max(1, len(roster)) self.rpc_thread.party_size = max(1, len(roster))
self.rpc_thread.party_max = max(1, bs.get_public_party_max_size()) self.rpc_thread.party_max = max(1, bs.get_public_party_max_size())
@ -908,7 +939,7 @@ class DiscordRP(babase.Plugin):
bs.get_foreground_host_session() bs.get_foreground_host_session()
.__class__.__name__.replace("MainMenuSession", "") .__class__.__name__.replace("MainMenuSession", "")
.replace("EndSession", "") .replace("EndSession", "")
.replace("FreeForAllSession", ": FFA") # ! for session use small image key .replace("FreeForAllSession", ": FFA") #! for session use small image key
.replace("DualTeamSession", ": Teams") .replace("DualTeamSession", ": Teams")
.replace("CoopSession", ": Coop") .replace("CoopSession", ": Coop")
) )
@ -981,3 +1012,4 @@ class DiscordRP(babase.Plugin):
) )
if ANDROID and Path(f"{getcwd()}/token.txt").exists(): if ANDROID and Path(f"{getcwd()}/token.txt").exists():
self.rpc_thread.presence() self.rpc_thread.presence()