1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

fixed strings and case sensitiveness in /cerca

This commit is contained in:
Fabio De Simone 2019-01-28 22:33:08 +01:00 committed by Stefano Pigozzi
parent e903c6484f
commit 84cb24a51a

View file

@ -298,14 +298,14 @@ def cmd_search(bot: Bot, update: Update):
text = update.message.text.split(" ", 1)[1] text = update.message.text.split(" ", 1)[1]
if text is None: if text is None:
return return
entries = session.query(db.Diario).filter(db.Diario.text.like('%'+text+'%')).all() entries = session.query(db.Diario).filter(db.Diario.text.ilike('%'+text+'%')).all()
messageText = "Ecco i risulati della ricerca:\n" messageText = "Ecco i risulati della ricerca:\n"
for entry in entries[:5]: for entry in entries[:5]:
messageText+="[#{entry.id}](https://ryg.steffo.eu/diario#entry-{entry.id}) di {entry.author}\n{entry.text}\n\n" messageText+=f"[#{entry.id}](https://ryg.steffo.eu/diario#entry-{entry.id}) di {entry.author}\n{entry.text}\n\n"
if len(entries)>5: if len(entries)>5:
messageText += "ci sono altre entrate del diario che corrispondono alla ricerca:\n" messageText += "ci sono altre entrate del diario che corrispondono alla ricerca:\n"
for entry in entries[5:]: for entry in entries[5:]:
messageText += "[#{entry.id}](https://ryg.steffo.eu/diario#entry-{entry.id}) " messageText += f"[#{entry.id}](https://ryg.steffo.eu/diario#entry-{entry.id}) "
bot.send_message(update.message.chat.id, messageText, parse_mode="Markdown") bot.send_message(update.message.chat.id, messageText, parse_mode="Markdown")
finally: finally:
session.close() session.close()