diff --git a/main.py b/main.py index 36a4866..6b5573d 100644 --- a/main.py +++ b/main.py @@ -8,13 +8,13 @@ import aiohttp from handlers.admin_commands import AdminCommands from handlers.user_commands import UserCommands -from neuroapi.config import Config +from neuroapi.config import GlobalConfig as Config from neuroapi.types import NeuroApiBot async def delay_bot()->None: if Config().token is None: - print('Delay bot needs token in environment') + logging.warning('Delay bot needs token in environment') return bot = NeuroApiBot(Config().token) bot.include_router(AdminCommands, UserCommands) @@ -22,7 +22,7 @@ async def delay_bot()->None: async def proxy_bot()->None: if Config().proxy_token is None: - print('Proxy bot needs token in environment') + logging.warning('Proxy bot needs token in environment') return bot = NeuroApiBot(Config().proxy_token) bot.include_router() @@ -30,30 +30,30 @@ async def proxy_bot()->None: async def main() -> None: for i in range(5): - print(f'Checking connectivity to backend ({i+1}/5)...') + logging.warning(f'Checking connectivity to backend ({i+1}/5)...') try: async with aiohttp.ClientSession() as session: response = await session.get(Config().api_url+'/ping') data = str(await response.content.read(), encoding='utf-8') if data == 'pong': - print('Successfully connected to backend') + logging.warning('Successfully connected to backend') break else: raise TimeoutError() except: - print('Error! Waiting 3 secs and retrying...') + logging.error('Waiting 3 secs and retrying...') await asyncio.sleep(3) tasks = [asyncio.create_task(delay_bot()), asyncio.create_task(proxy_bot())] await asyncio.gather(*tasks) if __name__ == '__main__': - logging.basicConfig(level=logging.INFO, stream=sys.stdout) + logging.basicConfig(level=logging.WARNING, stream=sys.stdout, format='%(asctime)s %(levelname)s: %(message)s', datefmt='%d.%m.%Y %H:%M:%S') loop = asyncio.get_event_loop() if platform.system() == 'Windows': try: loop.run_until_complete(main()) except KeyboardInterrupt: - print("KeyboardInterrupt occurred") + logging.error("KeyboardInterrupt occurred") finally: loop.close() else: diff --git a/neuroapi/_methods/post.py b/neuroapi/_methods/post.py index d2d58ef..49e9c5f 100644 --- a/neuroapi/_methods/post.py +++ b/neuroapi/_methods/post.py @@ -78,7 +78,6 @@ class Post(ApiMethod): if message_entities is not None: mes_ent = list(map(lambda x: x.model_dump(), message_entities)) arr =[] - print(mes_ent) for item in mes_ent: if item['type'] == 'bot_command': continue item['offset'] -= 7+len(order) diff --git a/neuroapi/types/_post.py b/neuroapi/types/_post.py index 5b85755..4029030 100644 --- a/neuroapi/types/_post.py +++ b/neuroapi/types/_post.py @@ -24,6 +24,9 @@ class Post(ApiModel): @classmethod def from_dict(cls: 'Post', obj: Dict[str, Any]) -> 'Post': mes_ent = json.loads(obj.get('message_entities', '[]')) + media_group_id_data = obj.get('media_group_id') + media_group_id = media_group_id_data if media_group_id_data is not None else 'None' + obj['media_group_id'] = media_group_id obj['message_entities'] = mes_ent return cls(**obj)