-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote-execute.py
49 lines (41 loc) · 1.34 KB
/
remote-execute.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from socketIO_client import SocketIO, LoggingNamespace
import os
import json
import voice
config = json.loads(open('config.json').read())
myId = config['identities']['pal-command']
def execute(data):
success = True
if data['command']['action'] == 'basic':
print('The message is: ' + data['command']['text'])
elif data['command']['action'] == 'speak':
voice.speak(data['command']['text'])
elif data['command']['action'] == 'exec':
os.system(data['command']['command'])
elif data['command']['action'] == 'open':
os.system('open ' + data['command']['path'])
else:
success = False
print('Can\'t process specified action.')
print(data)
if success:
socketIO.emit('complete', {'clientId': myId, 'id': data['id']})
def on_handshake(data):
print(data)
for i in data['commands']:
if not i == None:
execute(i)
def on_command(data):
print(data)
execute(data)
dataFile = open('config.json')
config = json.load(dataFile)
socketIO = SocketIO(config['servers']['pal-command']['server'], config['servers']['pal-command']['port'], LoggingNamespace)
socketIO.on('handshake', on_handshake)
socketIO.on('command', on_command)
# Listen
socketIO.emit('handshake', {'id': myId})
socketIO.wait(seconds=1)
# Listen only once
while True:
socketIO.wait(seconds=1)