async def init(self): keystore_service: Service = await self.cloud.wait_service("keystore") token = None while not token: await trio.sleep(1) token = await self.get_token() self.publics = await self.get_param("publics", defaultdict(list)) # self.publics = defaultdict(list) # # loaded_publics = await self.get_param() # if loaded_publics: # for public_name in loaded_publics: # self.publics[public_name] = loaded_publics[public_name] self.bot = triogram.make_bot(token) self.approved = await self.get_param("approved", list()) # self.approved = await keystore_service.request("get", "telegram#approved") # if not self.approved: # self.approved = [] self.pending_requests_access = await self.get_param( "pending_requests_access", dict()) # self.pending_requests_access = await keystore_service.request("get", "telegram#pending_requests_access") # if self.pending_requests_access is None: # self.pending_requests_access = dict() self.users_info = await self.get_param("users_info", dict())
async def main(): bot = triogram.make_bot() configure_logging() slugs = generate_slugs(EMOJIS_FILENAME, SLUG_LENGTH) async with trio.open_nursery() as nursery: nursery.start_soon(bot) nursery.start_soon(meet_handler, bot, slugs)
async def app(): bot = triogram.make_bot() configure_logging() handler = Handler(bot) async with trio.open_nursery() as nursery: nursery.start_soon(bot) nursery.start_soon(handler)
async def main(): """ Starts the bot and event handlers. """ bot = triogram.make_bot() async with bot, trio.open_nursery() as nursery: nursery.start_soon(bot) nursery.start_soon(echo, bot) nursery.start_soon(echo_once, bot)
async def main(): """ Gets info about the bot every 5 seconds. """ configure_logging() async with triogram.make_bot() as bot: while True: await bot.api.get_me() await trio.sleep(5)
async def test_make_bot(): token = "123:ABC" bot = triogram.make_bot(token) assert bot.api._http.base_url.path == f"/bot{token}/"
async def test_make_bot_token_from_env(): token = "123:ABC" with mock.patch.dict(os.environ, {"TOKEN": token}): bot = triogram.make_bot(token_env_var="TOKEN") assert bot.api._http.base_url.path == f"/bot{token}/"
def new(config): bot = triogram.make_bot() configure_logging(config) root_handler = RootHandler(bot, config) return App(bot, root_handler)