Closed ranjitsingha closed 4 months ago
Please answer these questions before submitting your issue. Thanks!
What version of pyTelegramBotAPI are you using? Latest
What OS are you using? Ubuntu
What version of python are you using? 3.10
class AntiSpamMiddleware(BaseMiddleware): def __init__(self, limit, window) -> None: self.message_count = {} self.limit = limit self.window = window self.update_types = ['message'] async def pre_process(self, message, data): current_time = time.time() user_id = message.from_user.id if user_id not in self.message_count: self.message_count[user_id] = {'count': 1, 'start_time': current_time} return elif current_time - self.message_count[user_id]['start_time'] < self.window: self.message_count[user_id]['count'] += 1 if self.message_count[user_id]['count'] > self.limit: await bot.send_message(message.chat.id, 'You have been blocked temporarily for spamming') return SkipHandler() else: self.message_count[user_id] = {'count': 1, 'start_time': current_time} async def post_process(self, message, data, exception): pass bot.setup_middleware(AntiSpamMiddleware(15, 30))
return SkipHandler() isn't working. It reaches the handlers too
You sure you are importing skiphandler from asyncio_handler_backends?
Sorry my mistake i didn't import. You can close this issue 😊
Please answer these questions before submitting your issue. Thanks!
What version of pyTelegramBotAPI are you using? Latest
What OS are you using? Ubuntu
What version of python are you using? 3.10
return SkipHandler() isn't working. It reaches the handlers too