diff --git a/examples/console_example.py b/examples/console_example.py new file mode 100644 index 0000000..a63a90c --- /dev/null +++ b/examples/console_example.py @@ -0,0 +1,39 @@ +import asyncio +import aioconsole +from getpass import getpass +from python_aternos import Client, atwss + +user = input('Username: ') +pswd = getpass('Password: ') +resp = input('Show responses? ').upper() == 'Y' +aternos = Client.from_credentials(user, pswd) + +s = aternos.list_servers()[0] +socket = s.wss() + +if resp: + @socket.wssreceiver(atwss.Streams.console) + async def console(msg): + print('<', msg) + +async def main(): + s.start() + await asyncio.gather( + socket.connect(), + commands() + ) + +async def commands(): + try: + while True: + cmd = await aioconsole.ainput('> ') + await socket.send({ + 'stream': 'console', + 'type': 'command', + 'data': cmd + }) + except KeyboardInterrupt: + await socket.close() + print('* Exit') + +asyncio.run(main()) diff --git a/python_aternos/atwss.py b/python_aternos/atwss.py index 0e6e16d..5facfd0 100644 --- a/python_aternos/atwss.py +++ b/python_aternos/atwss.py @@ -136,7 +136,6 @@ class AternosWss: msg = json.loads(obj['message']) if msgtype in self.recv: - t = asyncio.create_task( + asyncio.create_task( self.recv[msgtype](msg) ) - await t