Compare commits

...

2 Commits

Author SHA1 Message Date
franchioping 4338aebac2 commit 2024-07-24 14:16:51 +01:00
franchioping c9e23129aa delete message 2024-07-24 13:46:12 +01:00
2 changed files with 46 additions and 12 deletions

View File

@ -5,6 +5,9 @@ import os.path
import requests import requests
from util import parallel_downloads from util import parallel_downloads
prev_label = "Prev"
next_label = "Next"
class ListManga(discord.ui.View): class ListManga(discord.ui.View):
def __init__(self, manga_list: list[Manga]): def __init__(self, manga_list: list[Manga]):
@ -13,30 +16,58 @@ class ListManga(discord.ui.View):
self.index = 0 self.index = 0
self.manga_list = manga_list self.manga_list = manga_list
self.manga_files = gen_manga_files(self.manga_list) self.manga_files = gen_manga_files(self.manga_list)
self.comp = self.children
self.prev: discord.Button = None
self.next: discord.Button = None
for comp in self.comp:
if comp.type.name == "button":
button: discord.Button = comp
if button.label == prev_label:
self.prev = button
if button.label == next_label:
self.next = button
self.msg: discord.Message = None
print(self.manga_list)
async def force_reload(self, msg: discord.Message): def set_msg(self, msg):
await msg.edit( self.msg = msg
async def update_buttons(self):
self.prev.disabled = self.index != 0
self.next.disabled = self.index != len(self.manga_list) - 1
print(f"index: {self.index}, prev: {self.prev.disabled}, next {self.next.disabled}")
async def force_reload(self):
await self.update_buttons()
self.msg = await self.msg.edit(
embed=manga_embed(self.manga_list[self.index]), embed=manga_embed(self.manga_list[self.index]),
attachments=[self.manga_files[self.index]] attachments=[self.manga_files[self.index]],
view=self
) )
async def print_manga(self, interaction: discord.Interaction): async def print_manga(self, interaction: discord.Interaction):
await interaction.response.defer() await interaction.response.defer()
await interaction.message.edit(
embed=manga_embed(self.manga_list[self.index]),
attachments=[self.manga_files[self.index]]
)
await self.update_buttons()
@discord.ui.button(label='Prev', style=discord.ButtonStyle.grey) await self.force_reload()
@discord.ui.button(label=prev_label, style=discord.ButtonStyle.grey)
async def previous(self, interaction: discord.Interaction, button: discord.ui.Button): async def previous(self, interaction: discord.Interaction, button: discord.ui.Button):
self.prev = button
if self.index > 0: if self.index > 0:
self.index -= 1 self.index -= 1
print("cant go anymore back")
await self.print_manga(interaction) await self.print_manga(interaction)
@discord.ui.button(label='Next', style=discord.ButtonStyle.grey) @discord.ui.button(label=next_label, style=discord.ButtonStyle.grey)
async def next(self, interaction: discord.Interaction, button: discord.ui.Button): async def next(self, interaction: discord.Interaction, button: discord.ui.Button):
self.next = button
if self.index < len(self.manga_list) - 1: if self.index < len(self.manga_list) - 1:
self.index += 1 self.index += 1

View File

@ -31,7 +31,6 @@ async def first_command(interaction: discord.Interaction):
async def render_manga_list_in_dm(interaction: discord.Interaction, manga_list: list[manga_api.Manga]): async def render_manga_list_in_dm(interaction: discord.Interaction, manga_list: list[manga_api.Manga]):
await interaction.followup.send("Check your DM's")
chanel = await interaction.user.create_dm() chanel = await interaction.user.create_dm()
if len(manga_list) == 0: if len(manga_list) == 0:
@ -40,7 +39,11 @@ async def render_manga_list_in_dm(interaction: discord.Interaction, manga_list:
view = embed_util.ListManga(manga_list) view = embed_util.ListManga(manga_list)
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) view.set_msg(msg)
await view.force_reload()
await interaction.followup.send("Query done, Check your DM's")
await view.wait() await view.wait()
print("Done.. Checking Returns") print("Done.. Checking Returns")
@ -55,7 +58,7 @@ async def render_manga_list_in_dm(interaction: discord.Interaction, manga_list:
print(f"Userid {interaction.user.id} removed mangaid {manga_id}") 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))
await chanel.send("Done") await msg.delete()
await man.update() await man.update()