Check whether second parameter is an integer (Thank you mirux).

This commit is contained in:
Schimon Jehudah, Adv. 2024-06-02 16:23:10 +03:00
parent c1a5d8d5a6
commit b1891f33ac

View file

@ -125,31 +125,35 @@ class Chat:
case _ if (message_lowercase.startswith('tag +') or case _ if (message_lowercase.startswith('tag +') or
message_lowercase.startswith('tag -')): message_lowercase.startswith('tag -')):
message_lowercase_split = message_lowercase[4:].split(' ') message_lowercase_split = message_lowercase[4:].split(' ')
if len(message_lowercase_split) > 2: try:
arg = message_lowercase_split[0] int(message_lowercase_split[1])
val = message_lowercase_split[1] if len(message_lowercase_split) > 2:
try: arg = message_lowercase_split[0]
idx = int(val) val = message_lowercase_split[1]
except: try:
idx = bookmarks_db.get_rec_id(val) idx = int(val)
# tag = ',' + ' '.join(message_lowercase_split[2:]) + ',' except:
# tag = ' '.join(message_lowercase_split[2:]) idx = bookmarks_db.get_rec_id(val)
tag = arg + ',' + ' '.join(message_lowercase_split[2:]) # tag = ',' + ' '.join(message_lowercase_split[2:]) + ','
tag = tag.replace(' ,', ',') # tag = ' '.join(message_lowercase_split[2:])
tag = tag.replace(', ', ',') tag = arg + ',' + ' '.join(message_lowercase_split[2:])
result = bookmarks_db.update_rec(idx, tags_in=tag) tag = tag.replace(' ,', ',')
bookmark = bookmarks_db.get_rec_by_id(idx) tag = tag.replace(', ', ',')
if result: result = bookmarks_db.update_rec(idx, tags_in=tag)
message_body = Chat.format_message(bookmark, extended=True) if bookmark else '' bookmark = bookmarks_db.get_rec_by_id(idx)
message_body += '\n*Bookmark has been updated.*' if result:
message_body = Chat.format_message(bookmark, extended=True) if bookmark else ''
message_body += '\n*Bookmark has been updated.*'
else:
message_body = '\n*No action has been taken for index {}*'.format(idx)
else: else:
message_body = '\n*No action has been taken for index {}*'.format(idx) message_body = ('Missing argument. '
else: 'Require three arguments: '
message_body = ('Missing argument. ' '(1) + or - sign; '
'Require three arguments: ' '(2) <ID> or <URL>; '
'(1) + or - sign; ' '(3) <TAGS>.')
'(2) <ID> or <URL>; ' except:
'(3) <TAGS>.') message_body = 'Second parameter must be an ID number.'
case _ if message_lowercase.startswith('tag'): case _ if message_lowercase.startswith('tag'):
tag = message_lowercase[4:] tag = message_lowercase[4:]
results = bookmarks_db.search_by_tag(tag) results = bookmarks_db.search_by_tag(tag)