-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeout.py
More file actions
40 lines (32 loc) · 1.06 KB
/
timeout.py
File metadata and controls
40 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import sqlite3
import telebot
import schedule
from time import time
from time import sleep
from datetime import datetime
from datetime import timedelta
GROUP_ID = os.getenv("GROUP_ID")
API_TOKEN = os.getenv("API_TOKEN")
BOT_USERNAME = os.getenv("BOT_USERNAME")
database = sqlite3.connect("telebot-captcha.db")
bot = telebot.TeleBot(API_TOKEN, parse_mode="HTML")
cursor = database.cursor()
def captcha_timeout():
records = cursor.execute("SELECT * FROM captcha").fetchall()
for _ in records:
if int(_[-1]) <= int(time()):
try:
user_id = int(-[0])
bot.send_message(GROUP_ID, f"<b>[<a href='tg://user?id={user_id}'>{_[1]}</a>] was banned!\n\
\n<i>Reason: CAPTCHA timeout ⌛</i></b>")
bot.ban_chat_member(GROUP_ID, user_id, int(datetime.timestamp(
datetime.now() + timedelta(days=1))), False)
cursor.execute(f"DELETE * FROM captcha WHERE user_id = {user_id}")
database.commit()
except:
pass
schedule.every(1).minutes.do(captcha_timeout)
while True:
schedule.run_pending()
sleep(1)