fixed + notifications

This commit is contained in:
franchioping 2024-07-23 17:42:36 +01:00
parent 3b63d71882
commit 464b0a85ae
3 changed files with 15 additions and 7 deletions

View File

@ -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):

View File

@ -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",

View File

@ -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()