-
Notifications
You must be signed in to change notification settings - Fork 1
/
head.py
46 lines (33 loc) · 1.29 KB
/
head.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
import subprocess
from mouth import Mouth
class Head():
def __init__(self, bot):
if bot:
self.mouth = Mouth(bot)
def run_command(self, command):
return subprocess.getoutput(command)
def get_ip_addr(self):
# addr = subprocess.getoutput('hostname -I')
addr = self.run_command('hostname -I')
return addr.split(maxsplit=1)[0]
def start_vncserver(self):
return self.run_command('vncserver :1')
def get_command_and_params(self, msg):
v = msg.replace('/', '', 1).split(maxsplit=1)
if len(v) > 1:
return v[0].lower(), v[1]
return v[0].lower(), None
def handle_commands(self, msg):
cmd, params = self.get_command_and_params(msg)
print(cmd, params)
if cmd == 'start' or cmd == 'hello' or cmd == 'hi' or cmd == 'what\'s up' or cmd == 'help':
return self.mouth.help()
if cmd == 'run':
return self.mouth.command_output(self.run_command(params))
if cmd == 'ip':
return self.mouth.myip(self.get_ip_addr())
if cmd == 'vnc':
return self.mouth.command_output(self.start_vncserver())
return self.mouth.sorry()
def greetings(self):
return self.mouth.greetings(self.get_ip_addr())