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:
parent
d1bbc59e27
commit
9c41348338
1 changed files with 72 additions and 53 deletions
|
@ -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
|
type
|
||||||
CensoredData* = ref object of Model
|
CensoredData* = ref object of Model
|
||||||
|
@ -7,12 +9,21 @@ type
|
||||||
fileid*: string
|
fileid*: string
|
||||||
caption*: string
|
caption*: string
|
||||||
|
|
||||||
|
type
|
||||||
|
BannedUsers* = ref object of Model
|
||||||
|
userid*: string
|
||||||
|
|
||||||
func NewCensoredData*(ftype = ""; fhash = ""; fileid = ""; caption = ""):
|
func NewCensoredData*(ftype = ""; fhash = ""; fileid = ""; caption = ""):
|
||||||
CensoredData = CensoredData(ftype: ftype, fhash: fhash, fileid: fileid, caption: caption)
|
CensoredData = CensoredData(ftype: ftype, fhash: fhash, fileid: fileid, caption: caption)
|
||||||
|
|
||||||
|
func NewBannedUsers*(userid = ""):
|
||||||
|
BannedUsers = BannedUsers(userid: userid)
|
||||||
|
|
||||||
|
|
||||||
let dbConn* = sqlite.open("censordata.db", "", "", "")
|
let dbConn* = sqlite.open("censordata.db", "", "", "")
|
||||||
|
|
||||||
dbConn.createTables(NewCensoredData())
|
dbConn.createTables(NewCensoredData())
|
||||||
|
dbConn.createTables(NewBannedUsers())
|
||||||
|
|
||||||
var L = newConsoleLogger(fmtStr="$levelname, [$time] ")
|
var L = newConsoleLogger(fmtStr="$levelname, [$time] ")
|
||||||
addHandler(L)
|
addHandler(L)
|
||||||
|
@ -28,10 +39,18 @@ const API_KEY = getEnv("TELEGRAM_TOKEN")
|
||||||
|
|
||||||
proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
|
proc updateHandler(b: Telebot, u: Update): Future[bool] {.async, gcsafe.} =
|
||||||
let response = u.message.get
|
let response = u.message.get
|
||||||
|
if not dbConn.exists(BannedUsers, "userid = ?", response.chat.id):
|
||||||
if response.text.isSome:
|
if response.text.isSome:
|
||||||
let message = response.text.get
|
let message = response.text.get
|
||||||
if message == "/start":
|
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")
|
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"):
|
elif message.contains("/start"):
|
||||||
let deeplink = message.split(" ")
|
let deeplink = message.split(" ")
|
||||||
var TempData = @[NewCensoredData()]
|
var TempData = @[NewCensoredData()]
|
||||||
|
|
Loading…
Reference in a new issue