From b1891f33ac1473cc526358d50dbc592798bedca9 Mon Sep 17 00:00:00 2001 From: "Schimon Jehudah, Adv." Date: Sun, 2 Jun 2024 16:23:10 +0300 Subject: [PATCH] Check whether second parameter is an integer (Thank you mirux). --- bukubot/xmpp/chat.py | 52 ++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/bukubot/xmpp/chat.py b/bukubot/xmpp/chat.py index 3884be3..2fdefe9 100644 --- a/bukubot/xmpp/chat.py +++ b/bukubot/xmpp/chat.py @@ -125,31 +125,35 @@ class Chat: case _ if (message_lowercase.startswith('tag +') or message_lowercase.startswith('tag -')): message_lowercase_split = message_lowercase[4:].split(' ') - if len(message_lowercase_split) > 2: - arg = message_lowercase_split[0] - val = 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 = arg + ',' + ' '.join(message_lowercase_split[2:]) - tag = tag.replace(' ,', ',') - tag = tag.replace(', ', ',') - result = bookmarks_db.update_rec(idx, tags_in=tag) - bookmark = bookmarks_db.get_rec_by_id(idx) - if result: - message_body = Chat.format_message(bookmark, extended=True) if bookmark else '' - message_body += '\n*Bookmark has been updated.*' + try: + int(message_lowercase_split[1]) + if len(message_lowercase_split) > 2: + arg = message_lowercase_split[0] + val = 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 = arg + ',' + ' '.join(message_lowercase_split[2:]) + tag = tag.replace(' ,', ',') + tag = tag.replace(', ', ',') + result = bookmarks_db.update_rec(idx, tags_in=tag) + bookmark = bookmarks_db.get_rec_by_id(idx) + 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: - message_body = '\n*No action has been taken for index {}*'.format(idx) - else: - message_body = ('Missing argument. ' - 'Require three arguments: ' - '(1) + or - sign; ' - '(2) or ; ' - '(3) .') + message_body = ('Missing argument. ' + 'Require three arguments: ' + '(1) + or - sign; ' + '(2) or ; ' + '(3) .') + except: + message_body = 'Second parameter must be an ID number.' case _ if message_lowercase.startswith('tag'): tag = message_lowercase[4:] results = bookmarks_db.search_by_tag(tag)