From e38daf3c89bd4f9e4b8c5c6eaa7accf489be59a9 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 24 Apr 2023 20:51:54 +0800 Subject: [PATCH] Update tgclient.py --- plugins/tgclient/startup/tgclient.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/plugins/tgclient/startup/tgclient.py b/plugins/tgclient/startup/tgclient.py index 2a2c68c3a..40160686b 100644 --- a/plugins/tgclient/startup/tgclient.py +++ b/plugins/tgclient/startup/tgclient.py @@ -8,6 +8,8 @@ import re import json import base64 import threading +import asyncio +import logging # python /Users/midoks/Desktop/mwdev/server/tgclient/tgclient.py # python /www/server/tgclient/tgclient.py @@ -18,6 +20,10 @@ from telethon import TelegramClient sys.path.append(os.getcwd() + "/class/core") import mw +logging.basicConfig(level=logging.INFO, + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') +logger = logging.getLogger(__name__) + def getPluginName(): return 'tgclient' @@ -90,9 +96,25 @@ while True: client = TelegramClient('mdioks', cfg['bot']['api_id'], cfg['bot']['api_hash']) +async def change_name_auto(): + print('will change name') + await asyncio.sleep(1) + async def main(): + await client.start() + + # create new task + print('creating task') + task = loop.create_task(change_name_auto()) + await task + # Now you can use all client methods listed below, like for example... - await client.send_message('me', 'Hello to myself!') + # await client.send_message('me', 'Hello to myself!') + + print('It works.') + await client.run_until_disconnected() + task.cancel() -with client: - client.loop.run_until_complete(main()) +if __name__ == '__main__': + loop = asyncio.get_event_loop() + loop.run_until_complete(main(loop))