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 type
CENSORED_DATA* = ref object of Model CENSORED_DATA* = ref object of Model
ftype*: string ftype*: string
fhash*: string
fileid*: string fileid*: string
caption*: string caption*: string
func newCENSORED_DATA*(ftype = ""; fileid = ""; caption = ""): func newCENSORED_DATA*(ftype = ""; fhash = ""; fileid = ""; caption = ""):
CENSORED_DATA = CENSORED_DATA(ftype: ftype, fileid: fileid, caption: caption) CENSORED_DATA = CENSORED_DATA(ftype: ftype, fhash: fhash, fileid: fileid, caption: caption)
let dbConn* = sqlite.open("censordata.db", "", "", "") let dbConn* = sqlite.open("censordata.db", "", "", "")
@ -29,23 +30,28 @@ const API_KEY = ""
proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} = 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, "") let filehash = generate_hash()
var censordoc = newCENSORED_DATA("document", filehash, response.document.get.fileId, "")
with dbConn: with dbConn:
insert censordoc insert censordoc
if response.video.isSome: 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: with dbConn:
insert censorvid insert censorvid
if response.videoNote.isSome: 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: with dbConn:
insert censorvidnote insert censorvidnote
if response.animation.isSome: 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: with dbConn:
insert censoranimation insert censoranimation
if response.photo.isSome: 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: with dbConn:
insert censorphoto insert censorphoto