Dont handle non-message updates

Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
baalajimaestro 2022-04-17 19:40:07 +05:30
parent 5eac4c95d5
commit bb22849959
Signed by: baalajimaestro
GPG key ID: F93C394FE9BBAFD5

View file

@ -6,11 +6,12 @@
#
import telebot
import std/[asyncdispatch, logging, options, strutils, random, with, os, tables, times, sequtils]
import std/[asyncdispatch, logging, options, strutils, random, with, os, tables, times, sequtils, json]
import norm/[model, sqlite]
from cgi import encodeUrl
# Logging Level
var L = newConsoleLogger(levelThreshold=lvlError, fmtStr="$levelname, [$time] ")
var L = newConsoleLogger(levelThreshold=lvlDebug, fmtStr="$levelname, [$time] ")
addHandler(L)
# Custom Types Defined to handle tables on norm
@ -148,6 +149,7 @@ proc banHandler(b: Telebot, c: Command): Future[bool] {.gcsafe, async.} =
# Main update handler
proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
if u.message.isSome:
let response = u.message.get
# Refresh rate-limits
ManageRateLimit()
@ -193,7 +195,7 @@ proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
insert CensoredRow
var replybutton = InlineKeyboardButton(text: "Share", switchInlineQuery: some(filehash))
let replymark = newInlineKeyboardMarkup(@[replybutton])
discard await b.sendMessage(response.chat.id, "*Censored " & capitalizeAscii(ftype) & "*", replyMarkup = replymark, parseMode="Markdown")
discard await b.sendMessage(response.chat.id, "*Censored " & capitalizeAscii(ftype) & "*\n\n[Tap to View](tg://resolve?domain=" & b.username & "&start=" & filehash & ")", replyMarkup = replymark, parseMode="Markdown")
else:
let filehash = GroupMedia[parseInt(response.mediaGroupId.get)]
var CensoredRow = NewCensoredData(ftype, filehash, fileid, epochTime(), fcaption)
@ -207,25 +209,25 @@ proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
insert CensoredRow
var replybutton = InlineKeyboardButton(text: "Share", switchInlineQuery: some(filehash))
let replymark = newInlineKeyboardMarkup(@[replybutton])
discard await b.sendMessage(response.chat.id, "*Censored " & capitalizeAscii(ftype) & "*", replyMarkup = replymark, parseMode="Markdown")
discard await b.sendMessage(response.chat.id, "*Censored " & capitalizeAscii(ftype) & "*\n\n[Tap to View](tg://resolve?domain=" & b.username & "&start=" & filehash & ")", replyMarkup = replymark, parseMode="Markdown")
OldDataCleanup()
# Start the bot
let bot = newTeleBot(getEnv("TELEGRAM_TOKEN"))
echo "*********************"
echo "CensorBot is running!"
echo "*********************"
when isMainModule:
let bot = newTeleBot(getEnv("TELEGRAM_TOKEN"))
echo "*********************"
echo "CensorBot is running!"
echo "*********************"
var commands = @[
var commands = @[
BotCommand(command: "start" , description: "Start the bot!")
]
]
discard waitFor bot.setMyCommands(commands)
bot.onUpdate(updateHandler)
bot.onCommand("start", startHandler)
bot.onCommand("ban", banHandler)
bot.onCommand("unban", unbanHandler)
if getEnv("HOOK_DOMAIN") != "":
discard waitFor bot.setMyCommands(commands)
bot.onUpdate(updateHandler)
bot.onCommand("start", startHandler)
bot.onCommand("ban", banHandler)
bot.onCommand("unban", unbanHandler)
if getEnv("HOOK_DOMAIN") != "":
bot.startWebhook(getEnv("HOOK_SECRET"), getEnv("HOOK_DOMAIN") & "/" & getEnv("HOOK_SECRET"))
else:
else:
bot.poll(timeout=300)