fond ou chapter count is broken

TODO - fix
This commit is contained in:
franchioping 2024-07-23 20:20:06 +01:00
parent 464b0a85ae
commit e06049a858
5 changed files with 31 additions and 7 deletions

View File

@ -80,6 +80,8 @@ def chapter_embed(manga: Manga, chapter: Chapter):
e = discord.Embed( e = discord.Embed(
title=f'New "{manga.get_title()}" Chapter Released!', title=f'New "{manga.get_title()}" Chapter Released!',
description=f"Chapter {chapter.get_chapter_num()} of {manga.get_title()} Released." description=f"Chapter {chapter.get_chapter_num()} of {manga.get_title()} Released."
f"Go read it now!" f"\nGo read it now!",
url=chapter.get_chapter_url()
) )
e.set_thumbnail(url=f"attachment://{manga.id}.{manga.get_cover_art_extension()}") e.set_thumbnail(url=f"attachment://{manga.id}.{manga.get_cover_art_extension()}")
return e

View File

@ -39,23 +39,27 @@ async def search_command(
interaction: discord.Interaction, interaction: discord.Interaction,
title: str title: str
): ):
await interaction.response.send_message("Check your DM's") await interaction.response.send_message("Check your DM's")
chanel = await interaction.user.create_dm() chanel = await interaction.user.create_dm()
manga_list = mh.search(title) manga_list = mh.search(title)
view = embed_util.ListManga(manga_list) view = embed_util.ListManga(manga_list)
await chanel.send(f"Hey, you searched for {title}")
msg = await chanel.send(view=view, embed=embed_util.manga_embed(manga_list[0])) msg = await chanel.send(view=view, embed=embed_util.manga_embed(manga_list[0]))
await view.force_reload(msg) await view.force_reload(msg)
await view.wait() await view.wait()
print("Done.. Checking Returns")
ret: list[dict] = view.ret ret: list[dict] = view.ret
for action in ret: for action in ret:
if action["action"] == 1: if action["action"] == 1:
manga_id = action["manga"] manga_id = action["manga"]
print(f"Userid {interaction.user.id} added mangaid {manga_id}")
man.add_user_to_manga(interaction.user, manga_api.Manga(manga_id)) man.add_user_to_manga(interaction.user, manga_api.Manga(manga_id))
if action["action"] == -1: if action["action"] == -1:
manga_id = action["manga"] manga_id = action["manga"]
print(f"Userid {interaction.user.id} removed mangaid {manga_id}")
man.remove_user_from_manga(interaction.user, manga_api.Manga(manga_id)) man.remove_user_from_manga(interaction.user, manga_api.Manga(manga_id))

View File

@ -1,8 +1,12 @@
import discord import discord
import json
import embed_util import embed_util
import manga_api import manga_api
_manager = None
class Manager: class Manager:
def __init__(self, client): def __init__(self, client):
self.client: discord.Client = client self.client: discord.Client = client
@ -27,8 +31,10 @@ class Manager:
new_chap = self.check_for_new_chapter(manga) new_chap = self.check_for_new_chapter(manga)
if new_chap is not None: if new_chap is not None:
users = self.manga[manga_id] users = self.manga[manga_id]
for user in users: print(users)
await self.send_message_to_user(self.client.get_user(user), manga, new_chap) for userid in users:
await self.send_message_to_user(await self.client.fetch_user(userid), manga, new_chap)
self.save()
def check_for_new_chapter(self, manga: manga_api.Manga) -> manga_api.Chapter | None: def check_for_new_chapter(self, manga: manga_api.Manga) -> manga_api.Chapter | None:
latest_chap = manga.get_latest_chap() latest_chap = manga.get_latest_chap()
@ -41,6 +47,17 @@ class Manager:
else: else:
return None return None
async def send_message_to_user(self, user: discord.User, manga: manga_api.Manga, chapter: manga_api.Chapter) -> None: async def send_message_to_user(self, user: discord.User, manga: manga_api.Manga,
chapter: manga_api.Chapter) -> None:
dm_channel = await user.create_dm() dm_channel = await user.create_dm()
await dm_channel.send(embed=embed_util.chapter_embed(manga, chapter), files=embed_util.get_chapter_files(manga)) await dm_channel.send(embed=embed_util.chapter_embed(manga, chapter), files=embed_util.get_chapter_files(manga))
def save(self):
with open("manager.json", "w") as f:
json.dump(self.to_dict(), f)
def to_dict(self):
return {
"manga": self.manga,
"chapters": self.chapters
}

View File

@ -124,4 +124,4 @@ class MangaHandler:
if __name__ == "__main__": if __name__ == "__main__":
mh = MangaHandler() mh = MangaHandler()
print(mh.search("Release That Witch")[0].get_url()) print(mh.search("Umineko no Naku Koro ni Episode 4: Alliance of the Golden Witch")[0].data)

View File

@ -16,8 +16,9 @@ def download_file(manga: Manga):
return discord.File(f"tmp/{manga.id}.{extension}", f"{manga.id}.{extension}") return discord.File(f"tmp/{manga.id}.{extension}", f"{manga.id}.{extension}")
def parallel_download(manga_list: list[Manga]) -> list[discord.File]: def parallel_download(manga_list: list[Manga]) -> list[discord.File]:
print("Downloading Images...")
with concurrent.futures.ThreadPoolExecutor() as exector: with concurrent.futures.ThreadPoolExecutor() as exector:
result = exector.map(download_file, manga_list) result = exector.map(download_file, manga_list)
print("Images Finished Downloading")
return list(result) return list(result)