mirror of
https://github.com/kurbezz/discord-bot.git
synced 2025-12-06 15:15:37 +01:00
Fix game list
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user