taslim19
commited on
Commit
·
eb85327
1
Parent(s):
67b5fbf
fix: Make get_flood_settings robust to missing db keys
Browse files- DragMusic/utils/database.py +11 -10
DragMusic/utils/database.py
CHANGED
@@ -648,17 +648,18 @@ async def remove_banned_user(user_id: int):
|
|
648 |
|
649 |
# Antiflood Settings
|
650 |
async def get_flood_settings(chat_id: int):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
651 |
settings = await flooddb.find_one({"chat_id": chat_id})
|
652 |
-
if
|
653 |
-
|
654 |
-
|
655 |
-
"action": "ban",
|
656 |
-
"t_limit": 0, # Timed message count, 0 to disable
|
657 |
-
"t_duration": 30, # Timed duration in seconds
|
658 |
-
"action_duration": "1h", # Duration for tban/tmute
|
659 |
-
"clear": False, # Whether to delete flooding messages
|
660 |
-
}
|
661 |
-
return settings
|
662 |
|
663 |
async def update_flood_setting(chat_id: int, key: str, value):
|
664 |
await flooddb.update_one(
|
|
|
648 |
|
649 |
# Antiflood Settings
|
650 |
async def get_flood_settings(chat_id: int):
|
651 |
+
defaults = {
|
652 |
+
"limit": 0,
|
653 |
+
"action": "ban",
|
654 |
+
"t_limit": 0,
|
655 |
+
"t_duration": 30,
|
656 |
+
"action_duration": "1h",
|
657 |
+
"clear": False,
|
658 |
+
}
|
659 |
settings = await flooddb.find_one({"chat_id": chat_id})
|
660 |
+
if settings:
|
661 |
+
defaults.update(settings)
|
662 |
+
return defaults
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
663 |
|
664 |
async def update_flood_setting(chat_id: int, key: str, value):
|
665 |
await flooddb.update_one(
|