diff --git a/src/nim_censor_bot.nim b/src/nim_censor_bot.nim index 673aec9..2a7680d 100644 --- a/src/nim_censor_bot.nim +++ b/src/nim_censor_bot.nim @@ -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 CENSORED_DATA* = ref object of Model @@ -26,16 +26,28 @@ proc generate_hash(): string= # remember to strip your secret key to avoid HTTP error 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 - #if response.document.isSome: - - #if response.video.isSome: - #if response.videoNote.isSome: - #if response.animation.isSome: + if response.document.isSome: + var censordoc = newCENSORED_DATA("document", response.photo.get[0].fileId, "") + with dbConn: + insert censordoc + 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: - discard await b.sendPhoto(response.chat.id, response.photo.get[0].fileId) - echo "Found file" + var censorphoto = newCENSORED_DATA("photo", response.photo.get[0].fileId, "") + with dbConn: + insert censorphoto let bot = newTeleBot(API_KEY) bot.onUpdate(updateHandler)