mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
splitted cmd_cerca
the message creation is now a standalone function to allow different search methonds
This commit is contained in:
parent
7bdad85818
commit
b2dabce864
1 changed files with 9 additions and 7 deletions
|
@ -307,17 +307,19 @@ def cmd_cerca(bot: Bot, update: Update):
|
||||||
return
|
return
|
||||||
queryText = queryText.replace('%', '\\%').replace('_', '\\_')
|
queryText = queryText.replace('%', '\\%').replace('_', '\\_')
|
||||||
entries = session.query(db.Diario).filter(text(f"text ~* '(?:[^\w\d]+{queryText}[^\w\d]+|^{queryText}[^\w\d]+|^{queryText}$|[^\w\d]+{queryText}$)'")).order_by(db.Diario.id).all()
|
entries = session.query(db.Diario).filter(text(f"text ~* '(?:[^\w\d]+{queryText}[^\w\d]+|^{queryText}[^\w\d]+|^{queryText}$|[^\w\d]+{queryText}$)'")).order_by(db.Diario.id).all()
|
||||||
msg = f"Risultati della ricerca di {queryText}:\n"
|
cerca_message(bot, update, queryText, entries)
|
||||||
for entry in entries[:5]:
|
finally:
|
||||||
msg += f'<a href="https://ryg.steffo.eu/diario#entry-{entry.id}">#{entry.id}</a> di {entry.author or "Anonimo"}\n{entry.text}\n\n'
|
session.close()
|
||||||
|
|
||||||
|
def cerca_message (bot: Bot, update: Update, queryText, entries):
|
||||||
|
msg = f"Risultati della ricerca di {queryText}:\n"
|
||||||
|
for entry in entries[:5]:
|
||||||
|
msg += f'<a href="https://ryg.steffo.eu/diario#entry-{entry.id}">#{entry.id}</a> di {entry.author or "Anonimo"}\n{entry.text}\n\n'
|
||||||
if len(entries) > 5:
|
if len(entries) > 5:
|
||||||
msg += "I termini comapiono anche nelle righe:\n"
|
msg += "I termini comapiono anche nelle righe:\n"
|
||||||
for entry in entries[5:]:
|
for entry in entries[5:]:
|
||||||
msg += f'<a href="https://ryg.steffo.eu/diario#entry-{entry.id}">#{entry.id}</a> '
|
msg += f'<a href="https://ryg.steffo.eu/diario#entry-{entry.id}">#{entry.id}</a> '
|
||||||
bot.send_message(update.message.chat.id, msg, parse_mode="HTML")
|
bot.send_message(update.message.chat.id, msg, parse_mode="HTML")
|
||||||
finally:
|
|
||||||
session.close()
|
|
||||||
|
|
||||||
|
|
||||||
@catch_and_report
|
@catch_and_report
|
||||||
def cmd_mm(bot: Bot, update: Update):
|
def cmd_mm(bot: Bot, update: Update):
|
||||||
|
|
Loading…
Reference in a new issue