From 464b0a85aef1c2183ec0e845083372889df7f548 Mon Sep 17 00:00:00 2001 From: franchioping Date: Tue, 23 Jul 2024 17:42:36 +0100 Subject: [PATCH] fixed + notifications --- embed_util.py | 4 ++-- main.py | 3 ++- manager.py | 15 +++++++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/embed_util.py b/embed_util.py index badc11d..849164f 100644 --- a/embed_util.py +++ b/embed_util.py @@ -44,12 +44,12 @@ class ListManga(discord.ui.View): @discord.ui.button(label='Add', style=discord.ButtonStyle.green) async def add(self, interaction: discord.Interaction, button: discord.ui.Button): await interaction.response.defer() - self.ret.append({"manga": self.manga_list[self.index], "action": 1}) + self.ret.append({"manga": self.manga_list[self.index].id, "action": 1}) @discord.ui.button(label='Remove', style=discord.ButtonStyle.red) async def remove(self, interaction: discord.Interaction, button: discord.ui.Button): await interaction.response.defer() - self.ret.append({"manga": self.manga_list[self.index], "action": -1}) + self.ret.append({"manga": self.manga_list[self.index].id, "action": -1}) @discord.ui.button(label='Done', style=discord.ButtonStyle.blurple) async def exit(self, interaction: discord.Interaction, button: discord.ui.Button): diff --git a/main.py b/main.py index 73ea6f1..9958501 100644 --- a/main.py +++ b/main.py @@ -9,7 +9,6 @@ import manager import manga_api mh = manga_api.MangaHandler() -man = manager.Manager() load_dotenv() @@ -17,6 +16,8 @@ intents = discord.Intents.default() client = discord.Client(intents=intents) tree = app_commands.CommandTree(client) +man = manager.Manager(client) + @tree.command( name="ping", diff --git a/manager.py b/manager.py index e771f3d..ebcf74d 100644 --- a/manager.py +++ b/manager.py @@ -4,15 +4,22 @@ import embed_util import manga_api class Manager: - def __init__(self): + def __init__(self, client): + self.client: discord.Client = client self.manga = {} self.chapters = {} def add_user_to_manga(self, user: discord.User, manga: manga_api.Manga) -> None: - self.manga[manga.id].append(user.id) + if manga.id in self.manga.keys(): + self.manga[manga.id].append(user.id) + else: + self.manga[manga.id] = [user.id] def remove_user_from_manga(self, user: discord.User, manga: manga_api.Manga) -> None: - self.manga[manga.id].remove(user.id) + if manga.id in self.manga.keys(): + self.manga[manga.id].remove(user.id) + else: + self.manga[manga.id] = [] async def update(self): for manga_id in self.manga.keys(): @@ -21,7 +28,7 @@ class Manager: if new_chap is not None: users = self.manga[manga_id] for user in users: - await self.send_message_to_user(user, manga, new_chap) + await self.send_message_to_user(self.client.get_user(user), manga, new_chap) def check_for_new_chapter(self, manga: manga_api.Manga) -> manga_api.Chapter | None: latest_chap = manga.get_latest_chap()