Skip to content

Commit

Permalink
fix: undefined message when handling server update
Browse files Browse the repository at this point in the history
  • Loading branch information
y-young committed Apr 6, 2024
1 parent 81c8b24 commit 0999fcb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
6 changes: 2 additions & 4 deletions nazurin/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from nazurin.storage import Storage
from nazurin.utils import logger
from nazurin.utils.decorators import retry_after
from nazurin.utils.exceptions import NazurinError
from nazurin.utils.exceptions import AlreadyExistsError, NazurinError
from nazurin.utils.helpers import (
handle_bad_request,
remove_files_older_than,
Expand Down Expand Up @@ -153,8 +153,7 @@ async def update_collection(
db = Database().driver()
collection = db.collection(document.collection)
if await collection.document(document.id).exists():
await message.reply("Already exists in database, skipped update.")
return True
raise AlreadyExistsError

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

async def cleanup_temp_dir(self):
Expand Down
7 changes: 6 additions & 1 deletion nazurin/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from nazurin import config
from nazurin.utils import logger
from nazurin.utils.exceptions import AlreadyExistsError
from nazurin.utils.filters import URLFilter

from .bot import NazurinBot
Expand Down Expand Up @@ -116,4 +117,8 @@ def start(self):
self.executor.start_polling()

async def update_collection(self, message: Message, urls: List[str]):
await self.bot.update_collection(urls, message)
try:
await self.bot.update_collection(urls, message)
await message.reply("Done!")
except AlreadyExistsError as error:
await message.reply(error.msg)
2 changes: 1 addition & 1 deletion nazurin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def do_update(self, url):
)
except NazurinError as error:
await self.bot.send_message(
config.ADMIN_ID, f"Error processing {url}: {format_error(error)}"
config.ADMIN_ID, f"Error processing {url}: {error}"
)
# pylint: disable-next=broad-exception-caught
except Exception as error:
Expand Down
5 changes: 5 additions & 0 deletions nazurin/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ class InvalidCommandUsage(NazurinError):
def __init__(self, command):
self.command = command
super().__init__(f"Invalid usage of command {command}")


class AlreadyExistsError(NazurinError):
def __init__(self, msg="Already exists in database, skipped update."):
super().__init__(msg)

0 comments on commit 0999fcb

Please sign in to comment.