Skip to content

Commit 0999fcb

Browse files
committed
fix: undefined message when handling server update
1 parent 81c8b24 commit 0999fcb

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

nazurin/bot.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from nazurin.storage import Storage
1515
from nazurin.utils import logger
1616
from nazurin.utils.decorators import retry_after
17-
from nazurin.utils.exceptions import NazurinError
17+
from nazurin.utils.exceptions import AlreadyExistsError, NazurinError
1818
from nazurin.utils.helpers import (
1919
handle_bad_request,
2020
remove_files_older_than,
@@ -153,8 +153,7 @@ async def update_collection(
153153
db = Database().driver()
154154
collection = db.collection(document.collection)
155155
if await collection.document(document.id).exists():
156-
await message.reply("Already exists in database, skipped update.")
157-
return True
156+
raise AlreadyExistsError
158157

159158
# Send / Forward to gallery & Save to album
160159
download = asyncio.create_task(illust.download())
@@ -167,7 +166,6 @@ async def update_collection(
167166
await self.storage.store(illust)
168167
document.data["collected_at"] = time()
169168
await collection.insert(document.id, document.data)
170-
await message.reply("Done!")
171169
return True
172170

173171
async def cleanup_temp_dir(self):

nazurin/dispatcher.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from nazurin import config
99
from nazurin.utils import logger
10+
from nazurin.utils.exceptions import AlreadyExistsError
1011
from nazurin.utils.filters import URLFilter
1112

1213
from .bot import NazurinBot
@@ -116,4 +117,8 @@ def start(self):
116117
self.executor.start_polling()
117118

118119
async def update_collection(self, message: Message, urls: List[str]):
119-
await self.bot.update_collection(urls, message)
120+
try:
121+
await self.bot.update_collection(urls, message)
122+
await message.reply("Done!")
123+
except AlreadyExistsError as error:
124+
await message.reply(error.msg)

nazurin/server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def do_update(self, url):
4242
)
4343
except NazurinError as error:
4444
await self.bot.send_message(
45-
config.ADMIN_ID, f"Error processing {url}: {format_error(error)}"
45+
config.ADMIN_ID, f"Error processing {url}: {error}"
4646
)
4747
# pylint: disable-next=broad-exception-caught
4848
except Exception as error:

nazurin/utils/exceptions.py

+5
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ class InvalidCommandUsage(NazurinError):
1717
def __init__(self, command):
1818
self.command = command
1919
super().__init__(f"Invalid usage of command {command}")
20+
21+
22+
class AlreadyExistsError(NazurinError):
23+
def __init__(self, msg="Already exists in database, skipped update."):
24+
super().__init__(msg)

0 commit comments

Comments
 (0)