refactor mc status
This commit is contained in:
parent
62120c63d1
commit
e5d55ba0ad
|
@ -191,73 +191,55 @@ in
|
||||||
|
|
||||||
"module/minecraft" = {
|
"module/minecraft" = {
|
||||||
type = "custom/script";
|
type = "custom/script";
|
||||||
exec = "" + pkgs.writers.writePython3 "minecraft_status" { libraries = [ pkgs.python3.pkgs.mcstatus ]; flakeIgnore = [ "E722" ]; } ''
|
exec = "" + pkgs.writers.writePython3 "minecraft_status" {
|
||||||
|
libraries = with pkgs.python3.pkgs; [ mcstatus notify2 ];
|
||||||
|
flakeIgnore = [ "E722" ];
|
||||||
|
} ''
|
||||||
from mcstatus import JavaServer
|
from mcstatus import JavaServer
|
||||||
pvv = JavaServer.lookup("minecraft.pvv.ntnu.no")
|
import signal
|
||||||
dods = JavaServer.lookup("mc.dodsorf.as")
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
|
def see_players():
|
||||||
|
result = ""
|
||||||
|
if pvv_status is not None:
|
||||||
|
result += "PVV: "
|
||||||
|
for player in pvv_status.players.sample:
|
||||||
|
result += player.name + " "
|
||||||
|
result += "\n"
|
||||||
|
if dods_status is not None:
|
||||||
|
result += "DODS: "
|
||||||
|
for player in dods_status.players.sample:
|
||||||
|
result += player.name + " "
|
||||||
|
result += "\n"
|
||||||
|
|
||||||
try:
|
|
||||||
pvv_status = pvv.status()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
signal.signal(signal.SIGUSR1, see_players)
|
||||||
dods_status = dods.status()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
result = ""
|
while True:
|
||||||
try:
|
result = ""
|
||||||
if pvv_status.players.online > 0:
|
try:
|
||||||
result += ("P" + str(pvv_status.players.online))
|
pvv = JavaServer.lookup("minecraft.pvv.ntnu.no")
|
||||||
except:
|
pvv_status = pvv.status()
|
||||||
pass
|
if pvv_status.players.online > 0:
|
||||||
|
result += ("P" + str(pvv_status.players.online))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if dods_status.players.online > 0:
|
dods = JavaServer.lookup("mc.dodsorf.as")
|
||||||
result += ("D" + str(dods_status.players.online))
|
dods_status = dods.status()
|
||||||
except:
|
if dods_status.players.online > 0:
|
||||||
pass
|
result += ("D" + str(dods_status.players.online))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
print(result)
|
print(result)
|
||||||
|
sleep(5)
|
||||||
'';
|
'';
|
||||||
click-left = "" + pkgs.writers.writePython3 "minecraft_status" { libraries = with pkgs.python3.pkgs; [ mcstatus notify2 ]; flakeIgnore = [ "E722" ]; } ''
|
click-left = "kill -USR1 %pid%";
|
||||||
from mcstatus import JavaServer
|
# interval =
|
||||||
import notify2
|
tail = true;
|
||||||
|
|
||||||
pvv = JavaServer.lookup("minecraft.pvv.ntnu.no")
|
|
||||||
dods = JavaServer.lookup("mc.dodsorf.as")
|
|
||||||
|
|
||||||
pvv_status = None
|
|
||||||
dods_status = None
|
|
||||||
|
|
||||||
try:
|
|
||||||
pvv_status = pvv.status()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
dods_status = dods.status()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
result = ""
|
|
||||||
if pvv_status is not None:
|
|
||||||
result += "PVV: "
|
|
||||||
for player in pvv_status.players.sample:
|
|
||||||
result += player.name + " "
|
|
||||||
result += "\n"
|
|
||||||
if dods_status is not None:
|
|
||||||
result += "DODS: "
|
|
||||||
for player in dods_status.players.sample:
|
|
||||||
result += player.name + " "
|
|
||||||
result += "\n"
|
|
||||||
|
|
||||||
notify2.init('Minecraft Server Status')
|
|
||||||
n = notify2.Notification("Minecraft Server Status", result)
|
|
||||||
n.show()
|
|
||||||
'';
|
|
||||||
interval = 10;
|
|
||||||
format = " <label>";
|
format = " <label>";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue