mirror of
https://codeberg.org/vlw/labylib-chattycape.git
synced 2025-09-13 16:13:41 +02:00
Draft for 0.0.1
Minecraft chat poller is working. Next priority is chat filtering
This commit is contained in:
parent
22f6faa563
commit
b45ebba4b4
5 changed files with 118 additions and 0 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "labylib"]
|
||||
path = labylib
|
||||
url = git://github.com/VictorWesterlund/labylib.git
|
1
labylib
Submodule
1
labylib
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit a8db13cbf6b15e3b3676065055e48ea2271d62d3
|
BIN
render/background.png
Normal file
BIN
render/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 239 B |
5
servers.json
Normal file
5
servers.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"us.mineplex.net": [
|
||||
"/(?<=\\[CHAT\\])(.*)(?=ULTRA|HERO|LEGEND|TITAN|ETERNAL|IMMORTAL|TRAINEE|MOD)/g"
|
||||
]
|
||||
}
|
109
start.py
Normal file
109
start.py
Normal file
|
@ -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)
|
Loading…
Add table
Reference in a new issue