diff --git a/embed_util.py b/embed_util.py index 849164f..338ce08 100644 --- a/embed_util.py +++ b/embed_util.py @@ -80,6 +80,8 @@ def chapter_embed(manga: Manga, chapter: Chapter): e = discord.Embed( title=f'New "{manga.get_title()}" Chapter 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()}") + return e diff --git a/main.py b/main.py index 9958501..2f6615b 100644 --- a/main.py +++ b/main.py @@ -39,23 +39,27 @@ async def search_command( interaction: discord.Interaction, title: str ): + + await interaction.response.send_message("Check your DM's") chanel = await interaction.user.create_dm() manga_list = mh.search(title) 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])) await view.force_reload(msg) await view.wait() + print("Done.. Checking Returns") ret: list[dict] = view.ret for action in ret: if action["action"] == 1: 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)) if action["action"] == -1: 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)) diff --git a/manager.py b/manager.py index ebcf74d..0c026d2 100644 --- a/manager.py +++ b/manager.py @@ -1,8 +1,12 @@ import discord +import json import embed_util import manga_api +_manager = None + + class Manager: def __init__(self, client): self.client: discord.Client = client @@ -27,8 +31,10 @@ class Manager: new_chap = self.check_for_new_chapter(manga) if new_chap is not None: users = self.manga[manga_id] - for user in users: - await self.send_message_to_user(self.client.get_user(user), manga, new_chap) + print(users) + 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: latest_chap = manga.get_latest_chap() @@ -41,6 +47,17 @@ class Manager: else: 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() 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 + } diff --git a/manga_api.py b/manga_api.py index 113711e..4b95c4c 100644 --- a/manga_api.py +++ b/manga_api.py @@ -124,4 +124,4 @@ class MangaHandler: if __name__ == "__main__": 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) diff --git a/util/parallel_downloads.py b/util/parallel_downloads.py index 6a5747d..5173748 100644 --- a/util/parallel_downloads.py +++ b/util/parallel_downloads.py @@ -16,8 +16,9 @@ def download_file(manga: Manga): return discord.File(f"tmp/{manga.id}.{extension}", f"{manga.id}.{extension}") def parallel_download(manga_list: list[Manga]) -> list[discord.File]: + print("Downloading Images...") with concurrent.futures.ThreadPoolExecutor() as exector: result = exector.map(download_file, manga_list) - + print("Images Finished Downloading") return list(result)