Set argument extended as optional (default is False)

This commit is contained in:
Schimon Jehudah 2024-02-28 23:25:36 +00:00
parent 6d921ab070
commit 27f843d3b6

View file

@ -220,11 +220,11 @@ class Slixmark(slixmpp.ClientXMPP):
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 = self.format_message(result, True) message_body = self.format_message(result, extended=True)
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)
message_body = self.format_message(result, False) message_body = self.format_message(result)
case _ if message_lowercase.startswith('search any '): case _ if message_lowercase.startswith('search any '):
query = message_lowercase[11:] query = message_lowercase[11:]
query = query.split(' ') query = query.split(' ')
@ -234,7 +234,7 @@ class Slixmark(slixmpp.ClientXMPP):
regex=False) regex=False)
message_body = '*Results for query: {}*\n\n'.format(query) message_body = '*Results for query: {}*\n\n'.format(query)
for result in results: for result in results:
message_body += self.format_message(result, False) + '\n\n' message_body += self.format_message(result) + '\n\n'
message_body += '*Total of {} results*'.format(len(results)) message_body += '*Total of {} results*'.format(len(results))
case _ if message_lowercase.startswith('search '): case _ if message_lowercase.startswith('search '):
query = message_lowercase[7:] query = message_lowercase[7:]
@ -245,7 +245,7 @@ class Slixmark(slixmpp.ClientXMPP):
regex=False) regex=False)
message_body = '*Results for query: {}*\n\n'.format(query) message_body = '*Results for query: {}*\n\n'.format(query)
for result in results: for result in results:
message_body += self.format_message(result, False) + '\n\n' message_body += self.format_message(result) + '\n\n'
message_body += '*Total of {} results*\n\n'.format(len(results)) message_body += '*Total of {} results*\n\n'.format(len(results))
# elif message.startswith('regex'): # elif message.startswith('regex'):
# message_body = bookmark_regexp(message[7:]) # message_body = bookmark_regexp(message[7:])
@ -256,7 +256,7 @@ class Slixmark(slixmpp.ClientXMPP):
except: except:
idx = bookmarks_db.get_rec_id(val) idx = bookmarks_db.get_rec_id(val)
bookmark = bookmarks_db.get_rec_by_id(idx) bookmark = bookmarks_db.get_rec_by_id(idx)
message_body = self.format_message(bookmark, True) if bookmark else '' message_body = self.format_message(bookmark, extended=True) if bookmark else ''
result = bookmarks_db.delete_rec(idx) result = bookmarks_db.delete_rec(idx)
if result: if result:
message_body += '\n*Bookmark has been deleted.*' message_body += '\n*Bookmark has been deleted.*'
@ -283,7 +283,7 @@ class Slixmark(slixmpp.ClientXMPP):
message_body = ('*Invalid argument. ' message_body = ('*Invalid argument. '
'Must be "name" or "note".*\n') 'Must be "name" or "note".*\n')
bookmark = bookmarks_db.get_rec_by_id(idx) bookmark = bookmarks_db.get_rec_by_id(idx)
message_body += self.format_message(bookmark, True) if bookmark else '' message_body += self.format_message(bookmark, extended=True) if bookmark else ''
if result: if result:
message_body += '\n*Bookmark has been deleted.*' message_body += '\n*Bookmark has been deleted.*'
else: else:
@ -312,7 +312,7 @@ class Slixmark(slixmpp.ClientXMPP):
result = bookmarks_db.update_rec(idx, tags_in=tag) result = bookmarks_db.update_rec(idx, tags_in=tag)
bookmark = bookmarks_db.get_rec_by_id(idx) bookmark = bookmarks_db.get_rec_by_id(idx)
if result: if result:
message_body = self.format_message(bookmark, True) if bookmark else '' message_body = self.format_message(bookmark, extended=True) if bookmark else ''
message_body += '\n*Bookmark has been updated.*' message_body += '\n*Bookmark has been updated.*'
else: else:
message_body = '\n*No action has been taken for index {}*'.format(idx) message_body = '\n*No action has been taken for index {}*'.format(idx)
@ -327,7 +327,7 @@ class Slixmark(slixmpp.ClientXMPP):
results = bookmarks_db.search_by_tag(tag) results = bookmarks_db.search_by_tag(tag)
message_body = '*Results for tag: {}*\n\n'.format(tag) message_body = '*Results for tag: {}*\n\n'.format(tag)
for result in results: for result in results:
message_body += self.format_message(result, False) + '\n\n' message_body += self.format_message(result) + '\n\n'
message_body += '*Total of {} results*'.format(len(results)) message_body += '*Total of {} results*'.format(len(results))
case _: case _:
message_body = ('Unknown command. Send "help" for list ' message_body = ('Unknown command. Send "help" for list '
@ -335,7 +335,7 @@ class Slixmark(slixmpp.ClientXMPP):
message.reply(message_body).send() message.reply(message_body).send()
#message.reply("Thanks for sending\n%(body)s" % message).send() #message.reply("Thanks for sending\n%(body)s" % message).send()
def format_message(self, bookmark, extended): def format_message(self, bookmark, extended=False):
idx = bookmark.id idx = bookmark.id
url = bookmark.url url = bookmark.url
name = bookmark.title if bookmark.title else 'Untitled' name = bookmark.title if bookmark.title else 'Untitled'