Ejemplo n.º 1
0
async def main():
    # await bb.start()
    # stor.asyncio_loop.stop()
    # return

    path = os.path.dirname(os.path.abspath(__file__))
    full_path = f"{path}/base/config{mode}.json"
    with open(full_path, 'r') as file:
        stor.config = json.load(file)
    bot_tokens = Token(stor.config['TOKEN'])
    user_tokens = Token(stor.config['USER_TOKEN'])
    stor.config['BASEFILE'] = f"{path}/base/{stor.config['BASEFILE']}"
    stor.config['LOGFILE'] = f"{path}/base/{stor.config['LOGFILE']}"
    stor.config['CONFIG'] = full_path

    logging.basicConfig(level=stor.config['LOGLEVEL'],
                        filename=stor.config['LOGFILE'])
    logging.addLevelName(11, 'OK')
    logging.addLevelName(12, 'DONE')
    logging.addLevelName(13, 'NO')
    logging.addLevelName(14, 'BAD')

    base_logger = logging.getLogger('base')
    command_logger = logging.getLogger('co')
    utils.st.logger = command_logger

    stor.start_time = int(time.time())

    user_client = AIOHTTPClient()
    user_tokens = [UserSyncSingleToken(tok) for tok in user_tokens]
    stor.user_api = API(user_tokens, user_client)

    client = AIOHTTPClient()
    tokens = [BotSyncSingleToken(tok) for tok in bot_tokens]
    api_session = API(tokens, client)
    api = api_session.get_context()
    lp_data = BotLongpollData(stor.config['GROUP_ID'])
    longpoll = BotLongpoll(api, lp_data)
    token_storage = TokenStorage[GroupId]()
    dp = Dispatcher(api_session, token_storage)
    dp.add_router(await hand.initiate_router(DefaultRouter()))
    await dp.cache_potential_tokens()
    await base.initiate(stor.config['BASEFILE'], base_logger)

    # storage = ConfirmationStorage()
    # storage.add_confirmation(GroupId(stor.config['GROUP_ID']),stor.config['CONFIRMATION'])
    # cb_extension = AIOHTTPCallbackExtension(
    #     dp, path="/", host="0.0.0.0", port=80, secret=stor.config['SECRET'], confirmation_storage=storage
    # )

    lp_extension = BotLongpollExtension(dp, longpoll)

    # await cb_extension.start()
    await lp_extension.start()
Ejemplo n.º 2
0
 def __init__(self, tokens: typing.Union[str, typing.List[str]],
              bot_type: BotType):
     self.client = AIOHTTPClient()
     if bot_type.USER:
         self.tokens = (UserSyncSingleToken(Token(tokens)) if isinstance(
             tokens, str) else BotSyncPoolTokens(
                 [Token(token) for token in tokens]))
     else:
         self.tokens = (BotSyncSingleToken(Token(tokens)) if isinstance(
             tokens, str) else BotSyncPoolTokens(
                 [Token(token) for token in tokens]))
     self.api = API(clients=self.client, tokens=self.tokens)
Ejemplo n.º 3
0
 def __init__(self, token: str, api_version: typing.Optional[str] = None):
     client = AIOHTTPClient()
     token = UserSyncSingleToken(Token(token))
     self._api = LibAPI(tokens=token, clients=client, api_version=api_version)