From 3bd5496658c920b044341592ee2e6f1bd4273e1a Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Tue, 3 May 2022 01:54:31 +0200 Subject: [PATCH] minecraft player counter --- profiles/xsession/polybar.nix | 50 ++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/profiles/xsession/polybar.nix b/profiles/xsession/polybar.nix index 47b9080..763a841 100644 --- a/profiles/xsession/polybar.nix +++ b/profiles/xsession/polybar.nix @@ -45,7 +45,7 @@ in module-margin-right = "2"; modules-left = "i3 title"; - modules-right = "wlan eth filesystem uquota cpu memory battery date"; + modules-right = "minecraft wlan eth filesystem uquota cpu memory battery date"; }; "module/i3" = { @@ -178,6 +178,54 @@ in time = "%H:%M:%S"; label = "%date% %time%"; }; + + "module/minecraft" = { + type = "custom/script"; + exec = "" + pkgs.writers.writePython3 "minecraft_status" { libraries = [ pkgs.python3.pkgs.mcstatus ]; flakeIgnore = [ "E722" ]; } '' + from mcstatus import MinecraftServer as JavaServer + pvv = JavaServer.lookup("minecraft.pvv.ntnu.no") + dods = JavaServer.lookup("mc.dodsorf.as") + + try: + pvv_status = pvv.status() + dods_status = dods.status() + except: + pass + + result = "" + try: + if pvv_status.players.online > 0: + result += ("P" + str(pvv_status.players.online)) + if dods_status > 0: + result += ("D" + str(pvv_status.players.online)) + except: + pass + print(result) + ''; + click-left = "" + pkgs.writers.writePython3 "minecraft_status" { libraries = [ pkgs.python3.pkgs.mcstatus ]; flakeIgnore = [ "E722" ]; } '' + from mcstatus import MinecraftServer as JavaServer + import os + + pvv = JavaServer.lookup("minecraft.pvv.ntnu.no") + dods = JavaServer.lookup("mc.dodsorf.as") + + try: + pvv_status = pvv.status() + dods_status = dods.status() + except: + pass + + result = "" + if pvv_status.players.sample is not None: + result += "PVV\n" + for player in pvv_status.players.sample: + result += player + os.exec("notify-send", "Minecraft Server Status", result) + ''; + interval = 10; + format = "