Insert data flowing into the db

* File hash is still broken, we will do it now

Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
baalajimaestro 2022-04-09 19:56:17 +05:30
parent b7b94085b3
commit 298431fe38
Signed by: baalajimaestro
GPG key ID: F93C394FE9BBAFD5

View file

@ -1,4 +1,4 @@
import telebot, std/[asyncdispatch, logging, options, strutils, random], norm/[model, sqlite] import telebot, std/[asyncdispatch, logging, options, strutils, random, with], norm/[model, sqlite]
type type
CENSORED_DATA* = ref object of Model CENSORED_DATA* = ref object of Model
@ -26,16 +26,28 @@ proc generate_hash(): string=
# remember to strip your secret key to avoid HTTP error # remember to strip your secret key to avoid HTTP error
const API_KEY = "" const API_KEY = ""
proc updateHandler(b: Telebot, u: Update): Future[bool] {.async.} = proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
var response = u.message.get var response = u.message.get
#if response.document.isSome: if response.document.isSome:
var censordoc = newCENSORED_DATA("document", response.photo.get[0].fileId, "")
#if response.video.isSome: with dbConn:
#if response.videoNote.isSome: insert censordoc
#if response.animation.isSome: if response.video.isSome:
var censorvid = newCENSORED_DATA("video", response.photo.get[0].fileId, "")
with dbConn:
insert censorvid
if response.videoNote.isSome:
var censorvidnote = newCENSORED_DATA("videonote", response.photo.get[0].fileId, "")
with dbConn:
insert censorvidnote
if response.animation.isSome:
var censoranimation = newCENSORED_DATA("animation", response.photo.get[0].fileId, "")
with dbConn:
insert censoranimation
if response.photo.isSome: if response.photo.isSome:
discard await b.sendPhoto(response.chat.id, response.photo.get[0].fileId) var censorphoto = newCENSORED_DATA("photo", response.photo.get[0].fileId, "")
echo "Found file" with dbConn:
insert censorphoto
let bot = newTeleBot(API_KEY) let bot = newTeleBot(API_KEY)
bot.onUpdate(updateHandler) bot.onUpdate(updateHandler)