Fix error upon an attempt to display information from an id which does not exist; Allow a deletion of multiple bookmarks.

This commit is contained in:
Schimon Jehudah, Adv. 2024-06-02 18:51:00 +03:00
parent b1891f33ac
commit e27e87c43b

View file

@ -48,7 +48,7 @@ class Chat:
case _ if message_lowercase.startswith('id'): case _ if message_lowercase.startswith('id'):
idx = message_lowercase[2:] idx = message_lowercase[2:]
result = bookmarks_db.get_rec_by_id(idx) result = bookmarks_db.get_rec_by_id(idx)
message_body = Chat.format_message(result, extended=True) message_body = Chat.format_message(result, extended=True) if result else 'Index{} does not exist.'.format(idx)
case 'last': case 'last':
idx = bookmarks_db.get_max_id() idx = bookmarks_db.get_max_id()
result = bookmarks_db.get_rec_by_id(idx) result = bookmarks_db.get_rec_by_id(idx)
@ -79,17 +79,26 @@ class Chat:
# 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:] val = message_lowercase[4:]
try: ixs = message_lowercase[4:].split(',')
idx = int(val) message_body = ''
except: ixs_accepted = []
idx = bookmarks_db.get_rec_id(val) ixs_rejected = []
bookmark = bookmarks_db.get_rec_by_id(idx) for ix in ixs:
message_body = Chat.format_message(bookmark, extended=True) if bookmark else '' try:
result = bookmarks_db.delete_rec(idx) ixs_accepted.append(int(ix))
if result: except:
message_body += '\n*Bookmark has been deleted.*' ixs_rejected.append(ix)
else: ixs_accepted.sort(reverse=True)
message_body += '\n*No action has been taken for index {}*'.format(idx) for ix in ixs_accepted:
bookmark = bookmarks_db.get_rec_by_id(ix)
if bookmark: message_body += Chat.format_message(bookmark, extended=True)
result = bookmarks_db.delete_rec(ix)
if result:
message_body += '\n*Bookmark has been deleted.*\n'
else:
message_body += '*Index {} does not exist.*\n'.format(ix)
message_body += '\n'
message_body += '*Rejected indexes:* {} (ID must be a number)'.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:
@ -126,14 +135,9 @@ class Chat:
message_lowercase.startswith('tag -')): message_lowercase.startswith('tag -')):
message_lowercase_split = message_lowercase[4:].split(' ') message_lowercase_split = message_lowercase[4:].split(' ')
try: try:
int(message_lowercase_split[1])
if len(message_lowercase_split) > 2: if len(message_lowercase_split) > 2:
arg = message_lowercase_split[0] arg = message_lowercase_split[0]
val = message_lowercase_split[1] idx = int(message_lowercase_split[1])
try:
idx = int(val)
except:
idx = bookmarks_db.get_rec_id(val)
# tag = ',' + ' '.join(message_lowercase_split[2:]) + ',' # tag = ',' + ' '.join(message_lowercase_split[2:]) + ','
# tag = ' '.join(message_lowercase_split[2:]) # tag = ' '.join(message_lowercase_split[2:])
tag = arg + ',' + ' '.join(message_lowercase_split[2:]) tag = arg + ',' + ' '.join(message_lowercase_split[2:])