Commands sending example, bugfix in atwss

This commit is contained in:
DarkCat09 2022-05-17 16:35:25 +04:00
parent 13fa18f9d6
commit f606cfd521
2 changed files with 40 additions and 2 deletions

View file

@ -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())

View file

@ -136,7 +136,6 @@ class AternosWss:
msg = json.loads(obj['message']) msg = json.loads(obj['message'])
if msgtype in self.recv: if msgtype in self.recv:
t = asyncio.create_task( asyncio.create_task(
self.recv[msgtype](msg) self.recv[msgtype](msg)
) )
await t