mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
implemented /regex
it is kinda broken, if the result set is really large, it does nothing
This commit is contained in:
parent
b2dabce864
commit
bd672f9330
1 changed files with 16 additions and 0 deletions
|
@ -311,6 +311,21 @@ def cmd_cerca(bot: Bot, update: Update):
|
||||||
finally:
|
finally:
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
|
@catch_and_report
|
||||||
|
def cmd_regex_diario(bot: Bot, update: Update):
|
||||||
|
session = db.Session()
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
queryText = update.message.text.split(" ", 1)[1]
|
||||||
|
except IndexError:
|
||||||
|
bot.send_message(update.message.chat.id, s(strings.DIARIO_SEARCH.ERRORS.INVALID_SYNTAX))
|
||||||
|
return
|
||||||
|
queryText = queryText.replace('%', '\\%').replace('_', '\\_')
|
||||||
|
entries = session.query(db.Diario).filter(text(f"text ~* '{queryText}'")).order_by(db.Diario.id).all()
|
||||||
|
cerca_message(bot, update, queryText, entries)
|
||||||
|
finally:
|
||||||
|
session.close()
|
||||||
|
|
||||||
def cerca_message (bot: Bot, update: Update, queryText, entries):
|
def cerca_message (bot: Bot, update: Update, queryText, entries):
|
||||||
msg = f"Risultati della ricerca di {queryText}:\n"
|
msg = f"Risultati della ricerca di {queryText}:\n"
|
||||||
for entry in entries[:5]:
|
for entry in entries[:5]:
|
||||||
|
@ -751,6 +766,7 @@ def process(arg_discord_connection):
|
||||||
u.dispatcher.add_handler(CommandHandler("cerca", cmd_cerca))
|
u.dispatcher.add_handler(CommandHandler("cerca", cmd_cerca))
|
||||||
u.dispatcher.add_handler(CommandHandler("search", cmd_cerca))
|
u.dispatcher.add_handler(CommandHandler("search", cmd_cerca))
|
||||||
u.dispatcher.add_handler(CommandHandler("diariosearch", cmd_cerca))
|
u.dispatcher.add_handler(CommandHandler("diariosearch", cmd_cerca))
|
||||||
|
u.dispatcher.add_handler(CommandHandler("regex", cmd_regex_diario))
|
||||||
u.dispatcher.add_handler(CallbackQueryHandler(on_callback_query))
|
u.dispatcher.add_handler(CallbackQueryHandler(on_callback_query))
|
||||||
logger.info("Handlers registered.")
|
logger.info("Handlers registered.")
|
||||||
u.start_polling()
|
u.start_polling()
|
||||||
|
|
Loading…
Reference in a new issue