This repository has been archived on 2024-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
python-aternos/examples/console_example.py

43 lines
833 B
Python
Raw Permalink Normal View History

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'
atclient = Client()
aternos = atclient.account
atclient.login(user, pswd)
s = aternos.list_servers()[0]
socket = s.wss()
if resp:
@socket.wssreceiver(atwss.Streams.console)
async def console(msg):
print('<', msg)
2022-06-23 14:13:56 +03:00
async def main():
s.start()
await asyncio.gather(
socket.connect(),
commands()
)
2022-06-23 14:13:56 +03:00
async def commands():
while True:
cmd = await aioconsole.ainput('> ')
if cmd.strip() == '':
continue
await socket.send({
'stream': 'console',
'type': 'command',
'data': cmd
})
asyncio.run(main())