chatgpt fixes lol

This commit is contained in:
2026-01-28 18:21:13 +05:30
parent feb79f69b4
commit 80a92021f7

View File

@@ -32,6 +32,10 @@ new_release_tag_channel = 918559776269553756
load_dotenv() load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN') TOKEN = os.getenv('DISCORD_TOKEN')
if not TOKEN:
raise RuntimeError("DISCORD_TOKEN not set")
pixelget_token = os.getenv('PIXELGET_TOKEN') pixelget_token = os.getenv('PIXELGET_TOKEN')
copyparty_token = os.getenv('COPYPARTY_TOKEN') copyparty_token = os.getenv('COPYPARTY_TOKEN')
@@ -43,7 +47,7 @@ intents.guilds = True
bot = discord.Bot(intents=intents) bot = discord.Bot(intents=intents)
def pixelget(url: str): def pixelget(url: str):
response = requests.get(url) response = requests.get(url, timeout=10)
soup = BeautifulSoup(response.text, 'html.parser') soup = BeautifulSoup(response.text, 'html.parser')
title = soup.title.string[:-13] title = soup.title.string[:-13]
try: try:
@@ -51,12 +55,12 @@ def pixelget(url: str):
except AssertionError: except AssertionError:
logger.warning("Link was not a torrent") logger.warning("Link was not a torrent")
else: else:
response = requests.get(f'https://pixeldrain.com/api/file/{url.split("/")[-1]}?download', headers={"Authorization": (f":{pixelget_token}")}) response = requests.get(f'https://pixeldrain.com/api/file/{url.split("/")[-1]}?download', headers={"Authorization": (f":{pixelget_token}")}, timeout=10)
with open(title, "wb") as f: with open(title, "wb") as f:
f.write(response.content) f.write(response.content)
def dayuploads_get(url: str): def dayuploads_get(url: str):
request = requests.get(url) request = requests.get(url, timeout=10)
soup = BeautifulSoup(request.content, 'html.parser') soup = BeautifulSoup(request.content, 'html.parser')
title = soup.find_all('p', class_="mb-0 text-ellipsis")[0].text title = soup.find_all('p', class_="mb-0 text-ellipsis")[0].text
try: try:
@@ -65,7 +69,7 @@ def dayuploads_get(url: str):
print("Link was not a torrent") print("Link was not a torrent")
else: else:
download_url = soup.find_all('a', class_="download-link")[0]["href"] download_url = soup.find_all('a', class_="download-link")[0]["href"]
torrent_file = requests.get(download_url) torrent_file = requests.get(download_url, timeout=10)
with open(title, "wb") as file: with open(title, "wb") as file:
file.write(torrent_file.content) file.write(torrent_file.content)
@@ -73,28 +77,28 @@ def uploadfile(file_name: str):
with open(file_name, "rb") as torrent_file: with open(file_name, "rb") as torrent_file:
response = requests.put(f"https://upload.fieryeagle.org/torfiles/{file_name}", response = requests.put(f"https://upload.fieryeagle.org/torfiles/{file_name}",
torrent_file, auth=("torbot",copyparty_token)) torrent_file, auth=("torbot",copyparty_token))
try: if not (200 <= response.status_code < 300):
assert response.status_code in range(200, 300) logging.error(f'Error uploading file {file_name}. Status code: {response.status_code}') # noqa: E501
except AssertionError:
logging.error(f'Error uploading file {file_name}. Status code:', response.status_code) # noqa: E501
def regex(inp: str) -> str: def regex(inp: str) -> str:
if "pixeldrain.com" in inp.lower(): if "pixeldrain.com" in inp.lower():
cleaned = regmatch(inp, r'http?.://pixeldrain.com/u/.{8}$') cleaned = regmatch(inp, r'https?.:\/\/pixeldrain.com\/u\/.{8}$')
pixelget(cleaned) pixelget(cleaned)
logger.debug(cleaned) logger.debug(cleaned)
if "dayuploads.com" in inp.lower(): if "dayuploads.com" in inp.lower():
cleaned = regmatch(inp, r'http?.://dayuploads.com/.*/file') cleaned = regmatch(inp, r'https?.:\/\/dayuploads.com\/.*\/file')
dayuploads_get(cleaned) dayuploads_get(cleaned)
logger.debug(cleaned) logger.debug(cleaned)
def regmatch(inp: str, pattern: str) -> list: def regmatch(inp: str, pattern: str) -> list:
regmatch = re.search(pattern, inp).group(0) # noqa: E501 regmatch = re.search(pattern, inp).group(0) # noqa: E501
if not regmatch:
return None
return regmatch return regmatch
def files_to_upload(dir: str) -> list: def files_to_upload(dir: str) -> list:
files = os.listdir(dir) files = os.listdir(dir)
return [i for i in files if os.path.splitext(i)[1] == ".torrent" in i] return [i for i in files if i.lower().endswith(".torrent")]
def update_rss_feed(): def update_rss_feed():
df = rss_gen.create_df() df = rss_gen.create_df()
@@ -125,7 +129,7 @@ async def upload(ctx):
else: else:
for i in files: for i in files:
uploadfile(i) uploadfile(i)
await messagechannel.send(f"{i[:-8]}\nhttps://torfiles.fieryeagle.org/{urlencode(i)}") await messagechannel.send(f"{os.path.splitext(i)[0]}\nhttps://torfiles.fieryeagle.org/{urlencode(i)}")
os.remove(i) os.remove(i)
await ctx.respond(f"Sucessfully uploaded {files}") await ctx.respond(f"Sucessfully uploaded {files}")
@@ -177,6 +181,7 @@ async def on_message(message):
logger.info(f"Posted link for {i}") logger.info(f"Posted link for {i}")
update_rss_feed() update_rss_feed()
return return
await bot.process_commands(message)
def main(): def main():
bot.run(TOKEN) bot.run(TOKEN)