예제 #1
0
def run_multibot(bot: Bot,
                 apis: Iterable["ABCAPI"],
                 polling_type: Type["ABCPolling"] = BotPolling):
    """Add run_polling with polling constructed from derived apis
    :param bot: Bot main instance (api is not required)
    :param apis: Iterable of apis
    :param polling_type: polling type to be ran
    """
    for i, api_instance in enumerate(apis):
        logger.debug("Connecting API (index: {})", i)
        polling = polling_type().construct(api_instance)
        api_instance.http_client = SingleAiohttpClient()
        bot.loop_wrapper.add_task(bot.run_polling(custom_polling=polling))
    bot.loop_wrapper.run_forever()
예제 #2
0
 def __init__(
     self,
     token: "Token",
     ignore_errors: bool = False,
     http_client: Optional["ABCHTTPClient"] = None,
     request_rescheduler: Optional["ABCRequestRescheduler"] = None,
 ):
     self.token_generator = get_token_generator(token)
     self.ignore_errors = ignore_errors
     self.http_client = http_client or SingleAiohttpClient()
     self.request_rescheduler = request_rescheduler or BlockingRequestRescheduler()
     self.response_validators: List["ABCResponseValidator"] = DEFAULT_RESPONSE_VALIDATORS
     self.request_validators: List["ABCRequestValidator"] = DEFAULT_REQUEST_VALIDATORS  # type: ignore
     self.captcha_handler: Optional[CaptchaHandler] = None
예제 #3
0
async def test_client_init():
    client = AiohttpClient(test="test")
    assert client._session_params["test"] == "test"
    singleton_client = SingleAiohttpClient(test="test")
    assert singleton_client._session_params["test"] == "test"