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 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] import norm/[model, sqlite]
from cgi import encodeUrl
# Logging Level # Logging Level
var L = newConsoleLogger(levelThreshold=lvlError, fmtStr="$levelname, [$time] ") var L = newConsoleLogger(levelThreshold=lvlDebug, fmtStr="$levelname, [$time] ")
addHandler(L) addHandler(L)
# Custom Types Defined to handle tables on norm # 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 # 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:
let response = u.message.get let response = u.message.get
# Refresh rate-limits # Refresh rate-limits
ManageRateLimit() ManageRateLimit()
@ -193,7 +195,7 @@ proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
insert CensoredRow insert CensoredRow
var replybutton = InlineKeyboardButton(text: "Share", switchInlineQuery: some(filehash)) var replybutton = InlineKeyboardButton(text: "Share", switchInlineQuery: some(filehash))
let replymark = newInlineKeyboardMarkup(@[replybutton]) 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: else:
let filehash = GroupMedia[parseInt(response.mediaGroupId.get)] let filehash = GroupMedia[parseInt(response.mediaGroupId.get)]
var CensoredRow = NewCensoredData(ftype, filehash, fileid, epochTime(), fcaption) var CensoredRow = NewCensoredData(ftype, filehash, fileid, epochTime(), fcaption)
@ -207,10 +209,10 @@ proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
insert CensoredRow insert CensoredRow
var replybutton = InlineKeyboardButton(text: "Share", switchInlineQuery: some(filehash)) var replybutton = InlineKeyboardButton(text: "Share", switchInlineQuery: some(filehash))
let replymark = newInlineKeyboardMarkup(@[replybutton]) 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() OldDataCleanup()
# Start the bot when isMainModule:
let bot = newTeleBot(getEnv("TELEGRAM_TOKEN")) let bot = newTeleBot(getEnv("TELEGRAM_TOKEN"))
echo "*********************" echo "*********************"
echo "CensorBot is running!" echo "CensorBot is running!"