From 0b720ef770b5c9091039ebbf3cefa9b3aab4f36f Mon Sep 17 00:00:00 2001 From: profitroll Date: Wed, 30 Aug 2023 12:52:31 +0200 Subject: [PATCH] OperationFailure handling added --- plugins/commands/upcoming.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/plugins/commands/upcoming.py b/plugins/commands/upcoming.py index 262e53b..b96665f 100644 --- a/plugins/commands/upcoming.py +++ b/plugins/commands/upcoming.py @@ -1,5 +1,6 @@ from datetime import datetime, timedelta, timezone +from pymongo.errors import OperationFailure from pyrogram import filters from pyrogram.types import Message from pytz import timezone as pytz_timezone @@ -33,15 +34,23 @@ async def command_upcoming(app: PyroClient, message: Message): + timedelta(days=30) ).replace(tzinfo=timezone.utc) - entries = [ - await GarbageEntry.from_record(entry) - async for entry in col_entries.find( - { - "location": {"$in": user.location.id}, - "date": {"$gte": date_min, "$lte": date_max}, - } + try: + entries = [ + await GarbageEntry.from_record(entry) + async for entry in col_entries.find( + { + "location": {"$in": user.location.id}, + "date": {"$gte": date_min, "$lte": date_max}, + } + ) + ] + except OperationFailure: + await message.reply_text( + app._("upcoming_empty", "messages", locale=user.locale).format( + name=user.location.name + ) ) - ] + return entries_text = "\n\n".join( [