Implement banning unwanted users

People might use this bot on very gore/spam this repeatedly, we can block off them

Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
baalajimaestro 2022-04-09 23:15:02 +05:30
parent d1bbc59e27
commit 9c41348338
Signed by: baalajimaestro
GPG key ID: F93C394FE9BBAFD5

View file

@ -1,4 +1,6 @@
import telebot, std/[asyncdispatch, logging, options, strutils, random, with, os], norm/[model, sqlite]
import telebot
import std/[asyncdispatch, logging, options, strutils, random, with, os]
import norm/[model, sqlite]
type
CensoredData* = ref object of Model
@ -7,12 +9,21 @@ type
fileid*: string
caption*: string
type
BannedUsers* = ref object of Model
userid*: string
func NewCensoredData*(ftype = ""; fhash = ""; fileid = ""; caption = ""):
CensoredData = CensoredData(ftype: ftype, fhash: fhash, fileid: fileid, caption: caption)
func NewBannedUsers*(userid = ""):
BannedUsers = BannedUsers(userid: userid)
let dbConn* = sqlite.open("censordata.db", "", "", "")
dbConn.createTables(NewCensoredData())
dbConn.createTables(NewBannedUsers())
var L = newConsoleLogger(fmtStr="$levelname, [$time] ")
addHandler(L)
@ -28,10 +39,18 @@ const API_KEY = getEnv("TELEGRAM_TOKEN")
proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
let response = u.message.get
if not dbConn.exists(BannedUsers, "userid = ?", response.chat.id):
if response.text.isSome:
let message = response.text.get
if message == "/start":
discard await b.sendMessage(response.chat.id, "Hey, To create a censored post, you can share any album, video, photo, gif, sticker, etc. The messages could then be forwarded to any chat for them to view")
elif message.contains("/ban"):
let user = message.split(" ")
echo "BANNING"
var BannedUser = NewBannedUsers(user[1])
with dbConn:
insert BannedUser
discard await b.sendMessage(response.chat.id, "Banned!")
elif message.contains("/start"):
let deeplink = message.split(" ")
var TempData = @[NewCensoredData()]