attempt
This commit is contained in:
parent
189ae77abf
commit
3b63d71882
|
|
@ -1,4 +1,4 @@
|
|||
from manga import Manga, Chapter
|
||||
from manga_api import Manga, Chapter
|
||||
import discord
|
||||
import os.path
|
||||
|
||||
|
|
@ -61,7 +61,6 @@ class ListManga(discord.ui.View):
|
|||
|
||||
|
||||
def gen_manga_files(manga_list: list[Manga]):
|
||||
|
||||
return parallel_downloads.parallel_download(manga_list)
|
||||
|
||||
|
||||
|
|
@ -71,3 +70,16 @@ def manga_embed(manga: Manga):
|
|||
e.set_thumbnail(url=f"attachment://{manga.id}.{extension}")
|
||||
|
||||
return e
|
||||
|
||||
|
||||
def get_chapter_files(manga: Manga):
|
||||
return parallel_downloads.parallel_download([manga])
|
||||
|
||||
|
||||
def chapter_embed(manga: Manga, chapter: Chapter):
|
||||
e = discord.Embed(
|
||||
title=f'New "{manga.get_title()}" Chapter Released!',
|
||||
description=f"Chapter {chapter.get_chapter_num()} of {manga.get_title()} Released."
|
||||
f"Go read it now!"
|
||||
)
|
||||
e.set_thumbnail(url=f"attachment://{manga.id}.{manga.get_cover_art_extension()}")
|
||||
|
|
|
|||
21
main.py
21
main.py
|
|
@ -5,9 +5,11 @@ from discord import app_commands
|
|||
from dotenv import load_dotenv
|
||||
|
||||
import embed_util
|
||||
import manga
|
||||
import manager
|
||||
import manga_api
|
||||
|
||||
mh = manga.MangaHandler()
|
||||
mh = manga_api.MangaHandler()
|
||||
man = manager.Manager()
|
||||
|
||||
load_dotenv()
|
||||
|
||||
|
|
@ -44,9 +46,20 @@ async def search_command(
|
|||
await chanel.send(f"Hey, you searched for {title}")
|
||||
msg = await chanel.send(view=view, embed=embed_util.manga_embed(manga_list[0]))
|
||||
await view.force_reload(msg)
|
||||
ret = await view.wait()
|
||||
print(ret)
|
||||
await view.wait()
|
||||
|
||||
ret: list[dict] = view.ret
|
||||
for action in ret:
|
||||
if action["action"] == 1:
|
||||
manga_id = action["manga"]
|
||||
man.add_user_to_manga(interaction.user, manga_api.Manga(manga_id))
|
||||
if action["action"] == -1:
|
||||
manga_id = action["manga"]
|
||||
man.remove_user_from_manga(interaction.user, manga_api.Manga(manga_id))
|
||||
|
||||
|
||||
await chanel.send("Done")
|
||||
await man.update()
|
||||
|
||||
|
||||
@client.event
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
import discord
|
||||
|
||||
import embed_util
|
||||
import manga_api
|
||||
|
||||
class Manager:
|
||||
def __init__(self):
|
||||
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)
|
||||
|
||||
def remove_user_from_manga(self, user: discord.User, manga: manga_api.Manga) -> None:
|
||||
self.manga[manga.id].remove(user.id)
|
||||
|
||||
async def update(self):
|
||||
for manga_id in self.manga.keys():
|
||||
manga = manga_api.Manga(manga_id)
|
||||
new_chap = self.check_for_new_chapter(manga)
|
||||
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)
|
||||
|
||||
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():
|
||||
self.chapters[manga.id] = latest_chap
|
||||
return latest_chap
|
||||
if float(latest_chap.get_chapter_num()) > self.chapters[manga.id]:
|
||||
self.chapters[manga.id] = latest_chap
|
||||
return latest_chap
|
||||
else:
|
||||
return None
|
||||
|
||||
async def send_message_to_user(self, user: discord.User, manga: manga_api.Manga, chapter: manga_api.Chapter) -> None:
|
||||
dm_channel = await user.create_dm()
|
||||
await dm_channel.send(embed=embed_util.chapter_embed(manga, chapter), files=embed_util.get_chapter_files(manga))
|
||||
|
|
@ -4,7 +4,7 @@ import os.path
|
|||
|
||||
|
||||
import discord
|
||||
from manga import Manga
|
||||
from manga_api import Manga
|
||||
|
||||
|
||||
def download_file(manga: Manga):
|
||||
|
|
|
|||
Loading…
Reference in New Issue