Skip to content

Commit 0ae9e65

Browse files
committed
"small changes" lol
1 parent 4b107aa commit 0ae9e65

10 files changed

+578
-548
lines changed

backup.py

+85-127
Large diffs are not rendered by default.

cfgload.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class Config():
1111
"Ex: `config.threads`"
1212
def __init__(self) -> None:
13-
args = yaml.safe_load(open("config.yml"))
13+
data = yaml.safe_load(open("config.yml"))
1414

15-
for arg, val in args.items():
16-
exec(f"self.{arg} = val")
15+
self.colour = data['colour']
16+
self.group_chat_msg = data['group_chat_msg']

client_info.py

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (C) 2021 github.com/ItsChasa
3+
#
4+
# This source code has been released under the GNU Affero General Public
5+
# License v3.0. A copy of this license is available at
6+
# https://www.gnu.org/licenses/agpl-3.0.en.html
7+
8+
import base64
9+
import re
10+
import json
11+
12+
# browser data
13+
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
14+
sec_ch_ua = '"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"'
15+
browser_version = "113.0.0.0"
16+
request_client_identifier = "chrome_113" # tls_client uses this to determine what "Client Hello" to use
17+
18+
# discord data
19+
from main import request_client
20+
21+
def get_client_build_number():
22+
client_request = request_client.get(f'https://discord.com/app', headers={'User-Agent': 'Mozilla/5.0'}).text
23+
jsFileRegex = re.compile(r'([a-zA-z0-9]+)\.js', re.I)
24+
for asset in jsFileRegex.findall(client_request)[::-1]:
25+
if asset != "invisible":
26+
break
27+
28+
assetFileRequest = request_client.get(f'https://discord.com/assets/{asset}.js', headers={'User-Agent': 'Mozilla/5.0'}).text
29+
try:
30+
build_info_regex = re.compile(r'Build Number: "\)\.concat\("([0-9]{4,8})"')
31+
build_info_strings = build_info_regex.findall(assetFileRequest)
32+
build_num = build_info_strings[0]
33+
except (RuntimeError, TypeError, NameError):
34+
raise Exception(f"couldn't fetch discord build num from {asset}.js")
35+
36+
return int(build_num)
37+
38+
discord_build = get_client_build_number()
39+
super_properties = {
40+
"os": "Windows",
41+
"browser": "Chrome",
42+
"device": "",
43+
"system_locale": "en-US",
44+
"browser_user_agent": user_agent,
45+
"browser_version": browser_version,
46+
"os_version": "10",
47+
"referrer": "",
48+
"referring_domain": "",
49+
"referrer_current": "",
50+
"referring_domain_current": "",
51+
"release_channel": "stable",
52+
"client_build_number": discord_build,
53+
"client_event_source": None
54+
}
55+
b64_super_properties = base64.b64encode(json.dumps(super_properties, separators=(',', ':')).encode()).decode()
56+
57+
58+
def build_headers(
59+
method,
60+
superprop=False,
61+
debugoptions=False,
62+
discordlocale=False,
63+
authorization=False,
64+
origin=False,
65+
referer="https://discord.com/channels/@me",
66+
context=False,
67+
timezone=False
68+
):
69+
headers = {
70+
"Accept": "*/*",
71+
"Accept-Encoding": "gzip, deflate, br",
72+
"Accept-Language": "en-US,en;q=0.9",
73+
"Cookie": "locale=en-GB",
74+
"Referer": referer,
75+
"Sec-Ch-Ua": sec_ch_ua,
76+
"Sec-Ch-Ua-Mobile": "?0",
77+
"Sec-Ch-Ua-Platform": '"Windows"',
78+
"Sec-Fetch-Dest": "empty",
79+
"Sec-Fetch-Mode": "cors",
80+
"Sec-Fetch-Site": "same-origin",
81+
"User-Agent": user_agent
82+
}
83+
84+
if referer is False:
85+
del headers["Referer"]
86+
87+
if method != "get":
88+
headers["Content-Type"] = "application/json"
89+
if origin is not False:
90+
headers["Origin"] = origin
91+
92+
if authorization is not False:
93+
headers["Authorization"] = authorization
94+
if debugoptions is True:
95+
headers["X-Debug-Options"] = "bugReporterEnabled"
96+
if discordlocale is True:
97+
headers["X-Discord-Locale"] = "en-US"
98+
if superprop is True:
99+
headers["X-Super-Properties"] = b64_super_properties
100+
if context is True:
101+
headers["X-Context-Properties"] = context
102+
if timezone is True:
103+
headers["X-Discord-Timezone"] = "Europe/London"
104+
105+
keyssorted = sorted(headers.keys(), key=lambda x:x.lower())
106+
newheaders={}
107+
for key in keyssorted:
108+
newheaders[key] = headers[key]
109+
110+
return headers

config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ colour: purple
1515

1616

1717
# group chat backup:
18-
# if last message is older than _ seconds, dont create invite:
18+
# if last message is older than _ seconds, dont create invite
1919
# format: seconds
2020
# set to 0 to disable it
2121
# default: 1209600 (2 weeks)

console.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@
55
# License v3.0. A copy of this license is available at
66
# https://www.gnu.org/licenses/agpl-3.0.en.html
77

8-
import startup
8+
from main import colours
99

1010
class prnt():
11-
def __init__(self, clnt : startup.Setup) -> None:
12-
self.clnt = clnt
11+
def __init__(self) -> None:
12+
pass
1313

1414
def success(self, content, end="\n", indent=0):
1515
ind = ""
1616
for _ in range(indent): ind += " "
17-
print(f"{ind}{self.clnt.green}>{self.clnt.white} {content}", end=end)
17+
print(f"{ind}{colours['green']}>{colours['white']} {content}", end=end)
1818

1919
def info(self, content, end="\n", indent=0):
2020
ind = ""
2121
for _ in range(indent): ind += " "
22-
print(f"{ind}{self.clnt.white}> {content}", end=end)
22+
print(f"{ind}{colours['white']}> {content}", end=end)
2323

2424
def fail(self, content, end="\n", indent=0):
2525
ind = ""
2626
for _ in range(indent): ind += " "
27-
print(f"{ind}{self.clnt.red}>{self.clnt.white} {content}", end=end)
27+
print(f"{ind}{colours['light_red']}>{colours['white']} {content}", end=end)
2828

2929
def inp(self, content, end="\n", indent=0):
3030
ind = ""
3131
for _ in range(indent): ind += " "
32-
print(f"{ind}{self.clnt.blue}>{self.clnt.white} {content}", end=end)
32+
print(f"{ind}{colours['light_blue']}>{colours['white']} {content}", end=end)
3333

3434
def warn(self, content, end="\n", indent=0):
3535
ind = ""
3636
for _ in range(indent): ind += " "
37-
print(f"{ind}{self.clnt.yellow}>{self.clnt.white} {content}", end=end)
37+
print(f"{ind}{colours['yellow']}>{colours['white']} {content}", end=end)

fetch_tokens.py

+9-23
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55
# License v3.0. A copy of this license is available at
66
# https://www.gnu.org/licenses/agpl-3.0.en.html
77

8-
import os, re, requests, base64, json, brotli
8+
import os
9+
import re
10+
import base64
11+
import json
12+
import brotli
913
from Crypto.Cipher import AES
1014
from win32crypt import CryptUnprotectData
1115

16+
from client_info import build_headers
17+
from main import request_client
18+
1219
def fetch():
1320
"""[[token, user#tag], ...] """
1421

@@ -37,33 +44,12 @@ def get_decryption_key(path) -> str:
3744

3845
return decryption_key
3946

40-
def getheaders(token):
41-
headers = {
42-
"accept": "*/*",
43-
"accept-encoding": "gzip, deflate, br",
44-
"accept-language": "en-US,en;q=0.9",
45-
"authorization": token,
46-
"cookie": "locale=en-GB",
47-
"referer": "https://discord.com/channels/@me",
48-
"sec-ch-ua": '" Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"',
49-
"sec-ch-ua-mobile": "?0",
50-
"sec-ch-ua-platform": '"Windows"',
51-
"sec-fetch-dest": "empty",
52-
"sec-fetch-mode": "cors",
53-
"sec-fetch-site": "same-origin",
54-
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
55-
"x-debug-options": "bugReporterEnabled",
56-
"x-discord-locale": "en-GB",
57-
"x-super-properties": "eyJvcyI6IldpbmRvd3MiLCJicm93c2VyIjoiQ2hyb21lIiwiZGV2aWNlIjoiIiwic3lzdGVtX2xvY2FsZSI6ImVuLVVTIiwiYnJvd3Nlcl91c2VyX2FnZW50IjoiTW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzEwMC4wLjQ4OTYuMTI3IFNhZmFyaS81MzcuMzYiLCJicm93c2VyX3ZlcnNpb24iOiIxMDAuMC40ODk2LjEyNyIsIm9zX3ZlcnNpb24iOiIxMCIsInJlZmVycmVyIjoiIiwicmVmZXJyaW5nX2RvbWFpbiI6IiIsInJlZmVycmVyX2N1cnJlbnQiOiIiLCJyZWZlcnJpbmdfZG9tYWluX2N1cnJlbnQiOiIiLCJyZWxlYXNlX2NoYW5uZWwiOiJzdGFibGUiLCJjbGllbnRfYnVpbGRfbnVtYmVyIjoxMjY0NjIsImNsaWVudF9ldmVudF9zb3VyY2UiOm51bGx9"
58-
}
59-
return headers
60-
6147
def reqJSON(req) -> dict:
6248
try: return req.json()
6349
except: return json.loads(brotli.decompress(req.content).decode("utf-8"))
6450

6551
def check_token(tkn, name, ids:list, to_return_tokens:list):
66-
r = requests.get("https://discord.com/api/v9/users/@me", headers=getheaders(tkn))
52+
r = request_client.get("https://discord.com/api/v9/users/@me", headers=build_headers("get", superprop=True, debugoptions=True, discordlocale=True, authorization=tkn, timezone=True))
6753
if r.status_code == 200:
6854
tknid = base64.b64decode((tkn.split('.')[0] + '===').encode('ascii')).decode('ascii')
6955
if (tknid+name) not in ids:

0 commit comments

Comments
 (0)