Compare commits
4 Commits
abec3dc60e
...
48377ac905
Author | SHA1 | Date |
---|---|---|
Badiboy | 48377ac905 | |
Alexey Isaev | 14294d1aa3 | |
_run | ea3c159044 | |
AmirW | 58d53e1a54 |
|
@ -16,7 +16,7 @@ import telebot.types
|
||||||
from telebot.asyncio_storage import StateMemoryStorage, StatePickleStorage, StateStorageBase
|
from telebot.asyncio_storage import StateMemoryStorage, StatePickleStorage, StateStorageBase
|
||||||
from telebot.asyncio_handler_backends import BaseMiddleware, CancelUpdate, SkipHandler, State, ContinueHandling
|
from telebot.asyncio_handler_backends import BaseMiddleware, CancelUpdate, SkipHandler, State, ContinueHandling
|
||||||
|
|
||||||
from inspect import signature
|
from inspect import signature, iscoroutinefunction
|
||||||
|
|
||||||
from telebot import util, types, asyncio_helper
|
from telebot import util, types, asyncio_helper
|
||||||
import asyncio
|
import asyncio
|
||||||
|
@ -836,6 +836,8 @@ class AsyncTeleBot:
|
||||||
elif message_filter == 'chat_types':
|
elif message_filter == 'chat_types':
|
||||||
return message.chat.type in filter_value
|
return message.chat.type in filter_value
|
||||||
elif message_filter == 'func':
|
elif message_filter == 'func':
|
||||||
|
if iscoroutinefunction(filter_value):
|
||||||
|
return await filter_value(message)
|
||||||
return filter_value(message)
|
return filter_value(message)
|
||||||
elif self.custom_filters and message_filter in self.custom_filters:
|
elif self.custom_filters and message_filter in self.custom_filters:
|
||||||
return await self._check_filter(message_filter,filter_value,message)
|
return await self._check_filter(message_filter,filter_value,message)
|
||||||
|
|
|
@ -590,7 +590,7 @@ def webhook_google_functions(bot, request):
|
||||||
return 'Bot ON'
|
return 'Bot ON'
|
||||||
|
|
||||||
|
|
||||||
def antiflood(function: Callable, *args, **kwargs):
|
def antiflood(function: Callable, *args, number_retries=5, **kwargs):
|
||||||
"""
|
"""
|
||||||
Use this function inside loops in order to avoid getting TooManyRequests error.
|
Use this function inside loops in order to avoid getting TooManyRequests error.
|
||||||
Example:
|
Example:
|
||||||
|
@ -604,6 +604,9 @@ def antiflood(function: Callable, *args, **kwargs):
|
||||||
:param function: The function to call
|
:param function: The function to call
|
||||||
:type function: :obj:`Callable`
|
:type function: :obj:`Callable`
|
||||||
|
|
||||||
|
:param number_retries: Number of retries to send
|
||||||
|
:type function: :obj:int
|
||||||
|
|
||||||
:param args: The arguments to pass to the function
|
:param args: The arguments to pass to the function
|
||||||
:type args: :obj:`tuple`
|
:type args: :obj:`tuple`
|
||||||
|
|
||||||
|
@ -615,14 +618,16 @@ def antiflood(function: Callable, *args, **kwargs):
|
||||||
from telebot.apihelper import ApiTelegramException
|
from telebot.apihelper import ApiTelegramException
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
try:
|
for _ in range(number_retries - 1):
|
||||||
return function(*args, **kwargs)
|
try:
|
||||||
except ApiTelegramException as ex:
|
|
||||||
if ex.error_code == 429:
|
|
||||||
sleep(ex.result_json['parameters']['retry_after'])
|
|
||||||
return function(*args, **kwargs)
|
return function(*args, **kwargs)
|
||||||
else:
|
except ApiTelegramException as ex:
|
||||||
raise
|
if ex.error_code == 429:
|
||||||
|
sleep(ex.result_json['parameters']['retry_after'])
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
return function(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def parse_web_app_data(token: str, raw_init_data: str):
|
def parse_web_app_data(token: str, raw_init_data: str):
|
||||||
|
|
Loading…
Reference in New Issue