Fix game list

This commit is contained in:
2024-11-17 12:03:59 +01:00
parent 5f3bb3c1f8
commit 007555f1ca
2 changed files with 14 additions and 10 deletions

View File

@@ -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)

View File

@@ -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([
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