Compare commits
No commits in common. "4338aebac26032ce709b5515f7c0cbf027d20870" and "3c1759bf518b133f4a6eea10b98473568bae3e9c" have entirely different histories.
4338aebac2
...
3c1759bf51
|
|
@ -5,9 +5,6 @@ import os.path
|
|||
import requests
|
||||
from util import parallel_downloads
|
||||
|
||||
prev_label = "Prev"
|
||||
next_label = "Next"
|
||||
|
||||
|
||||
class ListManga(discord.ui.View):
|
||||
def __init__(self, manga_list: list[Manga]):
|
||||
|
|
@ -16,58 +13,30 @@ class ListManga(discord.ui.View):
|
|||
self.index = 0
|
||||
self.manga_list = 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)
|
||||
|
||||
def set_msg(self, msg):
|
||||
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(
|
||||
async def force_reload(self, msg: discord.Message):
|
||||
await msg.edit(
|
||||
embed=manga_embed(self.manga_list[self.index]),
|
||||
attachments=[self.manga_files[self.index]],
|
||||
view=self
|
||||
attachments=[self.manga_files[self.index]]
|
||||
)
|
||||
|
||||
async def print_manga(self, interaction: discord.Interaction):
|
||||
|
||||
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()
|
||||
|
||||
await self.force_reload()
|
||||
|
||||
@discord.ui.button(label=prev_label, style=discord.ButtonStyle.grey)
|
||||
@discord.ui.button(label='Prev', style=discord.ButtonStyle.grey)
|
||||
async def previous(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||
self.prev = button
|
||||
if self.index > 0:
|
||||
self.index -= 1
|
||||
print("cant go anymore back")
|
||||
|
||||
await self.print_manga(interaction)
|
||||
|
||||
@discord.ui.button(label=next_label, style=discord.ButtonStyle.grey)
|
||||
@discord.ui.button(label='Next', style=discord.ButtonStyle.grey)
|
||||
async def next(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||
self.next = button
|
||||
if self.index < len(self.manga_list) - 1:
|
||||
self.index += 1
|
||||
|
||||
|
|
|
|||
9
main.py
9
main.py
|
|
@ -31,6 +31,7 @@ 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.followup.send("Check your DM's")
|
||||
chanel = await interaction.user.create_dm()
|
||||
|
||||
if len(manga_list) == 0:
|
||||
|
|
@ -39,11 +40,7 @@ async def render_manga_list_in_dm(interaction: discord.Interaction, manga_list:
|
|||
|
||||
view = embed_util.ListManga(manga_list)
|
||||
msg = await chanel.send(view=view, embed=embed_util.manga_embed(manga_list[0]))
|
||||
view.set_msg(msg)
|
||||
await view.force_reload()
|
||||
|
||||
await interaction.followup.send("Query done, Check your DM's")
|
||||
|
||||
await view.force_reload(msg)
|
||||
await view.wait()
|
||||
|
||||
print("Done.. Checking Returns")
|
||||
|
|
@ -58,7 +55,7 @@ async def render_manga_list_in_dm(interaction: discord.Interaction, manga_list:
|
|||
print(f"Userid {interaction.user.id} removed mangaid {manga_id}")
|
||||
man.remove_user_from_manga(interaction.user, manga_api.Manga(manga_id))
|
||||
|
||||
await msg.delete()
|
||||
await chanel.send("Done")
|
||||
await man.update()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue