2024-07-23 17:31:23 +01:00
|
|
|
from manga_api import Manga, Chapter
|
2024-07-23 00:32:44 +01:00
|
|
|
import discord
|
2024-07-23 02:42:08 +01:00
|
|
|
import os.path
|
|
|
|
|
|
|
|
|
|
import requests
|
2024-07-23 14:19:45 +01:00
|
|
|
from util import parallel_downloads
|
2024-07-23 00:32:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ListManga(discord.ui.View):
|
|
|
|
|
def __init__(self, manga_list: list[Manga]):
|
|
|
|
|
super().__init__()
|
|
|
|
|
self.ret = []
|
|
|
|
|
self.index = 0
|
|
|
|
|
self.manga_list = manga_list
|
2024-07-23 13:35:34 +01:00
|
|
|
self.manga_files = gen_manga_files(self.manga_list)
|
2024-07-23 14:19:45 +01:00
|
|
|
|
|
|
|
|
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]]
|
|
|
|
|
)
|
2024-07-23 00:32:44 +01:00
|
|
|
|
|
|
|
|
async def print_manga(self, interaction: discord.Interaction):
|
|
|
|
|
await interaction.response.defer()
|
2024-07-23 14:19:45 +01:00
|
|
|
await interaction.message.edit(
|
2024-07-23 13:35:34 +01:00
|
|
|
embed=manga_embed(self.manga_list[self.index]),
|
|
|
|
|
attachments=[self.manga_files[self.index]]
|
|
|
|
|
)
|
2024-07-23 00:32:44 +01:00
|
|
|
|
2024-07-24 03:24:11 +01:00
|
|
|
|
2024-07-23 00:32:44 +01:00
|
|
|
@discord.ui.button(label='Prev', style=discord.ButtonStyle.grey)
|
|
|
|
|
async def previous(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
|
|
|
if self.index > 0:
|
|
|
|
|
self.index -= 1
|
|
|
|
|
|
|
|
|
|
await self.print_manga(interaction)
|
|
|
|
|
|
|
|
|
|
@discord.ui.button(label='Next', style=discord.ButtonStyle.grey)
|
|
|
|
|
async def next(self, interaction: discord.Interaction, button: discord.ui.Button):
|
2024-07-24 03:24:11 +01:00
|
|
|
if self.index < len(self.manga_list) - 1:
|
2024-07-23 00:32:44 +01:00
|
|
|
self.index += 1
|
|
|
|
|
|
|
|
|
|
await self.print_manga(interaction)
|
|
|
|
|
|
|
|
|
|
@discord.ui.button(label='Add', style=discord.ButtonStyle.green)
|
|
|
|
|
async def add(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
|
|
|
await interaction.response.defer()
|
2024-07-23 17:42:36 +01:00
|
|
|
self.ret.append({"manga": self.manga_list[self.index].id, "action": 1})
|
2024-07-23 00:32:44 +01:00
|
|
|
|
|
|
|
|
@discord.ui.button(label='Remove', style=discord.ButtonStyle.red)
|
|
|
|
|
async def remove(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
|
|
|
await interaction.response.defer()
|
2024-07-23 17:42:36 +01:00
|
|
|
self.ret.append({"manga": self.manga_list[self.index].id, "action": -1})
|
2024-07-23 00:32:44 +01:00
|
|
|
|
|
|
|
|
@discord.ui.button(label='Done', style=discord.ButtonStyle.blurple)
|
|
|
|
|
async def exit(self, interaction: discord.Interaction, button: discord.ui.Button):
|
|
|
|
|
if len(self.ret) > 0:
|
|
|
|
|
await interaction.response.send_message("Your list has been altered successfully", ephemeral=True)
|
|
|
|
|
else:
|
|
|
|
|
await interaction.response.send_message("You didn't make any changes", ephemeral=True)
|
|
|
|
|
self.stop()
|
|
|
|
|
|
|
|
|
|
|
2024-07-23 13:35:34 +01:00
|
|
|
def gen_manga_files(manga_list: list[Manga]):
|
2024-07-23 14:19:45 +01:00
|
|
|
return parallel_downloads.parallel_download(manga_list)
|
2024-07-23 02:42:08 +01:00
|
|
|
|
|
|
|
|
|
2024-07-23 00:32:44 +01:00
|
|
|
def manga_embed(manga: Manga):
|
|
|
|
|
e = discord.Embed(title=manga.get_title(), description=manga.get_description(), url=manga.get_url())
|
2024-07-23 14:19:45 +01:00
|
|
|
extension = manga.get_cover_art_extension()
|
|
|
|
|
e.set_thumbnail(url=f"attachment://{manga.id}.{extension}")
|
2024-07-23 02:42:08 +01:00
|
|
|
|
2024-07-23 00:32:44 +01:00
|
|
|
return e
|
2024-07-23 17:31:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_chapter_files(manga: Manga):
|
|
|
|
|
return parallel_downloads.parallel_download([manga])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def chapter_embed(manga: Manga, chapter: Chapter):
|
2024-07-24 03:24:11 +01:00
|
|
|
volume_info = f"Volume {chapter.get_volume()}" if chapter.get_volume() else ""
|
|
|
|
|
chapter_title = f"{chapter.get_title()}" if chapter.get_title() else ""
|
2024-07-23 17:31:23 +01:00
|
|
|
e = discord.Embed(
|
2024-07-24 03:24:11 +01:00
|
|
|
title=f'"{manga.get_title()}" Chapter {chapter_title} Released!',
|
|
|
|
|
description=f"{volume_info} Chapter {chapter.get_number()} of {manga.get_title()} Released."
|
2024-07-23 20:20:06 +01:00
|
|
|
f"\nGo read it now!",
|
2024-07-24 02:20:06 +01:00
|
|
|
url=chapter.get_url()
|
2024-07-23 17:31:23 +01:00
|
|
|
)
|
|
|
|
|
e.set_thumbnail(url=f"attachment://{manga.id}.{manga.get_cover_art_extension()}")
|
2024-07-23 20:20:06 +01:00
|
|
|
return e
|