From 33894b05015edc3c200a12c8730da80f5844d79f Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Mon, 22 Aug 2022 13:59:16 +0530 Subject: [PATCH] Dont make db calls if the inline query is null Signed-off-by: baalajimaestro --- src/nim_censor_bot.nim | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/nim_censor_bot.nim b/src/nim_censor_bot.nim index 12715d4..08a4232 100644 --- a/src/nim_censor_bot.nim +++ b/src/nim_censor_bot.nim @@ -187,25 +187,30 @@ proc inlineHandler(b: Telebot, u: InlineQuery): Future[bool]{.async.} = var results: seq[InlineQueryResultArticle] res.kind = "article" res.id = "1" - if not dbConn.exists(CensoredData, "fhash = ?",u.query): - res.title = "Media Not Found" - res.inputMessageContent = InputTextMessageContent( - "Media does not exist on database, ask the sender to censor this again!").some + if u.query != "": + if not dbConn.exists(CensoredData, "fhash = ?",u.query): + res.title = "Media Not Found" + res.inputMessageContent = InputTextMessageContent( + "Media does not exist on database, ask the sender to censor this again!").some + else: + dbConn.select(TempData, "fhash = ?", u.query) + if len(TempData) > 1: + ftype = "Album" + elif len(TempData) == 1: + ftype = TempData[0].ftype + res.title = "NSFW " & capitalizeAscii(ftype) + res.inputMessageContent = InputMessageContent(kind: TextMessage, + messageText:"*NSFW " & + capitalizeAscii(ftype) & + "*\n\n[Tap to View](tg://resolve?domain=" & + b.username & "&start=" & + u.query & + ")", + parseMode: some("Markdown")).some else: - dbConn.select(TempData, "fhash = ?", u.query) - if len(TempData) > 1: - ftype = "Album" - elif len(TempData) == 1: - ftype = TempData[0].ftype - res.title = "NSFW " & capitalizeAscii(ftype) - res.inputMessageContent = InputMessageContent(kind: TextMessage, - messageText:"*NSFW " & - capitalizeAscii(ftype) & - "*\n\n[Tap to View](tg://resolve?domain=" & - b.username & "&start=" & - u.query & - ")", - parseMode: some("Markdown")).some + res.title = "Waiting for File Hash" + res.inputMessageContent = InputTextMessageContent( + "Provide the filehash on inline query").some results.add(res) discard await b.answerInlineQuery(u.id, results)