From 512cb26cba0bfa54fd2b11ae1adc62cd1ceb4afa Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Sun, 17 Apr 2022 19:42:35 +0530 Subject: [PATCH] Process inline queries for sharing Signed-off-by: baalajimaestro --- src/nim_censor_bot.nim | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/nim_censor_bot.nim b/src/nim_censor_bot.nim index ed5bef6..b78ddde 100644 --- a/src/nim_censor_bot.nim +++ b/src/nim_censor_bot.nim @@ -147,6 +147,27 @@ proc banHandler(b: Telebot, c: Command): Future[bool] {.gcsafe, async.} = insert BannedUser discard await b.sendMessage(c.message.chat.id, "Banned!") +proc inlineHandler(b: Telebot, u: InlineQuery): Future[bool]{.async.} = + var TempData = @[NewCensoredData()] + var ftype = "" + var res: InlineQueryResultArticle + 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 Not Found").some + else: + dbConn.select(TempData, "fhash = ?", u.query) + if len(TempData) > 1: + ftype = "Album" + elif len(TempData) == 1: + ftype = TempData[0].ftype + res.title = "Censored " & ftype + res.inputMessageContent = InputMessageContent(kind: TextMessage, messageText:"*Censored " & capitalizeAscii(ftype) & "*\n\n[Tap to View](tg://resolve?domain=" & b.username & "&start=" & u.query & ")", parseMode: some("Markdown")).some + results.add(res) + discard await b.answerInlineQuery(u.id, results) + # Main update handler proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} = if u.message.isSome: @@ -227,6 +248,7 @@ when isMainModule: bot.onCommand("start", startHandler) bot.onCommand("ban", banHandler) bot.onCommand("unban", unbanHandler) + bot.onInlineQuery(inlineHandler) if getEnv("HOOK_DOMAIN") != "": bot.startWebhook(getEnv("HOOK_SECRET"), getEnv("HOOK_DOMAIN") & "/" & getEnv("HOOK_SECRET")) else: