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