TODO - fix buttons
This commit is contained in:
parent
b0230a6d88
commit
3c1759bf51
|
|
@ -27,6 +27,7 @@ class ListManga(discord.ui.View):
|
|||
attachments=[self.manga_files[self.index]]
|
||||
)
|
||||
|
||||
|
||||
@discord.ui.button(label='Prev', style=discord.ButtonStyle.grey)
|
||||
async def previous(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||
if self.index > 0:
|
||||
|
|
@ -36,7 +37,7 @@ class ListManga(discord.ui.View):
|
|||
|
||||
@discord.ui.button(label='Next', style=discord.ButtonStyle.grey)
|
||||
async def next(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||
if self.index < len(self.manga_list):
|
||||
if self.index < len(self.manga_list) - 1:
|
||||
self.index += 1
|
||||
|
||||
await self.print_manga(interaction)
|
||||
|
|
@ -77,9 +78,11 @@ def get_chapter_files(manga: Manga):
|
|||
|
||||
|
||||
def chapter_embed(manga: Manga, chapter: Chapter):
|
||||
volume_info = f"Volume {chapter.get_volume()}" if chapter.get_volume() else ""
|
||||
chapter_title = f"{chapter.get_title()}" if chapter.get_title() else ""
|
||||
e = discord.Embed(
|
||||
title=f'New "{manga.get_title()}" Chapter Released!',
|
||||
description=f"Chapter {chapter.get_number()} of {manga.get_title()} Released."
|
||||
title=f'"{manga.get_title()}" Chapter {chapter_title} Released!',
|
||||
description=f"{volume_info} Chapter {chapter.get_number()} of {manga.get_title()} Released."
|
||||
f"\nGo read it now!",
|
||||
url=chapter.get_url()
|
||||
)
|
||||
|
|
|
|||
19
main.py
19
main.py
|
|
@ -31,10 +31,13 @@ async def first_command(interaction: discord.Interaction):
|
|||
|
||||
|
||||
async def render_manga_list_in_dm(interaction: discord.Interaction, manga_list: list[manga_api.Manga]):
|
||||
await interaction.response.send_message("Check your DM's")
|
||||
|
||||
|
||||
await interaction.followup.send("Check your DM's")
|
||||
chanel = await interaction.user.create_dm()
|
||||
|
||||
if len(manga_list) == 0:
|
||||
await chanel.send("No Manga in Here")
|
||||
return
|
||||
|
||||
view = embed_util.ListManga(manga_list)
|
||||
msg = await chanel.send(view=view, embed=embed_util.manga_embed(manga_list[0]))
|
||||
await view.force_reload(msg)
|
||||
|
|
@ -55,6 +58,7 @@ async def render_manga_list_in_dm(interaction: discord.Interaction, manga_list:
|
|||
await chanel.send("Done")
|
||||
await man.update()
|
||||
|
||||
|
||||
@tree.command(
|
||||
name="search",
|
||||
description="Search for manga to follow",
|
||||
|
|
@ -65,8 +69,9 @@ async def search_command(
|
|||
interaction: discord.Interaction,
|
||||
title: str
|
||||
):
|
||||
await render_manga_list_in_dm(interaction, mh.search(title))
|
||||
await interaction.response.defer()
|
||||
|
||||
await render_manga_list_in_dm(interaction, mh.search(title))
|
||||
|
||||
|
||||
@tree.command(
|
||||
|
|
@ -75,14 +80,16 @@ async def search_command(
|
|||
guild=discord.Object(id=1042133536926347324)
|
||||
)
|
||||
async def list_command(interaction: discord.Interaction):
|
||||
await interaction.response.defer()
|
||||
|
||||
await render_manga_list_in_dm(interaction, man.get_user_mangas(interaction.user))
|
||||
|
||||
|
||||
|
||||
|
||||
@tasks.loop(minutes=5)
|
||||
async def update_manga():
|
||||
print("Updating... ")
|
||||
await man.update()
|
||||
print("Update Finished!")
|
||||
|
||||
|
||||
@client.event
|
||||
|
|
|
|||
15
manager.py
15
manager.py
|
|
@ -14,6 +14,8 @@ class Manager:
|
|||
self.chapters = {}
|
||||
self.savefile = savefile
|
||||
|
||||
self.load()
|
||||
|
||||
def get_user_mangas(self, user: discord.User) -> list[manga_api.Manga]:
|
||||
manga_ids = []
|
||||
|
||||
|
|
@ -48,13 +50,22 @@ class Manager:
|
|||
|
||||
def check_for_new_chapter(self, manga: manga_api.Manga) -> manga_api.Chapter | None:
|
||||
latest_chap = manga.get_latest_chap()
|
||||
if latest_chap not in self.chapters.keys():
|
||||
print("Comparing Chapters...")
|
||||
|
||||
if manga.id not in self.chapters.keys():
|
||||
self.chapters[manga.id] = latest_chap.id
|
||||
return latest_chap
|
||||
if latest_chap.is_more_recent_than(manga_api.Chapter(self.chapters[manga.id])):
|
||||
old_chap = manga_api.Chapter(self.chapters[manga.id])
|
||||
|
||||
print(f"Latest Chap ID: {latest_chap.id}, Old Chap ID: {self.chapters[manga.id]}")
|
||||
print(f"Latest Chap: {latest_chap.get_volume()}:{latest_chap.get_number()}")
|
||||
print(f"Latest Chap: {old_chap.get_volume()}:{old_chap.get_number()}")
|
||||
if latest_chap.is_more_recent_than(old_chap):
|
||||
self.chapters[manga.id] = latest_chap.id
|
||||
print("New Latest Chap!")
|
||||
return latest_chap
|
||||
else:
|
||||
print("No New Chapter.")
|
||||
return None
|
||||
|
||||
async def send_message_to_user(self, user: discord.User, manga: manga_api.Manga,
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ class Chapter:
|
|||
return float(self.get_volume()) > float(chapter.get_volume())
|
||||
return float(self.get_number()) > float(chapter.get_number())
|
||||
|
||||
def get_title(self) -> str | None:
|
||||
return self.data["attributes"]["title"] if self.data["attributes"]["title"] else None
|
||||
|
||||
def get_volume(self) -> str:
|
||||
return self.data["attributes"]["volume"]
|
||||
|
||||
|
|
@ -81,8 +84,6 @@ class Manga:
|
|||
f"=desc",
|
||||
|
||||
)
|
||||
print(r.request.__dict__)
|
||||
print(r.json())
|
||||
if r.json()["total"] == 0:
|
||||
r = requests.get(
|
||||
f"{self.base_url}/chapter?manga={self.id}&translatedLanguage%5B%5D=en&contentRating%5B%5D=safe"
|
||||
|
|
@ -157,4 +158,4 @@ class MangaHandler:
|
|||
|
||||
if __name__ == "__main__":
|
||||
mh = MangaHandler()
|
||||
print(mh.search("Umineko no Naku Koro ni Episode 4: Alliance of the Golden Witch")[0])
|
||||
print(mh.search("Umineko no Naku Koro ni Episode 4: Alliance of the Golden Witch")[0].get_latest_chap().data)
|
||||
|
|
|
|||
Loading…
Reference in New Issue