nim-censor-bot/src/nim_censor_bot.nim

43 lines
1.2 KiB
Nim
Raw Normal View History

import telebot, std/[asyncdispatch, logging, options, strutils, random], norm/[model, sqlite]
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())
var L = newConsoleLogger(fmtStr="$levelname, [$time] ")
addHandler(L)
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
# remember to strip your secret key to avoid HTTP error
const API_KEY = ""
proc updateHandler(b: Telebot, u: Update): Future[bool] {.async.} =
var response = u.message.get
#if response.document.isSome:
#if response.video.isSome:
#if response.videoNote.isSome:
#if response.animation.isSome:
if response.photo.isSome:
discard await b.sendPhoto(response.chat.id, response.photo.get[0].fileId)
echo "Found file"
let bot = newTeleBot(API_KEY)
bot.onUpdate(updateHandler)
bot.poll(timeout=300)