mc up up
This commit is contained in:
parent
6b331144c4
commit
622683df5e
1 changed files with 30 additions and 10 deletions
40
worker/mc.py
40
worker/mc.py
|
@ -1,26 +1,46 @@
|
|||
from zzcore import StdAns
|
||||
import re
|
||||
from subprocess import getoutput
|
||||
from subprocess import getoutput,call
|
||||
|
||||
class Ans(StdAns):
|
||||
AllowGroup = [959613860]
|
||||
def GETMSG(self):
|
||||
cmd = self.parms[1]
|
||||
if cmd == 'status':
|
||||
return getoutput('spigot status')
|
||||
AllowCmd = ['list']
|
||||
AllowCmd = ['list','status','say']
|
||||
|
||||
if cmd in AllowCmd:
|
||||
if cmd == 'list':
|
||||
if cmd == 'status':
|
||||
output = getoutput('spigot status')
|
||||
p = re.compile(r'processes = ([0-9]*) \(')
|
||||
prsnum = re.findall(p,output)[0]
|
||||
p = re.compile(r' \((.*?)\)',re.S)
|
||||
prsnames = re.findall(p,output)[0].split(', ')
|
||||
p = re.compile(r'Total memory usage = (.*)$')
|
||||
memory = re.findall(p,output)[0]
|
||||
msg = '咱的MC服务器现在有 '
|
||||
for prsname in prsnames:
|
||||
msg = msg + prsname + ' '
|
||||
msg = msg + '这' + prsnum +'个进程,\n一共占用了' + memory +'内存呢。'
|
||||
elif cmd == 'list':
|
||||
output = getoutput('spigot command list')
|
||||
p = re.compile(r'There are (.*?)[ of a max]', re.S)
|
||||
online = int(re.findall(p,output)[0])
|
||||
if online == 0:
|
||||
online = re.findall(p,output)[0]
|
||||
if online == '0':
|
||||
msg = '咱看着没有人在线哎\n_(-ω-`_)⌒)_'
|
||||
else:
|
||||
msg = '有' + str(online) + '个小伙伴在线!'
|
||||
msg = '有' + online + '个小伙伴在线!'
|
||||
p = re.compile(r'online: (.*?)[\n>]', re.S)
|
||||
players = re.findall(p,output)[0].split(', ')
|
||||
for player in players:
|
||||
msg = msg + '\n' + player
|
||||
return msg
|
||||
elif cmd == 'say':
|
||||
saywhat = self.raw_msg['message'][8:]
|
||||
shellcmd = ['spigot','command','say',saywhat]
|
||||
if call(shellcmd) == 0:
|
||||
msg = '咱已经把消息传过去了。'
|
||||
else:
|
||||
return self.parms[1] + ' 是暂时不被允许的命令!'
|
||||
msg = '٩(ŏ﹏ŏ、)۶竟然失败了,汝是不是让我发送奇怪的话过去!'
|
||||
else:
|
||||
msg = '汝是不是在mc后面添加了奇怪的参数,咱可只知道 status list 和 say。'
|
||||
|
||||
return msg
|
Loading…
Reference in a new issue