2020-02-27 21:47:36 +08:00
|
|
|
|
from zzcore import StdAns
|
2020-02-27 22:34:47 +08:00
|
|
|
|
import re
|
2020-02-28 19:39:40 +08:00
|
|
|
|
from subprocess import getoutput,call
|
2020-02-27 21:47:36 +08:00
|
|
|
|
|
|
|
|
|
class Ans(StdAns):
|
2020-07-15 19:43:33 +08:00
|
|
|
|
AllowGroup = [959613860, 125733077, 204097403, 1140391080]
|
2020-08-02 23:44:45 +08:00
|
|
|
|
AllowUser = [1318000868]
|
2020-02-27 21:47:36 +08:00
|
|
|
|
def GETMSG(self):
|
2020-02-28 19:42:53 +08:00
|
|
|
|
if len(self.parms) < 2:
|
|
|
|
|
return '不加参数是坏文明!'
|
2020-02-27 22:34:47 +08:00
|
|
|
|
cmd = self.parms[1]
|
2020-02-28 19:39:40 +08:00
|
|
|
|
AllowCmd = ['list','status','say']
|
|
|
|
|
|
2020-02-27 22:34:47 +08:00
|
|
|
|
if cmd in AllowCmd:
|
2020-02-28 19:39:40 +08:00
|
|
|
|
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':
|
2020-02-27 22:46:35 +08:00
|
|
|
|
output = getoutput('spigot command list')
|
2020-02-27 22:34:47 +08:00
|
|
|
|
p = re.compile(r'There are (.*?)[ of a max]', re.S)
|
2020-02-28 19:39:40 +08:00
|
|
|
|
online = re.findall(p,output)[0]
|
|
|
|
|
if online == '0':
|
2020-02-27 22:34:47 +08:00
|
|
|
|
msg = '咱看着没有人在线哎\n_(-ω-`_)⌒)_'
|
|
|
|
|
else:
|
2020-02-28 19:39:40 +08:00
|
|
|
|
msg = '有' + online + '个小伙伴在线!'
|
2020-02-27 22:34:47 +08:00
|
|
|
|
p = re.compile(r'online: (.*?)[\n>]', re.S)
|
2020-02-27 22:35:24 +08:00
|
|
|
|
players = re.findall(p,output)[0].split(', ')
|
2020-02-27 22:34:47 +08:00
|
|
|
|
for player in players:
|
|
|
|
|
msg = msg + '\n' + player
|
2020-02-28 19:39:40 +08:00
|
|
|
|
elif cmd == 'say':
|
|
|
|
|
saywhat = self.raw_msg['message'][8:]
|
2020-02-28 19:46:17 +08:00
|
|
|
|
if not saywhat:
|
|
|
|
|
return '汝让咱say what?o(≧口≦)o'
|
2020-02-28 19:39:40 +08:00
|
|
|
|
shellcmd = ['spigot','command','say',saywhat]
|
|
|
|
|
if call(shellcmd) == 0:
|
|
|
|
|
msg = '咱已经把消息传过去了。'
|
|
|
|
|
else:
|
|
|
|
|
msg = '٩(ŏ﹏ŏ、)۶竟然失败了,汝是不是让我发送奇怪的话过去!'
|
2020-02-27 21:47:36 +08:00
|
|
|
|
else:
|
2020-02-28 19:39:40 +08:00
|
|
|
|
msg = '汝是不是在mc后面添加了奇怪的参数,咱可只知道 status list 和 say。'
|
|
|
|
|
|
2020-06-01 22:50:52 +08:00
|
|
|
|
return msg
|