diff --git a/client_info.py b/client_info.py index 009dd91..7b281a7 100644 --- a/client_info.py +++ b/client_info.py @@ -19,21 +19,11 @@ from main import request_client def get_client_build_number(): - client_request = request_client.get(f'https://discord.com/app', headers={'User-Agent': 'Mozilla/5.0'}).text - jsFileRegex = re.compile(r'([a-zA-z0-9]+)\.js', re.I) - for asset in jsFileRegex.findall(client_request)[::-1]: - if asset != "invisible": - break - - assetFileRequest = request_client.get(f'https://discord.com/assets/{asset}.js', headers={'User-Agent': 'Mozilla/5.0'}).text - try: - build_info_regex = re.compile(r'Build Number: "\)\.concat\("([0-9]{4,8})"') - build_info_strings = build_info_regex.findall(assetFileRequest) - build_num = build_info_strings[0] - except (RuntimeError, TypeError, NameError): - raise Exception(f"couldn't fetch discord build num from {asset}.js") - - return int(build_num) + res = request_client.get("https://discord.com/login").text + file_with_build_num = 'https://discord.com/assets/' + re.compile(r'assets/+([a-z0-9]+)\.js').findall(res)[-2]+'.js' + req_file_build = request_client.get(file_with_build_num).text + index_of_build_num = req_file_build.find('buildNumber')+24 + return int(req_file_build[index_of_build_num:index_of_build_num+6]) discord_build = get_client_build_number() super_properties = { diff --git a/main.py b/main.py index 0c12ea2..ebfe22a 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ # License v3.0. A copy of this license is available at # https://www.gnu.org/licenses/agpl-3.0.en.html -app_version = "v1.2.3" +app_version = "v1.2.4" import time import sys @@ -60,7 +60,7 @@ import restore c = console.prnt() - os.system('cls') + os.system('cls' if os.name == 'nt' else 'clear') try: github_data = request_client.get("https://api.github.com/repos/ItsChasa/Discord-Backup/releases/latest").json() app_latest_ver = github_data['tag_name'] @@ -316,6 +316,22 @@ c.info('For additional help, join the Discord Server: https://discord.gg/MUP5TSEPc4') c.info("If it's invalid, go to https://chasa.wtf and click the Discord icon.") + elif choice == 999: + c.info("Test Guild Creation (TLS Client)") + c.inp("Token: ", end="") + token = input() + restore.restore.create_guild( + token, + { + "name": "Test Server", + "icon": None, + "channels": [], + "system_channel_id": "0", + "guild_template_code": "2TffvPucqHkN", + }, + verbose=True + ) + else: c.fail(f"Invalid Choice") diff --git a/restore.py b/restore.py index 5f9bed1..323f1e1 100644 --- a/restore.py +++ b/restore.py @@ -106,6 +106,21 @@ def _message(self, guild, channel, content) -> bool: print(response.json()) return False + @staticmethod + def create_guild(token, payload, verbose=False): + req = request_client.post("https://discord.com/api/v9/guilds", + headers=build_headers("post", debugoptions=True, discordlocale=True, superprop=True, authorization=token, timezone=True, origin="https://discord.com"), + json=payload + ) + + try: guild_id = req.json()['id'] + except: + if verbose: + print(f"Failed to create guild: {req.status_code}") + print(req.text) + return None, req + else: return guild_id, req + def servers(self): channels = [ { @@ -166,13 +181,9 @@ def servers(self): "guild_template_code": "2TffvPucqHkN", } - req = request_client.post("https://discord.com/api/v9/guilds", - headers=build_headers("post", debugoptions=True, discordlocale=True, superprop=True, authorization=self.token, timezone=True, origin="https://discord.com"), - json=payload - ) + guild_id, req = self.create_guild(self.token, payload) - try: guild_id = req.json()['id'] - except: + if not guild_id: self.c.fail(f"Failed to create guild: {req.status_code}") self.c.fail(req.text) self.fatal_error = "Failed to create guild"