Commit 0999fcb 1 parent 81c8b24 commit 0999fcb Copy full SHA for 0999fcb
File tree 4 files changed +14
-6
lines changed
4 files changed +14
-6
lines changed Original file line number Diff line number Diff line change 14
14
from nazurin .storage import Storage
15
15
from nazurin .utils import logger
16
16
from nazurin .utils .decorators import retry_after
17
- from nazurin .utils .exceptions import NazurinError
17
+ from nazurin .utils .exceptions import AlreadyExistsError , NazurinError
18
18
from nazurin .utils .helpers import (
19
19
handle_bad_request ,
20
20
remove_files_older_than ,
@@ -153,8 +153,7 @@ async def update_collection(
153
153
db = Database ().driver ()
154
154
collection = db .collection (document .collection )
155
155
if await collection .document (document .id ).exists ():
156
- await message .reply ("Already exists in database, skipped update." )
157
- return True
156
+ raise AlreadyExistsError
158
157
159
158
# Send / Forward to gallery & Save to album
160
159
download = asyncio .create_task (illust .download ())
@@ -167,7 +166,6 @@ async def update_collection(
167
166
await self .storage .store (illust )
168
167
document .data ["collected_at" ] = time ()
169
168
await collection .insert (document .id , document .data )
170
- await message .reply ("Done!" )
171
169
return True
172
170
173
171
async def cleanup_temp_dir (self ):
Original file line number Diff line number Diff line change 7
7
8
8
from nazurin import config
9
9
from nazurin .utils import logger
10
+ from nazurin .utils .exceptions import AlreadyExistsError
10
11
from nazurin .utils .filters import URLFilter
11
12
12
13
from .bot import NazurinBot
@@ -116,4 +117,8 @@ def start(self):
116
117
self .executor .start_polling ()
117
118
118
119
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 )
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ async def do_update(self, url):
42
42
)
43
43
except NazurinError as error :
44
44
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 } "
46
46
)
47
47
# pylint: disable-next=broad-exception-caught
48
48
except Exception as error :
Original file line number Diff line number Diff line change @@ -17,3 +17,8 @@ class InvalidCommandUsage(NazurinError):
17
17
def __init__ (self , command ):
18
18
self .command = command
19
19
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 )
You can’t perform that action at this time.
0 commit comments