mirror of
https://github.com/kurbezz/discord-bot.git
synced 2025-12-06 07:05:36 +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_message.edit(content=str(game_list))
|
||||||
await game_list.save(streamer.twitch.id)
|
await game_list.save()
|
||||||
|
|
||||||
await interaction.response.send_message("Игра добавлена!", ephemeral=True)
|
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_message.edit(content=str(game_list))
|
||||||
await game_list.save(streamer.twitch.id)
|
await game_list.save()
|
||||||
|
|
||||||
await interaction.response.send_message("Игра удалена!", ephemeral=True)
|
await interaction.response.send_message("Игра удалена!", ephemeral=True)
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ class GameList:
|
|||||||
"gifts": "Подарки",
|
"gifts": "Подарки",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, data: list[Category]):
|
def __init__(self, twitch_id: int, data: list[Category]):
|
||||||
|
self.twitch_id = twitch_id
|
||||||
self.data = data
|
self.data = data
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -46,20 +47,23 @@ class GameList:
|
|||||||
if doc is None:
|
if doc is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return cls([
|
return cls(
|
||||||
Category(**category)
|
twitch_id,
|
||||||
for category in doc["data"]
|
[
|
||||||
])
|
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:
|
async with mongo_manager.connect() as client:
|
||||||
db = client.get_default_database()
|
db = client.get_default_database()
|
||||||
collection = db[self.COLLECTION_NAME]
|
collection = db[self.COLLECTION_NAME]
|
||||||
|
|
||||||
await collection.replace_one(
|
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]
|
"data": [category.model_dump() for category in self.data]
|
||||||
},
|
},
|
||||||
upsert=True
|
upsert=True
|
||||||
|
|||||||
Reference in New Issue
Block a user