diff --git a/worker/mc.py b/worker/mc.py index 138f7bc..9337a40 100644 --- a/worker/mc.py +++ b/worker/mc.py @@ -1,14 +1,26 @@ from zzcore import StdAns +import re from subprocess import getoutput class Ans(StdAns): def GETMSG(self): - if self.parms[1] == 'status': + cmd = self.parms[1] + if cmd == 'status': return getoutput('spigot status') - AllowCmd = ['list','tps'] - if self.parms[1] in AllowCmd: - cmd = 'spigot command ' - cmd = cmd + self.parms[1] - return getoutput(cmd) + AllowCmd = ['list'] + if cmd in AllowCmd: + if cmd == 'list': + output = getoutput('spigot status') + p = re.compile(r'There are (.*?)[ of a max]', re.S) + online = int(re.findall(p,a)[0]) + if online == 0: + msg = '咱看着没有人在线哎\n_(-ω-`_)⌒)_' + else: + msg = '有' + str(online) + '个小伙伴在线!' + p = re.compile(r'online: (.*?)[\n>]', re.S) + players = re.findall(p,a)[0].split(', ') + for player in players: + msg = msg + '\n' + player + return msg else: return self.parms[1] + ' 是暂时不被允许的命令!' \ No newline at end of file