mirror of
https://codeberg.org/sch/BukuBot
synced 2024-12-22 18:05:24 +01:00
Improve deletion by using buku function delete_resultset()
This commit is contained in:
parent
e27e87c43b
commit
3387dffeaa
1 changed files with 19 additions and 11 deletions
|
@ -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) if result else 'Index{} does not exist.'.format(idx)
|
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)
|
||||||
|
@ -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:
|
||||||
|
|
Loading…
Reference in a new issue