27 lines
884 B
Python
27 lines
884 B
Python
|
import datetime
|
||
|
|
||
|
from background_task import background
|
||
|
from telegram.bot import Bot
|
||
|
|
||
|
from . import models
|
||
|
|
||
|
|
||
|
@background()
|
||
|
def captcha_kicker():
|
||
|
for pendingCaptchaUser in models.PendingCaptchaUser.objects.all():
|
||
|
expirity = pendingCaptchaUser.created + datetime.timedelta(seconds=pendingCaptchaUser.lifetime)
|
||
|
if expirity < datetime.datetime.now():
|
||
|
if (expirity+datetime.timedelta(seconds=1800)) < datetime.datetime.now():
|
||
|
pendingCaptchaUser.delete()
|
||
|
continue
|
||
|
bot_token = pendingCaptchaUser.bot_token
|
||
|
bot = Bot(token=bot_token)
|
||
|
bot.kick_chat_member(
|
||
|
chat_id=pendingCaptchaUser.group.telegram_id,
|
||
|
user_id=pendingCaptchaUser.user.telegram_id,
|
||
|
)
|
||
|
pendingCaptchaUser.delete()
|
||
|
|
||
|
|
||
|
captcha_kicker(schedule=1, repeat=10, repeat_until=None)
|