Skip to content

Commit

Permalink
TEMP
Browse files Browse the repository at this point in the history
  • Loading branch information
Amund211 committed Sep 10, 2024
1 parent c41f79b commit 6d4bebe
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/prism/overlay/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,13 @@ def get_estimated_winstreaks(self) -> Callable[[str], tuple["Winstreaks", bool]]
@abstractmethod
def store_settings(self) -> Callable[[], None]:
raise NotImplementedError

@property
@abstractmethod
def schedule_autowho(self) -> Callable[[], None]:
raise NotImplementedError

@property
@abstractmethod
def cancel_autowho(self) -> Callable[[], None]:
raise NotImplementedError
11 changes: 11 additions & 0 deletions src/prism/overlay/process_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,23 @@ def process_event(
if event.event_type is EventType.BEDWARS_GAME_STARTING_SOON:
# Bedwars game is starting soon
logger.info(f"Bedwars game starting soon {event.seconds} second(s)")
# if state.in_queue:
# return state, False

controller.cancel_autowho()

return state, False

if event.event_type is EventType.START_BEDWARS_GAME:
# Bedwars game has started
logger.info("Bedwars game starting")

controller.schedule_autowho()

# if not state.in_queue:
# Probably game end
# return state, False

# Leaving the queue and starting a game
# Reset the users preference for showing the overlay
controller.wants_shown = None
Expand Down
50 changes: 49 additions & 1 deletion src/prism/overlay/real_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
get_estimated_winstreaks,
get_playerdata,
)
from prism.overlay.controller import ERROR_DURING_PROCESSING, ProcessingError
from prism.overlay.controller import (
ERROR_DURING_PROCESSING,
OverlayController,
ProcessingError,
)
from prism.overlay.player import MISSING_WINSTREAKS
from prism.ratelimiting import RateLimiter
from prism.ssl_errors import MissingLocalIssuerSSLError
Expand Down Expand Up @@ -64,6 +68,8 @@ def __init__(
else None
)

AutoWhoThread(self.autowho_event, self).start()

def get_uuid(self, username: str) -> str | None | ProcessingError:
try:
uuid = get_uuid(username)
Expand Down Expand Up @@ -132,3 +138,45 @@ def get_estimated_winstreaks(

def store_settings(self) -> None:
self.settings.flush_to_disk()

def schedule_autowho(self) -> None:
self.autowho_event.set()

def cancel_autowho(self) -> None:
self.autowho_event.clear()


class AutoWhoThread(threading.Thread): # pragma: nocover
"""Thread that types /who on request, unless cancelled"""

def __init__(
self,
autowho_event: threading.Event,
controller: OverlayController,
) -> None:
super().__init__(daemon=True) # Don't block the process from exiting
self.autowho_event = autowho_event
self.controller = controller

def run(self) -> None:
"""Wait for requests, check if not cancelled, then type /who"""
try:
while True:
self.autowho_event.wait()
# time.sleep(self.controller.settings.autowho_delay)
time.sleep(2)
if not self.autowho_event.is_set():
continue

self.autowho_event.clear()

from pynput.keyboard import Controller, Key

keyboard = Controller()
keyboard.type("u")
time.sleep(0.1)
keyboard.type("/who")
keyboard.tap(Key.enter)
except Exception:
logger.exception("Exception caught in autowho thread. Exiting.")
# We let the overlay keep working if the autowho thread dies
2 changes: 1 addition & 1 deletion src/prism/overlay/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_test_loglines(options: Options) -> Iterable[str]: # pragma: nocover
f"{CHAT}sdflksjdfh has joined (2/16)!",
f"{CHAT}sdflksjddfoih has joined (3/16)!",
f"{CHAT}ONLINE: Testing, Teammate, Hypixel, Technoblade, Manhal_IQ_, SomeUnknownNick", # noqa: E501
# f"{CHAT} Bed Wars ", # game start
f"{CHAT} Bed Wars ", # game start
# f"{CHAT}Hypixel was killed by Testing. FINAL KILL!",
# f"{CHAT}1st Killer - [MVP+] Player1", # game end
]
Expand Down

0 comments on commit 6d4bebe

Please sign in to comment.