Skip to content

Commit 522c0a8

Browse files
author
Pablo Chinea
committed
Delays welcome message to wait user completes captcha.
1 parent e5daf54 commit 522c0a8

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

bot.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from time import sleep
23

34
import telegram
45
from telegram.ext import Updater, Filters, MessageHandler, CommandHandler
@@ -38,6 +39,14 @@ def command_status(update, context):
3839
def welcome(update: Update, context):
3940
logger.info('Received new user event')
4041
new_member = update.message.new_chat_members[0]
42+
43+
logger.info(f'Waiting {config.WELCOME_DELAY} seconds until user completes captcha...')
44+
sleep(config.WELCOME_DELAY)
45+
membership_info = context.bot.get_chat_member(update.message.chat_id, new_member.id)
46+
if membership_info['status'] == 'left':
47+
logger.info(f'Skipping welcome message, user {new_member.name} is no longer in the chat')
48+
return
49+
4150
logger.info(f'send welcome message for {new_member.name}')
4251
msg = None
4352

config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ def log(logger_method):
6868
default=0.15)
6969

7070

71+
# Delay (in seconds) to wait before sending welcome message. New users have
72+
# 5 minutes to solve a captcha. The default delay is 5 and a half minutes.
73+
WELCOME_DELAY = config('WELCOME_DELAY', int, default=330)
74+
75+
7176
def bot_replies_enabled() -> bool:
7277
return VERBOSITY > 0
7378

0 commit comments

Comments
 (0)