Insert the hash as well to db

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

View file

@ -3,11 +3,12 @@ import telebot, std/[asyncdispatch, logging, options, strutils, random, with], n
type
CENSORED_DATA* = ref object of Model
ftype*: string
fhash*: string
fileid*: string
caption*: string
func newCENSORED_DATA*(ftype = ""; fileid = ""; caption = ""):
CENSORED_DATA = CENSORED_DATA(ftype: ftype, fileid: fileid, caption: caption)
func newCENSORED_DATA*(ftype = ""; fhash = ""; fileid = ""; caption = ""):
CENSORED_DATA = CENSORED_DATA(ftype: ftype, fhash: fhash, fileid: fileid, caption: caption)
let dbConn* = sqlite.open("censordata.db", "", "", "")
@ -29,23 +30,28 @@ const API_KEY = ""
proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
var response = u.message.get
if response.document.isSome:
var censordoc = newCENSORED_DATA("document", response.photo.get[0].fileId, "")
let filehash = generate_hash()
var censordoc = newCENSORED_DATA("document", filehash, response.document.get.fileId, "")
with dbConn:
insert censordoc
if response.video.isSome:
var censorvid = newCENSORED_DATA("video", response.photo.get[0].fileId, "")
let filehash = generate_hash()
var censorvid = newCENSORED_DATA("video", filehash, response.video.get.fileId, "")
with dbConn:
insert censorvid
if response.videoNote.isSome:
var censorvidnote = newCENSORED_DATA("videonote", response.photo.get[0].fileId, "")
let filehash = generate_hash()
var censorvidnote = newCENSORED_DATA("videonote", filehash, response.videoNote.get.fileId, "")
with dbConn:
insert censorvidnote
if response.animation.isSome:
var censoranimation = newCENSORED_DATA("animation", response.photo.get[0].fileId, "")
let filehash = generate_hash()
var censoranimation = newCENSORED_DATA("animation", filehash, response.animation.get.fileId, "")
with dbConn:
insert censoranimation
if response.photo.isSome:
var censorphoto = newCENSORED_DATA("photo", response.photo.get[0].fileId, "")
let filehash = generate_hash()
var censorphoto = newCENSORED_DATA("photo", filehash, response.photo.get[0].fileId, "")
with dbConn:
insert censorphoto