fixed + notifications
This commit is contained in:
parent
3b63d71882
commit
464b0a85ae
|
|
@ -44,12 +44,12 @@ class ListManga(discord.ui.View):
|
||||||
@discord.ui.button(label='Add', style=discord.ButtonStyle.green)
|
@discord.ui.button(label='Add', style=discord.ButtonStyle.green)
|
||||||
async def add(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def add(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
await interaction.response.defer()
|
await interaction.response.defer()
|
||||||
self.ret.append({"manga": self.manga_list[self.index], "action": 1})
|
self.ret.append({"manga": self.manga_list[self.index].id, "action": 1})
|
||||||
|
|
||||||
@discord.ui.button(label='Remove', style=discord.ButtonStyle.red)
|
@discord.ui.button(label='Remove', style=discord.ButtonStyle.red)
|
||||||
async def remove(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def remove(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
await interaction.response.defer()
|
await interaction.response.defer()
|
||||||
self.ret.append({"manga": self.manga_list[self.index], "action": -1})
|
self.ret.append({"manga": self.manga_list[self.index].id, "action": -1})
|
||||||
|
|
||||||
@discord.ui.button(label='Done', style=discord.ButtonStyle.blurple)
|
@discord.ui.button(label='Done', style=discord.ButtonStyle.blurple)
|
||||||
async def exit(self, interaction: discord.Interaction, button: discord.ui.Button):
|
async def exit(self, interaction: discord.Interaction, button: discord.ui.Button):
|
||||||
|
|
|
||||||
3
main.py
3
main.py
|
|
@ -9,7 +9,6 @@ import manager
|
||||||
import manga_api
|
import manga_api
|
||||||
|
|
||||||
mh = manga_api.MangaHandler()
|
mh = manga_api.MangaHandler()
|
||||||
man = manager.Manager()
|
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
|
|
@ -17,6 +16,8 @@ intents = discord.Intents.default()
|
||||||
client = discord.Client(intents=intents)
|
client = discord.Client(intents=intents)
|
||||||
tree = app_commands.CommandTree(client)
|
tree = app_commands.CommandTree(client)
|
||||||
|
|
||||||
|
man = manager.Manager(client)
|
||||||
|
|
||||||
|
|
||||||
@tree.command(
|
@tree.command(
|
||||||
name="ping",
|
name="ping",
|
||||||
|
|
|
||||||
11
manager.py
11
manager.py
|
|
@ -4,15 +4,22 @@ import embed_util
|
||||||
import manga_api
|
import manga_api
|
||||||
|
|
||||||
class Manager:
|
class Manager:
|
||||||
def __init__(self):
|
def __init__(self, client):
|
||||||
|
self.client: discord.Client = client
|
||||||
self.manga = {}
|
self.manga = {}
|
||||||
self.chapters = {}
|
self.chapters = {}
|
||||||
|
|
||||||
def add_user_to_manga(self, user: discord.User, manga: manga_api.Manga) -> None:
|
def add_user_to_manga(self, user: discord.User, manga: manga_api.Manga) -> None:
|
||||||
|
if manga.id in self.manga.keys():
|
||||||
self.manga[manga.id].append(user.id)
|
self.manga[manga.id].append(user.id)
|
||||||
|
else:
|
||||||
|
self.manga[manga.id] = [user.id]
|
||||||
|
|
||||||
def remove_user_from_manga(self, user: discord.User, manga: manga_api.Manga) -> None:
|
def remove_user_from_manga(self, user: discord.User, manga: manga_api.Manga) -> None:
|
||||||
|
if manga.id in self.manga.keys():
|
||||||
self.manga[manga.id].remove(user.id)
|
self.manga[manga.id].remove(user.id)
|
||||||
|
else:
|
||||||
|
self.manga[manga.id] = []
|
||||||
|
|
||||||
async def update(self):
|
async def update(self):
|
||||||
for manga_id in self.manga.keys():
|
for manga_id in self.manga.keys():
|
||||||
|
|
@ -21,7 +28,7 @@ class Manager:
|
||||||
if new_chap is not None:
|
if new_chap is not None:
|
||||||
users = self.manga[manga_id]
|
users = self.manga[manga_id]
|
||||||
for user in users:
|
for user in users:
|
||||||
await self.send_message_to_user(user, manga, new_chap)
|
await self.send_message_to_user(self.client.get_user(user), manga, new_chap)
|
||||||
|
|
||||||
def check_for_new_chapter(self, manga: manga_api.Manga) -> manga_api.Chapter | None:
|
def check_for_new_chapter(self, manga: manga_api.Manga) -> manga_api.Chapter | None:
|
||||||
latest_chap = manga.get_latest_chap()
|
latest_chap = manga.get_latest_chap()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue