refactor mc status

This commit is contained in:
Daniel Lovbrotte Olsen 2022-06-20 23:35:14 +02:00
parent 62120c63d1
commit e5d55ba0ad
1 changed files with 42 additions and 60 deletions

View File

@ -191,56 +191,16 @@ 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
try:
pvv_status = pvv.status()
except:
pass
try:
dods_status = dods.status()
except:
pass
result = ""
try:
if pvv_status.players.online > 0:
result += ("P" + str(pvv_status.players.online))
except:
pass
try:
if dods_status.players.online > 0:
result += ("D" + str(dods_status.players.online))
except:
pass
print(result)
'';
click-left = "" + pkgs.writers.writePython3 "minecraft_status" { libraries = with pkgs.python3.pkgs; [ mcstatus notify2 ]; flakeIgnore = [ "E722" ]; } ''
from mcstatus import JavaServer
import notify2
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
def see_players():
result = "" result = ""
if pvv_status is not None: if pvv_status is not None:
result += "PVV: " result += "PVV: "
@ -253,11 +213,33 @@ in
result += player.name + " " result += player.name + " "
result += "\n" result += "\n"
notify2.init('Minecraft Server Status')
n = notify2.Notification("Minecraft Server Status", result) signal.signal(signal.SIGUSR1, see_players)
n.show()
while True:
result = ""
try:
pvv = JavaServer.lookup("minecraft.pvv.ntnu.no")
pvv_status = pvv.status()
if pvv_status.players.online > 0:
result += ("P" + str(pvv_status.players.online))
except:
pass
try:
dods = JavaServer.lookup("mc.dodsorf.as")
dods_status = dods.status()
if dods_status.players.online > 0:
result += ("D" + str(dods_status.players.online))
except:
pass
print(result)
sleep(5)
''; '';
interval = 10; click-left = "kill -USR1 %pid%";
# interval =
tail = true;
format = " <label>"; format = " <label>";
}; };
}; };