Skip to content

Commit

Permalink
fix to build num + test guild option
Browse files Browse the repository at this point in the history
  • Loading branch information
itschasa committed Sep 3, 2023
1 parent 10b40b6 commit 6dc3a1c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
20 changes: 5 additions & 15 deletions client_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
20 changes: 18 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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")

Expand Down
23 changes: 17 additions & 6 deletions restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 6dc3a1c

Please sign in to comment.