Improve deletion by using buku function delete_resultset()

This commit is contained in:
Schimon Jehudah, Adv. 2024-06-03 18:46:55 +03:00
parent e27e87c43b
commit 3387dffeaa

View file

@ -78,27 +78,35 @@ class Chat:
# elif message.startswith('regex'): # elif message.startswith('regex'):
# message_body = bookmark_regexp(message[7:]) # message_body = bookmark_regexp(message[7:])
case _ if message_lowercase.startswith('del '): case _ if message_lowercase.startswith('del '):
val = message_lowercase[4:]
ixs = message_lowercase[4:].split(',') ixs = message_lowercase[4:].split(',')
message_body = '' ixs = set(ixs)
message_body = '*Deleted bookmarks*\n\n'
ixs_accepted = [] ixs_accepted = []
ixs_rejected = [] ixs_rejected = []
for ix in ixs: for ix in ixs:
try: try:
ixs_accepted.append(int(ix)) ix_as_int = int(ix)
if ix_as_int > 0:
ixs_accepted.append(ix_as_int)
else:
ixs_rejected.append(ix)
except: except:
ixs_rejected.append(ix) ixs_rejected.append(ix)
ixs_accepted.sort(reverse=True) ixs_accepted.sort(reverse=True)
ixs_approrved = []
for ix in ixs_accepted: for ix in ixs_accepted:
bookmark = bookmarks_db.get_rec_by_id(ix) bookmark = bookmarks_db.get_rec_by_id(ix)
if bookmark: message_body += Chat.format_message(bookmark, extended=True) if bookmark:
result = bookmarks_db.delete_rec(ix) ixs_approrved.append((ix,))
if result:
message_body += '\n*Bookmark has been deleted.*\n'
else: else:
message_body += '*Index {} does not exist.*\n'.format(ix) ixs_rejected.append(str(ix))
message_body += '\n' if ixs_approrved:
message_body += '*Rejected indexes:* {} (ID must be a number)'.format(', '.join(ixs_rejected)) for ix in ixs_approrved:
bookmark = bookmarks_db.get_rec_by_id(ix[0])
message_body += Chat.format_message(bookmark, extended=True) + '\n\n'
result = bookmarks_db.delete_resultset(list(ixs_approrved))
if ixs_rejected:
message_body += '*Deletion has failed for indexes:* {}'.format(', '.join(ixs_rejected))
case _ if message_lowercase.startswith('mod '): case _ if message_lowercase.startswith('mod '):
message_lowercase_split = message_lowercase[4:].split(' ') message_lowercase_split = message_lowercase[4:].split(' ')
if len(message_lowercase_split) > 2: if len(message_lowercase_split) > 2: