Process inline queries for sharing

Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
baalajimaestro 2022-04-17 19:42:35 +05:30
parent bb22849959
commit 512cb26cba
Signed by: baalajimaestro
GPG key ID: F93C394FE9BBAFD5

View file

@ -147,6 +147,27 @@ proc banHandler(b: Telebot, c: Command): Future[bool] {.gcsafe, async.} =
insert BannedUser insert BannedUser
discard await b.sendMessage(c.message.chat.id, "Banned!") 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 # Main update handler
proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} = proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
if u.message.isSome: if u.message.isSome:
@ -227,6 +248,7 @@ when isMainModule:
bot.onCommand("start", startHandler) bot.onCommand("start", startHandler)
bot.onCommand("ban", banHandler) bot.onCommand("ban", banHandler)
bot.onCommand("unban", unbanHandler) bot.onCommand("unban", unbanHandler)
bot.onInlineQuery(inlineHandler)
if getEnv("HOOK_DOMAIN") != "": if getEnv("HOOK_DOMAIN") != "":
bot.startWebhook(getEnv("HOOK_SECRET"), getEnv("HOOK_DOMAIN") & "/" & getEnv("HOOK_SECRET")) bot.startWebhook(getEnv("HOOK_SECRET"), getEnv("HOOK_DOMAIN") & "/" & getEnv("HOOK_SECRET"))
else: else: