Commands sending example, bugfix in atwss
This commit is contained in:
parent
13fa18f9d6
commit
f606cfd521
2 changed files with 40 additions and 2 deletions
39
examples/console_example.py
Normal file
39
examples/console_example.py
Normal 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())
|
|
@ -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
|
||||
|
|
Reference in a new issue