add ability to auto-switch between team and match chat

This commit is contained in:
ultrablob 2025-02-13 11:28:33 -05:00
parent c86d383c79
commit b47e9cddbd
5 changed files with 164 additions and 19 deletions

48
main.py
View file

@ -6,11 +6,14 @@ from slang import replacements
import re
import subprocess
from time import sleep
from mss import mss
import numpy as np
import sounddevice # turns off alsa error logging
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
r.adjust_for_ambient_noise(source, duration=3)
def recognize_text() -> str:
@ -22,7 +25,27 @@ def recognize_text() -> str:
return result
def chat_type():
screen = mss() #! bad for performance but necessary
screenshot = np.array(screen.grab({"top": 1090, "left": 1110, "width": 100, "height": 100}))
try:
pg.locate("ui/team-chat.png", screenshot, confidence=0.9)
return "team"
except pg.ImageNotFoundException:
pass
try:
pg.locate("ui/match-chat.png", screenshot, confidence=0.9)
return "match"
except pg.ImageNotFoundException:
pass
return None
def on_press(key):
if key is not keyboard.Key.home:
return
@ -42,17 +65,28 @@ def on_press(key):
print(f"Cleaned up command: {command}")
if "chat" in command:
message = re.search(r"type (.+?)(in |\n|$)", command).groups(0)[0].strip()
message = re.search(r"type (.+?)(and |in |\n|$)", command).groups(0)[0].strip()
print(f"Typing: {message} in team chat")
pg.keyDown("enter")
sleep(0.041)
pg.keyUp("enter")
pg.typewrite(message, 0.048)
pg.keyDown("enter")
sleep(0.074)
pg.keyUp("enter")
sleep(0.94)
elif any(keyword in command for keyword in ["maximum", "pulse", "balls", "remove", "eliminate", "murder"]):
current_chat = chat_type()
if current_chat in command:
pass # no change needed
elif "match" in command or "team" in command:
pg.keyDown("tab")
sleep(0.041)
pg.keyUp("tab")
pg.typewrite(message, 0.048)
# pg.keyDown("enter")
# sleep(0.074)
# pg.keyUp("enter")
elif any(keyword in command for keyword in ["maximum", "pulse", "balls", "remove", "eliminate", "murder", "goon"]):
print("MAXIMUM PULSE!!!!")
pg.keyDown("q")
sleep(0.032)