2022-04-09 14:26:17 +00:00
|
|
|
import telebot, std/[asyncdispatch, logging, options, strutils, random, with], norm/[model, sqlite]
|
2022-04-07 17:41:36 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
CENSORED_DATA* = ref object of Model
|
|
|
|
ftype*: string
|
|
|
|
fileid*: string
|
|
|
|
caption*: string
|
|
|
|
|
|
|
|
func newCENSORED_DATA*(ftype = ""; fileid = ""; caption = ""):
|
|
|
|
CENSORED_DATA = CENSORED_DATA(ftype: ftype, fileid: fileid, caption: caption)
|
|
|
|
|
|
|
|
let dbConn* = sqlite.open("censordata.db", "", "", "")
|
|
|
|
|
|
|
|
dbConn.createTables(newCENSORED_DATA())
|
|
|
|
|
2022-04-07 10:51:02 +00:00
|
|
|
var L = newConsoleLogger(fmtStr="$levelname, [$time] ")
|
|
|
|
addHandler(L)
|
|
|
|
|
2022-04-07 11:45:56 +00:00
|
|
|
proc generate_hash(): string=
|
|
|
|
result = newString(7)
|
|
|
|
const charset = {'a' .. 'z', 'A' .. 'Z', '0' .. '9'}
|
|
|
|
for i in 0..6:
|
|
|
|
result[i] = sample(charset)
|
|
|
|
return result
|
|
|
|
|
2022-04-07 10:51:02 +00:00
|
|
|
# remember to strip your secret key to avoid HTTP error
|
|
|
|
const API_KEY = ""
|
|
|
|
|
2022-04-09 14:26:17 +00:00
|
|
|
proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
|
2022-04-07 10:51:02 +00:00
|
|
|
var response = u.message.get
|
2022-04-09 14:26:17 +00:00
|
|
|
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
|
2022-04-07 10:51:02 +00:00
|
|
|
if response.photo.isSome:
|
2022-04-09 14:26:17 +00:00
|
|
|
var censorphoto = newCENSORED_DATA("photo", response.photo.get[0].fileId, "")
|
|
|
|
with dbConn:
|
|
|
|
insert censorphoto
|
2022-04-07 10:51:02 +00:00
|
|
|
|
|
|
|
let bot = newTeleBot(API_KEY)
|
|
|
|
bot.onUpdate(updateHandler)
|
|
|
|
bot.poll(timeout=300)
|