1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Use HTML in /cerca

This commit is contained in:
Steffo 2019-01-28 23:37:01 +01:00
parent 6df65c0f3e
commit 36badb1a82
2 changed files with 30 additions and 16 deletions

View file

@ -69,7 +69,13 @@ class MATCHMAKING:
} }
class ERRORS: class ERRORS:
INVALID_SYNTAX = "⚠ Sintassi del comando errata.\n Sintassi: <pre>/mm [minplayers-][maxplayers] per <gamename> \\n[descrizione]</pre>" INVALID_SYNTAX = "⚠ Sintassi del comando errata.\nSintassi: <pre>/mm [minplayers-][maxplayers] per {gamename} \\n[descrizione]</pre>"
NOT_ADMIN = "⚠ Non sei il creatore di questo match!" NOT_ADMIN = "⚠ Non sei il creatore di questo match!"
MATCH_CLOSED = "⚠ Il matchmaking per questa partita è terminato!" MATCH_CLOSED = "⚠ Il matchmaking per questa partita è terminato!"
UNAUTHORIZED = "⚠ Non sono autorizzato a inviare messaggi a {mention}. \nPer piacere, {mention}, inviami un messaggio in privata!" UNAUTHORIZED = "⚠ Non sono autorizzato a inviare messaggi a {mention}.\nPer piacere, {mention}, inviami un messaggio in privata!"
# Diario search
class DIARIO_SEARCH:
class ERRORS:
INVALID_SYNTAX = "⚠ Non hai specificato un termine da cercare!\nSintassi: <pre>/search {termine}</pre>"

View file

@ -63,7 +63,7 @@ def catch_and_report(func: "function"):
try: try:
bot.send_message(int(config["Telegram"]["main_group"]), bot.send_message(int(config["Telegram"]["main_group"]),
s(strings.TELEGRAM.ERRORS.CRITICAL_ERROR, exc_info=sys.exc_info()), s(strings.TELEGRAM.ERRORS.CRITICAL_ERROR, exc_info=sys.exc_info()),
parse_mode="Markdown") parse_mode="HTML")
except Exception: except Exception:
logger.error(f"Double critical error: {sys.exc_info()}") logger.error(f"Double critical error: {sys.exc_info()}")
sentry.user_context({ sentry.user_context({
@ -93,7 +93,8 @@ def cmd_register(bot: Bot, update: Update):
try: try:
username = update.message.text.split(" ", 1)[1] username = update.message.text.split(" ", 1)[1]
except IndexError: except IndexError:
bot.send_message(update.message.chat.id, s(strings.LINKING.ERRORS.INVALID_SYNTAX)) bot.send_message(update.message.chat.id, s(strings.LINKING.ERRORS.INVALID_SYNTAX),
parse_mode="HTML")
session.close() session.close()
return return
try: try:
@ -101,16 +102,19 @@ def cmd_register(bot: Bot, update: Update):
royal_username=username, royal_username=username,
telegram_user=update.message.from_user) telegram_user=update.message.from_user)
except errors.NotFoundError: except errors.NotFoundError:
bot.send_message(update.message.chat.id, s(strings.LINKING.ERRORS.NOT_FOUND)) bot.send_message(update.message.chat.id, s(strings.LINKING.ERRORS.NOT_FOUND),
parse_mode="HTML")
session.close() session.close()
return return
except errors.AlreadyExistingError: except errors.AlreadyExistingError:
bot.send_message(update.message.chat.id, s(strings.LINKING.ERRORS.ALREADY_EXISTING)) bot.send_message(update.message.chat.id, s(strings.LINKING.ERRORS.ALREADY_EXISTING),
parse_mode="HTML")
session.close() session.close()
return return
session.add(t) session.add(t)
session.commit() session.commit()
bot.send_message(update.message.chat.id, s(strings.LINKING.SUCCESSFUL)) bot.send_message(update.message.chat.id, s(strings.LINKING.SUCCESSFUL),
parse_mode="HTML")
finally: finally:
session.close() session.close()
@ -290,26 +294,30 @@ def cmd_vote(bot: Bot, update: Update):
finally: finally:
session.close() session.close()
@catch_and_report @catch_and_report
def cmd_search(bot: Bot, update: Update): def cmd_search(bot: Bot, update: Update):
session = db.Session() session = db.Session()
try: try:
text = update.message.text.split(" ", 1)[1] try:
if text is None: text = update.message.text.split(" ", 1)[1]
except IndexError:
bot.send_message(update.message.chat.id, s(strings.DIARIO_SEARCH.ERRORS.INVALID_SYNTAX))
return return
text = text.replace('%','\\%').replace('_','\_') text = text.replace('%', '\\%').replace('_', '\\_')
entries = session.query(db.Diario).filter(db.Diario.text.ilike('%'+text+'%')).all() entries = session.query(db.Diario).filter(db.Diario.text.ilike('%'+text+'%')).all()
messageText = "Ecco i risultati della ricerca:\n" msg = f"Risultati della ricerca di {text}:\n"
for entry in entries[:5]: for entry in entries[:5]:
messageText+=f"[#{entry.id}](https://ryg.steffo.eu/diario#entry-{entry.id}) di {entry.author if entry.author is not None else 'Anonimo'}\n{entry.text}\n\n" 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:
messageText += "ci sono altre entrate del diario che corrispondono alla ricerca:\n" msg += "I termini comapiono anche nelle righe:\n"
for entry in entries[5:]: for entry in entries[5:]:
messageText += f"[#{entry.id}](https://ryg.steffo.eu/diario#entry-{entry.id}) " msg += f'<a href="https://ryg.steffo.eu/diario#entry-{entry.id}">#{entry.id}</a> '
bot.send_message(update.message.chat.id, messageText, parse_mode="Markdown") bot.send_message(update.message.chat.id, msg, parse_mode="HTML")
finally: finally:
session.close() session.close()
@catch_and_report @catch_and_report
def cmd_mm(bot: Bot, update: Update): def cmd_mm(bot: Bot, update: Update):
session = db.Session() session = db.Session()