From 007555f1ca7f9e9f52db3ff01778038f75c87a05 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Sun, 17 Nov 2024 12:03:59 +0100 Subject: [PATCH] Fix game list --- src/modules/games_list/discord.py | 4 ++-- src/modules/games_list/games_list.py | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/modules/games_list/discord.py b/src/modules/games_list/discord.py index 800bf1c..aa94c27 100644 --- a/src/modules/games_list/discord.py +++ b/src/modules/games_list/discord.py @@ -124,7 +124,7 @@ async def add( ) await game_list_message.edit(content=str(game_list)) - await game_list.save(streamer.twitch.id) + await game_list.save() await interaction.response.send_message("Игра добавлена!", ephemeral=True) @@ -188,7 +188,7 @@ async def delete(interaction: discord.Interaction, game: str): ) await game_list_message.edit(content=str(game_list)) - await game_list.save(streamer.twitch.id) + await game_list.save() await interaction.response.send_message("Игра удалена!", ephemeral=True) diff --git a/src/modules/games_list/games_list.py b/src/modules/games_list/games_list.py index e4e4cfd..14d46b7 100644 --- a/src/modules/games_list/games_list.py +++ b/src/modules/games_list/games_list.py @@ -33,7 +33,8 @@ class GameList: "gifts": "Подарки", } - def __init__(self, data: list[Category]): + def __init__(self, twitch_id: int, data: list[Category]): + self.twitch_id = twitch_id self.data = data @classmethod @@ -46,20 +47,23 @@ class GameList: if doc is None: return None - return cls([ - Category(**category) - for category in doc["data"] - ]) + return cls( + twitch_id, + [ + Category(**category) + for category in doc["data"] + ] + ) - async def save(self, twitch_id: int): + async def save(self): async with mongo_manager.connect() as client: db = client.get_default_database() collection = db[self.COLLECTION_NAME] await collection.replace_one( - {"twitch_id": twitch_id}, + {"twitch_id": self.twitch_id}, { - "twitch_id": twitch_id, + "twitch_id": self.twitch_id, "data": [category.model_dump() for category in self.data] }, upsert=True