Skip to content

Commit

Permalink
Merge pull request #181 from brostosjoined/main
Browse files Browse the repository at this point in the history
Bug fix and 2fa update
  • Loading branch information
rikkolovescats authored Jul 31, 2023
2 parents a0bcfbc + d9f5e3e commit 8dfb811
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 33 deletions.
8 changes: 7 additions & 1 deletion plugins/utilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@
},
"discord_richpresence": {
"description": "Discord Rich Presence for Bombsquad.",
"external_url": "https://github.com/brostosjoined/bombsquadrpc",
"external_url": "https://youtu.be/SbbG9V74_E4",
"authors": [
{
"name": "Dliwk&brostos",
Expand All @@ -810,6 +810,12 @@
}
],
"versions": {
"1.2.0": {
"api_version": 8,
"commit_sha": "150f49f",
"released_on": "28-07-2023",
"md5sum": "3b13d83518865a2b07b9340d59d0ab92"
},
"1.1.0": {
"api_version": 8,
"commit_sha": "90fff9b",
Expand Down
129 changes: 97 additions & 32 deletions plugins/utilities/discord_richpresence.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def get_module():
content = f.read()
assert hashlib.md5(content).hexdigest() == "86bc69b61947943627afc1b351c0b5db"
shutil.unpack_archive(filename, install_path)
remove(path)
shutil.copytree(source_dir, file_path)
shutil.rmtree(Path(f"{install_path}/websocket-client-1.6.1"))
remove(path)
except Exception as e:
if type(e) == shutil.Error:
shutil.rmtree(Path(f"{install_path}/websocket-client-1.6.1"))
Expand Down Expand Up @@ -265,11 +265,11 @@ def get_event_loop(force_fresh=False):
return running
else:
return loop"""

with open(Path(f"{getcwd()}/ba_data/python/pypresence/utils.py"), "w") as file:
for number, line in enumerate(data):
if number not in range(46, 56):
file.write(line)
# Thanks Loup
with open(Path(f"{getcwd()}/ba_data/python/pypresence/utils.py"), "w") as file:
for number, line in enumerate(data):
if number not in range(46, 56):
file.write(line)
get_module()

from pypresence import PipeClosed, DiscordError, DiscordNotFound
Expand Down Expand Up @@ -501,7 +501,8 @@ def on_join_request(self, username, uid, discriminator, avatar) -> None:
babase.pushcall(
babase.Call(
bui.screenmessage,
"Discord: {} wants to join!".format(username),
"Discord: {}{} wants to join!".format(
username, discriminator if discriminator != "#0" else ""),
color=(0.0, 1.0, 0.0),
),
from_other_thread=True,
Expand All @@ -522,6 +523,12 @@ def __init__(self):
bg_color = (0.5, 0.4, 0.6)
log_btn_colour = (0.10, 0.95, 0.10) if not self.path.exists() else (1.00, 0.15, 0.15)
log_txt = "LOG IN" if not self.path.exists() else "LOG OUT"
self.code = False
self.resp = "Placeholder"
self.headers = {
'user-agent': "Mozilla/5.0",
'content-type': "application/json",
}

# creates our _root_widget
PopupWindow.__init__(self,
Expand Down Expand Up @@ -618,42 +625,100 @@ def on_bascenev1libup_cancel(self) -> None:
bui.getsound('swish').play()
self._transition_out()

def login(self):
if not self.path.exists():
json_data = {
'login': bui.textwidget(query=self.email_widget),
'password': bui.textwidget(query=self.password_widget),
'undelete': False,
'captcha_key': None,
'login_source': None,
'gift_code_sku_id': None,
}
headers = {
'user-agent': "Mozilla/5.0",
'content-type': "application/json",
}

conn = http.client.HTTPSConnection("discord.com")

payload = json.dumps(json_data)
# conn.request("POST", "/api/v9/auth/login", payload, headers)
# res = conn.getresponse().read()

def backup_2fa_code(self, tickt):
if babase.do_once():
self.email_widget.delete()
self.password_widget.delete()

self.backup_2fa_widget = bui.textwidget(parent=self.root_widget,
text="2FA/Discord Backup code",
size=(400, 70),
position=(50, 120),
h_align='left',
v_align='center',
editable=True,
scale=0.8,
autoselect=True,
maxwidth=220)

json_data_2FA = {
"code": bui.textwidget(query=self.backup_2fa_widget),
"gift_code_sku_id": None,
"ticket": tickt,
}

if json_data_2FA['code'] != "2FA/Discord Backup code":
try:
conn.request("POST", "/api/v9/auth/login", payload, headers)
res = conn.getresponse().read()
token = json.loads(res)['token'].encode().hex().encode()
payload_2FA = json.dumps(json_data_2FA)
conn_2FA = http.client.HTTPSConnection("discord.com")
conn_2FA.request("POST", "/api/v9/auth/mfa/totp", payload_2FA, self.headers)
res_2FA = conn_2FA.getresponse().read()
token = json.loads(res_2FA)['token'].encode().hex().encode()

with open(self.path, 'wb') as f:
f.write(token)
bui.screenmessage("Successfully logged in", (0.21, 1.0, 0.20))
bui.getsound('shieldUp').play()
self.on_bascenev1libup_cancel()
PresenceUpdate().start()
except:
bui.screenmessage("Incorrect credentials", (1.00, 0.15, 0.15))
self.code = True
bui.screenmessage("Incorrect code", (1.00, 0.15, 0.15))
bui.getsound('error').play()

def login(self):
if not self.path.exists() and self.code == False:
try:

json_data = {
'login': bui.textwidget(query=self.email_widget),
'password': bui.textwidget(query=self.password_widget),
'undelete': False,
'captcha_key': None,
'login_source': None,
'gift_code_sku_id': None,
}

conn = http.client.HTTPSConnection("discord.com")

payload = json.dumps(json_data)
# conn.request("POST", "/api/v9/auth/login", payload, headers)
# res = conn.getresponse().read()
conn.request("POST", "/api/v9/auth/login", payload, self.headers)
res = conn.getresponse().read()

try:
token = json.loads(res)['token'].encode().hex().encode()
with open(self.path, 'wb') as f:
f.write(token)
bui.screenmessage("Successfully logged in", (0.21, 1.0, 0.20))
bui.getsound('shieldUp').play()
self.on_bascenev1libup_cancel()
PresenceUpdate().start()
except KeyError:
try:
ticket = json.loads(res)['ticket']
bui.screenmessage("Input your 2FA or Discord Backup code",
(0.21, 1.0, 0.20))
bui.getsound('error').play()
self.resp = ticket
self.backup_2fa_code(tickt=ticket)
self.code = True
except KeyError:
bui.screenmessage("Incorrect credentials", (1.00, 0.15, 0.15))
bui.getsound('error').play()

except:
bui.screenmessage("Connect to the internet", (1.00, 0.15, 0.15))
bui.getsound('error').play()

conn.close()
elif self.code == True:
self.backup_2fa_code(tickt=self.resp)

else:
self.email_widget.delete()
self.password_widget.delete()
remove(self.path)
bui.getsound('shieldDown').play()
bui.screenmessage("Account successfully removed!!", (0.10, 0.10, 1.00))
Expand Down

0 comments on commit 8dfb811

Please sign in to comment.