diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..970dc27 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "labylib"] + path = labylib + url = git://github.com/VictorWesterlund/labylib.git diff --git a/labylib b/labylib new file mode 160000 index 0000000..a8db13c --- /dev/null +++ b/labylib @@ -0,0 +1 @@ +Subproject commit a8db13cbf6b15e3b3676065055e48ea2271d62d3 diff --git a/render/background.png b/render/background.png new file mode 100644 index 0000000..5d92343 Binary files /dev/null and b/render/background.png differ diff --git a/servers.json b/servers.json new file mode 100644 index 0000000..d0fd88b --- /dev/null +++ b/servers.json @@ -0,0 +1,5 @@ +{ + "us.mineplex.net": [ + "/(?<=\\[CHAT\\])(.*)(?=ULTRA|HERO|LEGEND|TITAN|ETERNAL|IMMORTAL|TRAINEE|MOD)/g" + ] +} \ No newline at end of file diff --git a/start.py b/start.py new file mode 100644 index 0000000..bc345b9 --- /dev/null +++ b/start.py @@ -0,0 +1,109 @@ +from labylib import Cape +from threading import Thread, Event +from pathlib import Path + +from PIL import Image +from PIL import ImageFont +from PIL import ImageDraw + +import platform +import getpass +import subprocess + +# Chattycape daemon +class Chattycape(Thread): + + pollRate = 1 # Logfile pollrate + updateRate = 1 # Update rate of Labylib cosmetic + + def __init__(self,event,phpsessid,logfile): + Thread.__init__(self) + self.stopped = event + + self.phpsessid = phpsessid + self.logfile = logfile + + self.line = "" + + self.i = 0 + + # Poll last line from logfile + def linefeed(self): + self.line = subprocess.check_output(['tail','-1',self.logfile]) + + # Update labylib cosmetic + def update(self): + print(self.line) + + def run(self): + while not self.stopped.wait(Chattycape.pollRate): + self.linefeed() # Poll logfile + + # Cooldown for labylib texture update + if(self.i >= (Chattycape.updateRate * Chattycape.pollRate)): + self.update() + self.i = 0 + + self.i += 1 + + +# Initializer and watchdog +class Main: + + def __init__(self): + print("-- Labylib Chattycape --") + self.logfile = self.locate() + self.phpsessid = input("\nhttps://github.com/VictorWesterlund/labylib#find-your-phpsessid-cookie\nPaste your PHPSESSID here:\n") + + self.start() + + # Attempt to locate '.minecraft' automatically, otherwise prompt user + def locate(self): + sys = platform.system() # Get operating system + user = getpass.getuser() # Get current user + + mclog = "/logs/latest.log" + + # Default locations for various systems + paths = { + "Linux": [ + "~/.minecraft", + f"/mnt/c/Users/{user}/AppData/Roaming/.minecraft", # Windows Subsystem for Linux (WSL) + f"/home/{user}/.minecraft" + ], + "Windows": [ + "%APPDATA%\.minecraft", + f"C://Users/{user}/AppData/Roaming/.minecraft", + ], + "Darwin": [ + "~/Library/Application Support/minecraft" # macOS + ] + } + + for path in paths[sys]: + if(Path(path).exists()): + return path + mclog + + # Failed to locate Minecraft-installation automatically + + path = input("Please paste the path to your '.minecraft'-folder:\n") + + if(Path(path).exists()): + return path + mclog + + print(f"\nInvalid path; No Minecraft-installation found at '{path}'") + self.locate() + + def start(self): + stop = Event() + + # Start the daemon + chattycape = Chattycape(stop,self.phpsessid,self.logfile) + chattycape.start() + + interrupt = input("\nRunning! Press enter to stop\n") + stop.set() # Stop the daemon + print("Bye!") + +main = Main() +print(main.file) \ No newline at end of file