From b45ebba4b4ef62336272ef1b8de5c91f48ea7a60 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Mon, 16 Nov 2020 03:53:29 +0100 Subject: [PATCH] Draft for 0.0.1 Minecraft chat poller is working. Next priority is chat filtering --- .gitmodules | 3 ++ labylib | 1 + render/background.png | Bin 0 -> 239 bytes servers.json | 5 ++ start.py | 109 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+) create mode 100644 .gitmodules create mode 160000 labylib create mode 100644 render/background.png create mode 100644 servers.json create mode 100644 start.py 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 0000000000000000000000000000000000000000..5d92343e7e4c5ed96cfdac10a60c7295e0572783 GIT binary patch literal 239 zcmeAS@N?(olHy`uVBq!ia0y~yU`z&LVJ2pv$h^M(%|MDLz$e7jy};+o7X~J#U;qFA zPkm6f0w~T{666=m;PC858jv&5)5S5Q;?~>i8+jWHcw8O%J7)@>n4lsQ(xD~DyE8oM z*LCZ2*Dl_i7ykNj+$>2)waF)+2>#41jbl1D%FX42Xq{Rr>mdKI;Vst01eq(Pyhe` literal 0 HcmV?d00001 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