40 lines
871 B
Python
40 lines
871 B
Python
|
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())
|