From 2f859b5735e628cac4b5dd59f31ddde2531d8cd9 Mon Sep 17 00:00:00 2001 From: baalajimaestro Date: Sat, 9 Apr 2022 22:10:27 +0530 Subject: [PATCH] Perform a nice cleanup of the mess Signed-off-by: baalajimaestro --- censorbot.db | 0 src/nim_censor_bot.nim | 41 +++++++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 censorbot.db diff --git a/censorbot.db b/censorbot.db new file mode 100644 index 0000000..e69de29 diff --git a/src/nim_censor_bot.nim b/src/nim_censor_bot.nim index c000f0c..d6b8c20 100644 --- a/src/nim_censor_bot.nim +++ b/src/nim_censor_bot.nim @@ -33,31 +33,32 @@ proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} = if message.contains("/start"): let deeplink = message.split(" ") var fileid = "" - let filehash = generate_hash() + var ftype = "" + var fcaption = "" + if response.caption.isSome: + fcaption = response.caption.get if response.document.isSome: - var censordoc = NewCensoredData("document", filehash, response.document.get.fileId, "") - with dbConn: - insert censordoc + fileid = response.document.get.fileId + ftype = "document" if response.video.isSome: - let filehash = generate_hash() - var censorvid = NewCensoredData("video", filehash, response.video.get.fileId, "") - with dbConn: - insert censorvid + fileid = response.video.get.fileId + ftype = "video" if response.videoNote.isSome: - let filehash = generate_hash() - var censorvidnote = NewCensoredData("videonote", filehash, response.videoNote.get.fileId, "") - with dbConn: - insert censorvidnote + fileid = response.videoNote.get.fileId + ftype = "videonote" if response.animation.isSome: - let filehash = generate_hash() - var censoranimation = NewCensoredData("animation", filehash, response.animation.get.fileId, "") - with dbConn: - insert censoranimation + fileid = response.animation.get.fileId + ftype = "animation" if response.photo.isSome: - let filehash = generate_hash() - var censorphoto = NewCensoredData("photo", filehash, response.photo.get[0].fileId, "") - with dbConn: - insert censorphoto + fileid = response.photo.get[0].fileId + ftype = "photo" + + let filehash = generate_hash() + + var CensoredRow = NewCensoredData(ftype, filehash, fileid, fcaption) + + with dbConn: + insert CensoredRow let bot = newTeleBot(API_KEY) bot.onUpdate(updateHandler)