CDRM-Bot/main.py

127 lines
3.9 KiB
Python

# Import dependencies
import os
import interactions
from helper_scripts import TPD_Keys
from helper_scripts import DB_Cache
from helper_scripts import anime_api
from interactions import *
# Get current working directory
main_directory = os.getcwd()
# Define bot
bot = Client(intents=Intents.DEFAULT)
# Check if discord bot token file exists, if not create file
if not os.path.isfile(f"{main_directory}/discord/bot-token.txt"):
with open(f'{main_directory}/discord/bot-token.txt', 'w') as discord_bot_token:
print("Please put your bot token in /discord/bot-token.txt")
discord_bot_token.write("Delete this and place your bot token on this line")
exit()
# Check if bot token exists and if it has been changed
with open(f'{main_directory}/discord/bot-token.txt') as discord_bot_token:
bot_token = discord_bot_token.readline()
if bot_token == "Delete this and place your bot token on this line":
print("Please put your bot token in /discord/bot-token.txt")
exit()
# Place your discord bot token here.
discord_bot_token = bot_token
# Check / Create keys database if it doesn't exist
DB_Cache.create_database.create_database()
# Defining decrypt command
@slash_command(
name="decrypt",
description="Decrypt widevine protected content"
)
# PSSH slash option
@slash_option(
name="pssh",
description="Protection Scheme Specific Header",
required=True,
opt_type=OptionType.STRING,
)
@slash_option(
name="license_url",
description="License URL",
required=True,
opt_type=OptionType.STRING,
)
@slash_option(
name="auth_bearer",
description="Authorization: Bearer token",
required=False,
opt_type=OptionType.STRING,
)
@slash_option(
name="x_dt_auth",
description="X-DT-Auth token",
required=False,
opt_type=OptionType.STRING,
)
async def decrypt(ctx: SlashContext, pssh: str, license_url: str,
auth_bearer: str = None, x_dt_auth: str = None):
keys = TPD_Keys.decrypt_content(pssh=pssh, license_url=license_url, auth_token=auth_bearer,
xdt_auth_token=x_dt_auth)
if keys != "Unable to retrieve service certificate" and keys != "Could not complete license challenge" and keys != "Invalid PSSH":
try:
DB_Cache.cache_key.cache_keys(pssh=pssh, keys=keys)
embed = interactions.Embed(title="uWu")
embed.set_image(url=f"{anime_api.waifu_pics.get_image()}")
await ctx.send(f"Keys:\n\n```{keys}```", embed=embed)
except:
await ctx.send(f"An error occurred `{keys}`!")
else:
await ctx.send(f"An error occurred `{keys}`!")
# Defining search database command
@slash_command(
name="search_database",
description="Search CDRM-Bot's database"
)
@slash_option(
name="pssh",
description="Protection Scheme Specific Header",
required=True,
opt_type=OptionType.STRING,
)
async def search_database(ctx: SlashContext, pssh: str):
keys = DB_Cache.check_database.check_database(pssh=pssh)
if keys != "Not found":
await ctx.send(f"Found key for PSSH `{pssh}` :\n\n```{keys}```")
else:
await ctx.send(f"No keys found for `{pssh}`\n\n Why not use `/decrypt` and add it?")
# Defining key count command
@slash_command(
name="key_count",
description="Check how many keys I have!"
)
async def key_count(ctx: SlashContext):
await ctx.send(f"I have {DB_Cache.key_count.key_count()} keys in my vault!")
# Defining upload database command
@slash_command(
name="upload_database",
description="Upload my database to fileditch"
)
async def upload_database(ctx: SlashContext):
message = await ctx.send("Uploading...")
db_url = DB_Cache.upload_database.upload_database()
embed = interactions.Embed(
title="CDRM-Bot key database",
description=f"{db_url}"
)
embed.set_footer(text="Brought to you by TPD94")
await message.edit(content="Finished!", embeds=embed)
bot.start(token=discord_bot_token)