Refactored code. Added setup.py installation script. Implemented logging.
authorGeorgios Atheridis <georgios@atheridis.org>
Sat, 14 Jan 2023 23:55:11 +0000 (23:55 +0000)
committerGeorgios Atheridis <georgios@atheridis.org>
Sat, 14 Jan 2023 23:55:11 +0000 (23:55 +0000)
93 files changed:
README.md
announcer.pyw [deleted file]
announcer/__init__.py [new file with mode: 0644]
announcer/constants.py [new file with mode: 0644]
announcer/events.py [new file with mode: 0644]
announcer/main.py [new file with mode: 0644]
announcer/sounds/peks/AllyAce/allyace.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyDeath/anallyhasbeenslain1.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyDeath/anallyhasbeenslain2.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyDoubleKill/doublekill1.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyDoubleKill/doublekill2.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor1.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor2.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyInhibitorRespawned/yourinhibitorhasrespawned.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyInhibitorRespawningSoon/yourinhibitorisrespawningsoon.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyKill/anenemyhasbeenslain1.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyKill/anenemyhasbeenslain2.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyKill/anenemyhasbeenslain3.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyPentaKill/pentakill1.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyPentaKill/pentakill2.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyQuadraKill/quadrakill.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyTripleKill/triplekill.mp3 [new file with mode: 0644]
announcer/sounds/peks/AllyTurretKill/yourteamhasdestroyedaturret.mp3 [new file with mode: 0644]
announcer/sounds/peks/Defeat/defeat.mp3 [new file with mode: 0644]
announcer/sounds/peks/EnemyAce/enemyace.mp3 [new file with mode: 0644]
announcer/sounds/peks/EnemyDoubleKill/enemydoublekill.mp3 [new file with mode: 0644]
announcer/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed1.mp3 [new file with mode: 0644]
announcer/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed2.mp3 [new file with mode: 0644]
announcer/sounds/peks/EnemyInhibitorRespawned/enemyinhibitorhasrespawned.mp3 [new file with mode: 0644]
announcer/sounds/peks/EnemyInhibitorRespawningSoon/enemyinhibitorisrespawningsoon.mp3 [new file with mode: 0644]
announcer/sounds/peks/EnemyPentaKill/enemypentakill.mp3 [new file with mode: 0644]
announcer/sounds/peks/EnemyQuadraKill/enemyquadrakill.mp3 [new file with mode: 0644]
announcer/sounds/peks/EnemyTripleKill/enemytriplekill.mp3 [new file with mode: 0644]
announcer/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed1.mp3 [new file with mode: 0644]
announcer/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed2.mp3 [new file with mode: 0644]
announcer/sounds/peks/Executed/executed1.mp3 [new file with mode: 0644]
announcer/sounds/peks/Executed/executed2.mp3 [new file with mode: 0644]
announcer/sounds/peks/Executed/executed3.mp3 [new file with mode: 0644]
announcer/sounds/peks/FirstBlood/firstblood.mp3 [new file with mode: 0644]
announcer/sounds/peks/MinionsSpawning/minionshavespawned.mp3 [new file with mode: 0644]
announcer/sounds/peks/MinionsSpawningSoon/30secondsuntilminionsspawn.mp3 [new file with mode: 0644]
announcer/sounds/peks/PlayerDeath/youhavebeenslain1.mp3 [new file with mode: 0644]
announcer/sounds/peks/PlayerDeath/youhavebeenslain2.mp3 [new file with mode: 0644]
announcer/sounds/peks/PlayerKill/youhaveslainanenemy1.mp3 [new file with mode: 0644]
announcer/sounds/peks/PlayerKill/youhaveslainanenemy2.mp3 [new file with mode: 0644]
announcer/sounds/peks/PlayerKill/youhaveslainanenemy3.mp3 [new file with mode: 0644]
announcer/sounds/peks/Victory/victory.mp3 [new file with mode: 0644]
announcer/sounds/peks/Welcome/welcometosummonersrift.mp3 [new file with mode: 0644]
announcer/window.py [new file with mode: 0644]
requirements.txt
setup.py [new file with mode: 0644]
sounds/peks/AllyAce/allyace.mp3 [deleted file]
sounds/peks/AllyDeath/anallyhasbeenslain1.mp3 [deleted file]
sounds/peks/AllyDeath/anallyhasbeenslain2.mp3 [deleted file]
sounds/peks/AllyDoubleKill/doublekill1.mp3 [deleted file]
sounds/peks/AllyDoubleKill/doublekill2.mp3 [deleted file]
sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor1.mp3 [deleted file]
sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor2.mp3 [deleted file]
sounds/peks/AllyInhibitorRespawned/yourinhibitorhasrespawned.mp3 [deleted file]
sounds/peks/AllyInhibitorRespawningSoon/yourinhibitorisrespawningsoon.mp3 [deleted file]
sounds/peks/AllyKill/anenemyhasbeenslain1.mp3 [deleted file]
sounds/peks/AllyKill/anenemyhasbeenslain2.mp3 [deleted file]
sounds/peks/AllyKill/anenemyhasbeenslain3.mp3 [deleted file]
sounds/peks/AllyPentaKill/pentakill1.mp3 [deleted file]
sounds/peks/AllyPentaKill/pentakill2.mp3 [deleted file]
sounds/peks/AllyQuadraKill/quadrakill.mp3 [deleted file]
sounds/peks/AllyTripleKill/triplekill.mp3 [deleted file]
sounds/peks/AllyTurretKill/yourteamhasdestroyedaturret.mp3 [deleted file]
sounds/peks/Defeat/defeat.mp3 [deleted file]
sounds/peks/EnemyAce/enemyace.mp3 [deleted file]
sounds/peks/EnemyDoubleKill/enemydoublekill.mp3 [deleted file]
sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed1.mp3 [deleted file]
sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed2.mp3 [deleted file]
sounds/peks/EnemyInhibitorRespawned/enemyinhibitorhasrespawned.mp3 [deleted file]
sounds/peks/EnemyInhibitorRespawningSoon/enemyinhibitorisrespawningsoon.mp3 [deleted file]
sounds/peks/EnemyPentaKill/enemypentakill.mp3 [deleted file]
sounds/peks/EnemyQuadraKill/enemyquadrakill.mp3 [deleted file]
sounds/peks/EnemyTripleKill/enemytriplekill.mp3 [deleted file]
sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed1.mp3 [deleted file]
sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed2.mp3 [deleted file]
sounds/peks/Executed/executed1.mp3 [deleted file]
sounds/peks/Executed/executed2.mp3 [deleted file]
sounds/peks/Executed/executed3.mp3 [deleted file]
sounds/peks/FirstBlood/firstblood.mp3 [deleted file]
sounds/peks/MinionsSpawning/minionshavespawned.mp3 [deleted file]
sounds/peks/MinionsSpawningSoon/30secondsuntilminionsspawn.mp3 [deleted file]
sounds/peks/PlayerDeath/youhavebeenslain1.mp3 [deleted file]
sounds/peks/PlayerDeath/youhavebeenslain2.mp3 [deleted file]
sounds/peks/PlayerKill/youhaveslainanenemy1.mp3 [deleted file]
sounds/peks/PlayerKill/youhaveslainanenemy2.mp3 [deleted file]
sounds/peks/PlayerKill/youhaveslainanenemy3.mp3 [deleted file]
sounds/peks/Victory/victory.mp3 [deleted file]
sounds/peks/Welcome/welcometosummonersrift.mp3 [deleted file]

index 1ede42987502899c0d677f80c843a1107782b265..8d2e2472a78bbf11ec4952f60b2ff8305004e06f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -4,8 +4,14 @@ Changes the default League of Legends announcer using Live Client Data API. Note
 \r
 ## Installation guide\r
 \r
-To run make sure to have a python interpreter.\r
+To install clone the repository and use pip to install it.\r
 ```sh\r
-pip install -r requirements.txt\r
-python announcer.pyw\r
+git clone https://github.com/IHasPeks/peks-announcer\r
+cd peks-announcer\r
+pip install .\r
+```\r
+\r
+If developing on this, install it using editable mode instead\r
+```sh\r
+pip install -e .\r
 ```\r
diff --git a/announcer.pyw b/announcer.pyw
deleted file mode 100644 (file)
index b581336..0000000
+++ /dev/null
@@ -1,312 +0,0 @@
-import requests
-import time
-import urllib3
-import audioplayer
-import os
-import sys
-import random
-import tkinter
-import tkinter.ttk
-import threading
-from PyQt5 import QtCore, QtGui, QtWidgets
-
-
-if os.name == "posix":
-    if "XDG_CONFIG_HOME" in os.environ and "XDG_CACHE_HOME" in os.environ:
-        LOGS_DIR = os.path.join(os.environ["XDG_CACHE_HOME"], "announcer")
-    elif "HOME" in os.environ:
-        LOGS_DIR = os.path.join(os.environ["HOME"], ".cache/announcer")
-    else:
-        print(
-            "HOME environment variable is not set, something must be very wrong.",
-            file=sys.stderr,
-        )
-        sys.exit(1)
-elif os.name == "nt":
-    if "APPDATA" in os.environ:
-        LOGS_DIR = os.path.join(os.environ["APPDATA"], "announcer")
-    else:
-        print(
-            "APPDATA is not set, something must be very wrong.",
-            file=sys.stderr,
-        )
-        sys.exit(1)
-else:
-    print("Your OS is not supported", file=sys.stderr)
-    sys.exit(1)
-
-SOUNDS_FOLDER = "sounds/"
-SOUND_PACKS = os.listdir(SOUNDS_FOLDER)
-volume = 100
-
-
-def play_event_sound(event: str):
-    global sound_pack
-    event_sounds = os.path.join(SOUNDS_FOLDER, sound_pack.get(), event)
-    sound = random.choice(os.listdir(event_sounds))
-    ap = audioplayer.AudioPlayer(os.path.join(event_sounds, sound))
-    ap.volume = volume
-    ap.play(block=True)
-
-
-def update_volume(v):
-    global volume
-    volume = int(v)
-
-
-def mute():
-    global volume_slider
-    volume_slider.set(0)
-
-
-def play_random_sound():
-    global sound_pack
-    sound_pack_dir = os.path.join(SOUNDS_FOLDER, sound_pack.get())
-    events = os.listdir(sound_pack_dir)
-    event = random.choice(events)
-    threading.Thread(
-        target=play_event_sound,
-        args=(event,),
-    ).start()
-
-
-def close_script():
-    gui.quit()
-    gui.destroy()
-    os._exit(0)
-
-
-# Ignore the Unverified HTTPS request warning.
-urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
-
-previous_game_time = 0
-game_time = 0
-previous_event_count = 0
-event_count = 0
-
-# Get event count so if the program is started in the middle of the match
-# it doesn't play every announcement sound which happened until that point.
-try:
-    # Get all data from the game in JSON format.
-    all_game_data = requests.get(
-        'https://127.0.0.1:2999/liveclientdata/allgamedata',
-        verify=False
-    ).json()
-    events = all_game_data["events"]["Events"]
-    event_count = len(events)
-    previous_event_count = event_count
-except:
-    pass
-
-
-def announcer_loop():
-    global stop
-    # File for logging exceptions.
-    os.makedirs(LOGS_DIR, exist_ok=True)
-    log_file = open(os.path.join(LOGS_DIR, "logs.txt"), "w")
-
-    global previous_game_time
-    global game_time
-    global previous_event_count
-    global event_count
-
-    global sound_pack
-
-    while True:
-        try:
-            # Get all data from the game in JSON format.
-            all_game_data = requests.get(
-                'https://127.0.0.1:2999/liveclientdata/allgamedata',
-                verify=False
-            ).json()
-
-            game_time = all_game_data["gameData"]["gameTime"]
-            events = all_game_data["events"]["Events"]
-
-            # TODO: move some things to only update once per game.
-            player_name = all_game_data["activePlayer"]["summonerName"]
-            player_team = ""
-            team_order_players = []
-            team_chaos_players = []
-            ally_team_players = []
-            enemy_team_players = []
-
-            # Populate team chaos and team order players lists
-            # and figure out which team the player is on.
-            for player in all_game_data["allPlayers"]:
-                if player["team"] == "ORDER":
-                    team_order_players.append(player["summonerName"])
-                    if player["summonerName"] == player_name:
-                        player_team = "ORDER"
-                elif player["team"] == "CHAOS":
-                    team_chaos_players.append(player["summonerName"])
-                    if player["summonerName"] == player_name:
-                        player_team = "CHAOS"
-
-            # Populate ally and enemy team player lists.
-            if player_team == "ORDER":
-                ally_team_players = team_order_players
-                enemy_team_players = team_chaos_players
-            elif player_team == "CHAOS":
-                ally_team_players = team_chaos_players
-                enemy_team_players = team_order_players
-
-            # Welcome announcement.
-            if game_time >= 26 and previous_game_time < 26 and game_time < 28:
-                play_event_sound("Welcome")
-            # Minions spawning soon.
-            if game_time >= 36 and previous_game_time < 36 and game_time < 38:
-                play_event_sound("MinionsSpawningSoon")
-
-            event_count = len(events)
-
-            # Loop over all new events.
-            for event_index in range(previous_event_count, event_count):
-                event = events[event_index]
-                event_name = event["EventName"]
-
-                # Someone got first blood.
-                if event_name == "ChampionKill" and event_index < event_count - 1 and events[event_index + 1]["EventName"] == "FirstBlood":
-                    play_event_sound("FirstBlood")
-                    event_index += 1
-                # Someone got a multikill.
-                elif event_name == "ChampionKill" and event_index < event_count - 1 and events[event_index + 1]["EventName"] == "Multikill":
-                    multikill = events[event_index + 1]["KillStreak"]
-                    # Ally got a multikill.
-                    if event["KillerName"] in ally_team_players:
-                        if multikill == 2:
-                            play_event_sound("AllyDoubleKill")
-                        elif multikill == 3:
-                            play_event_sound("AllyTripleKill")
-                        elif multikill == 4:
-                            play_event_sound("AllyQuadraKill")
-                        elif multikill == 5:
-                            play_event_sound("AllyPentaKill")
-                    # Enemy got a multikill.
-                    elif event["KillerName"] in enemy_team_players:
-                        if multikill == 2:
-                            play_event_sound("EnemyDoubleKill")
-                        elif multikill == 3:
-                            play_event_sound("EnemyTripleKill")
-                        elif multikill == 4:
-                            play_event_sound("EnemyQuadraKill")
-                        elif multikill == 5:
-                            play_event_sound("EnemyPentaKill")
-                    event_index += 1
-                # Someone got a kill.
-                elif event_name == "ChampionKill":
-                    # Player got a kill.
-                    if event["KillerName"] == player_name:
-                        play_event_sound("PlayerKill")
-                    # Ally got a kill.
-                    elif event["KillerName"] in ally_team_players:
-                        play_event_sound("AllyKill")
-                    # Enemy got a kill.
-                    elif event["KillerName"] in enemy_team_players:
-                        # Player was killed.
-                        if event["VictimName"] == player_name:
-                            play_event_sound("PlayerDeath")
-                        # Ally was killed.
-                        else:
-                            play_event_sound("AllyDeath")
-                    # Someone got executed.
-                    else:
-                        play_event_sound("Executed")
-                # A team scored an ace.
-                elif event_name == "Ace":
-                    # Ally team scored an ace.
-                    if event["AcingTeam"] == player_team:
-                        play_event_sound("AllyAce")
-                    # Enemy team scored an ace.
-                    else:
-                        play_event_sound("EnemyAce")
-                # A turret was killed.
-                elif event_name == "TurretKilled":
-                    turret_name = event["TurretKilled"]
-                    # Ally team got a turret kill.
-                    if turret_name[7:9] == "T2" and player_team == "ORDER" or turret_name[7:9] == "T1" and player_team == "CHAOS":
-                        play_event_sound("AllyTurretKill")
-                    # Enemy team got a turret kill.
-                    elif turret_name[7:9] == "T1" and player_team == "ORDER" or turret_name[7:9] == "T2" and player_team == "CHAOS":
-                        play_event_sound("EnemyTurretKill")
-                # A turret was killed.
-                elif event_name == "InhibKilled":
-                    inhib_name = event["InhibKilled"]
-                    # Ally team got a turret kill.
-                    if inhib_name[9:11] == "T2" and player_team == "ORDER" or inhib_name[9:11] == "T1" and player_team == "CHAOS":
-                        play_event_sound("AllyInhibitorKill")
-                    # Enemy team got a turret kill.
-                    elif inhib_name[9:11] == "T1" and player_team == "ORDER" or inhib_name[9:11] == "T2" and player_team == "CHAOS":
-                        play_event_sound("EnemyInhibitorKill")
-                # An inhibitor is respawning soon.
-                elif event_name == "InhibRespawningSoon":
-                    inhib_name = event["InhibRespawningSoon"]
-                    # Ally team's inhibitor is respawning soon.
-                    if inhib_name[9:11] == "T1" and player_team == "ORDER" or inhib_name[9:11] == "T2" and player_team == "CHAOS":
-                        play_event_sound("AllyInhibitorRespawningSoon")
-                    # Enemy team's inhibitor is respawning soon.
-                    elif inhib_name[9:11] == "T2" and player_team == "ORDER" or inhib_name[9:11] == "T1" and player_team == "CHAOS":
-                        play_event_sound("EnemyInhibitorRespawningSoon")
-                # An inhibitor has respawned.
-                elif event_name == "InhibRespawned":
-                    inhib_name = event["InhibRespawned"]
-                    # Ally team's inhibitor has respawned.
-                    if inhib_name[9:11] == "T1" and player_team == "ORDER" or inhib_name[9:11] == "T2" and player_team == "CHAOS":
-                        play_event_sound("AllyInhibitorRespawned")
-                    # Enemy team's inhibitor has respawned.
-                    elif inhib_name[9:11] == "T2" and player_team == "ORDER" or inhib_name[9:11] == "T1" and player_team == "CHAOS":
-                        play_event_sound("EnemyInhibitorRespawned")
-                # Minions have spawned.
-                elif event_name == "MinionsSpawning":
-                    play_event_sound("MinionsSpawning")
-                # Game has ended.
-                elif event_name == "GameEnd":
-                    # Victory
-                    if event["Result"] == "Win":
-                        play_event_sound("Victory")
-                    # Defeat
-                    elif event["Result"] == "Lose":
-                        play_event_sound("Defeat")
-                # TODO: killing streaks
-            previous_game_time = game_time
-            previous_event_count = event_count
-        except Exception as e:
-            # Probably not in game or some other catastrophic error.
-            print(e)
-            log_file.write(repr(e) + "\n")
-            log_file.flush()
-            time.sleep(5)
-
-class MainWindow(QtWidgets.QMainWindow):
-    def __init__(self):
-        super().__init__()
-        self.setWindowTitle("Peks Announcer")
-        self.setFixedSize(250, 150)
-        self.volume_slider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self)
-        self.mute_button = QtWidgets.QPushButton("Mute", self)
-        self.test_volume_button = QtWidgets.QPushButton("Test sound", self)
-        self.headerlabel = QtWidgets.QLabel("Hello World", self)
-        self.vollabel = QtWidgets.QLabel("Volume", self)
-        self.packlabel = QtWidgets.QLabel("Sound Pack:", self)
-        self.sound_pack = QtWidgets.QComboBox(self)
-        self.sound_pack.addItems(SOUND_PACKS)
-        self.central_widget = QtWidgets.QWidget(self)
-        self.setCentralWidget(self.central_widget)
-        self.layout = QtWidgets.QGridLayout(self.central_widget)
-        self.layout.addWidget(self.headerlabel, 0,1)
-        self.layout.addWidget(self.vollabel, 1,1)
-        self.layout.addWidget(self.volume_slider, 2,1)
-        self.layout.addWidget(self.mute_button, 1,0)
-        self.layout.addWidget(self.test_volume_button, 1,2)
-        self.layout.addWidget(self.packlabel, 3,0)
-        self.layout.addWidget(self.sound_pack, 3,1)
-    def setup_connections(self):
-        self.volume_slider.valueChanged.connect(update_volume)
-        self.mute_button.clicked.connect(mute)
-        self.test_volume_button.clicked.connect(play_random_sound)
-if __name__ == '__main__':
-    app = QtWidgets.QApplication(sys.argv)
-    window = MainWindow()
-    window.setup_connections()
-    window.show()
-    sys.exit(app.exec_())
diff --git a/announcer/__init__.py b/announcer/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/announcer/constants.py b/announcer/constants.py
new file mode 100644 (file)
index 0000000..15d87aa
--- /dev/null
@@ -0,0 +1,84 @@
+import os
+import sys
+
+DIR_NAME = "lol-announcer"
+
+if os.name == "posix":
+    if "XDG_CONFIG_HOME" in os.environ and "XDG_CACHE_HOME" in os.environ:
+        LOGS_DIR = os.path.join(os.environ["XDG_CACHE_HOME"], DIR_NAME, "logs")
+        SOUNDS_DIR_LOCAL = os.path.join(os.environ["XDG_CONFIG_HOME"], DIR_NAME, "sounds")
+    elif "HOME" in os.environ:
+        HOME = os.environ["HOME"]
+        LOGS_DIR = os.path.join(HOME, ".cache", DIR_NAME, "logs")
+        SOUNDS_DIR_LOCAL = os.path.join(HOME, ".config", DIR_NAME, "sounds")
+    else:
+        print("HOME environment variable is not set.", file=sys.stderr)
+        sys.exit(1)
+elif os.name == "nt":
+    if "APPDATA" in os.environ:
+        APPDATA = os.environ["APPDATA"]
+        LOGS_DIR = os.path.join(APPDATA, DIR_NAME)
+        LOGS_DIR = os.path.join(APPDATA, DIR_NAME, "logs")
+    else:
+        print("APPDATA is not set.", file=sys.stderr)
+        sys.exit(1)
+else:
+    print("Your OS is not supported.", file=sys.stderr)
+    sys.exit(1)
+
+
+os.makedirs(LOGS_DIR, exist_ok=True)
+os.makedirs(SOUNDS_DIR_LOCAL, exist_ok=True)
+SOUNDS_DIR_GLOBAL = os.path.join(os.path.dirname(__file__), "sounds/")
+
+
+SOUND_PACKS = dict()
+
+for dir in os.listdir(os.path.join(os.path.dirname(__file__), "sounds/")):
+    SOUND_PACKS[dir] = os.path.join(os.path.dirname(__file__), "sounds/", dir)
+
+for dir in os.listdir(SOUNDS_DIR_LOCAL):
+    SOUND_PACKS[dir] = os.path.join(SOUNDS_DIR_LOCAL, dir)
+
+
+LOGS_FILE = os.path.join(LOGS_DIR, "announcer.log")
+LOGGING_DICT = {
+    "version": 1,
+    "formatters": {
+        "brief": {
+            "format": "[%(levelname)s] %(filename)s:%(lineno)d; %(message)s",
+        },
+        "precise": {
+            "format": "%(asctime)s.%(msecs)03dZ %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s",
+            "datefmt": "%Y-%m-%dT%H:%M:%S",
+        },
+    },
+    "handlers": {
+        "console": {
+            "class": "logging.StreamHandler",
+            "level": "INFO",
+            "formatter": "brief",
+            "stream": "ext://sys.stdout",
+        },
+        "file": {
+            "class": "logging.handlers.RotatingFileHandler",
+            "level": "WARNING",
+            "formatter": "precise",
+            "filename": LOGS_FILE,
+            "maxBytes": 32 * 1024,
+            "backupCount": 3,
+        },
+    },
+    "loggers": {
+        "basicLogger": {
+            "level": "DEBUG",
+            "handlers": ["console", "file"],
+            "propagate": "no",
+        }
+    },
+    "root": {
+        "level": "DEBUG",
+        "handlers": ["console", "file"],
+    },
+    "disable_existing_loggers": False,
+}
diff --git a/announcer/events.py b/announcer/events.py
new file mode 100644 (file)
index 0000000..8e235a6
--- /dev/null
@@ -0,0 +1,210 @@
+import requests
+import urllib3
+import urllib3.exceptions
+import logging
+import time
+
+logger = logging.getLogger(__name__)
+
+# Ignore the Unverified HTTPS request warning.
+urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
+
+
+class Event:
+    ENDPOINT = "liveclientdata/allgamedata"
+
+    def __init__(self, ip: str = "127.0.0.1", port: int = 2999):
+        self.ip = ip
+        self.port = port
+        self.previous_event_count: int = 0
+        self.previous_game_time: int = 0
+        self.game_data: dict | None = None
+        self.new_events: list[str] = []
+
+        # If the Event class initializes while a game is running
+        # get all events up till that point, so that we don't send
+        # events that have already happened.
+        self._update_events()
+
+    def _update_events(self):
+        try:
+            game_data = requests.get(
+                f"https://{self.ip}:{self.port}/{Event.ENDPOINT}",
+                verify=False,
+            )
+        except requests.exceptions.ConnectionError as e:
+            # logger.exception(f"Unable to Connect to League Game. {e}")
+            self.game_data = None
+            time.sleep(3)
+        else:
+            logger.info("Connected to League Game")
+            self.game_data = game_data.json()
+
+    @property
+    def events(self) -> list:
+        if not self.game_data:
+            return []
+        return self.game_data["events"]["Events"]
+
+    @property
+    def event_count(self) -> int:
+        return len(self.events)
+
+    @property
+    def game_time(self) -> int:
+        if not self.game_data:
+            return 0
+        return self.game_data["gameData"]["gameTime"]
+
+    def event_polling(self) -> list[str]:
+        self.new_events = []
+        self._update_events()
+        if not self.game_data:
+            logger.warning("Polling without game data")
+            return []
+        self.player_name = self.game_data["activePlayer"]["summonerName"]
+        self.player_team = ""
+        self.team_order_players = []
+        self.team_chaos_players = []
+        self.ally_team_players = []
+        self.enemy_team_players = []
+
+        # Populate team chaos and team order players lists
+        # and figure out which team the player is on.
+        for player in self.game_data["allPlayers"]:
+            if player["team"] == "ORDER":
+                self.team_order_players.append(player["summonerName"])
+                if player["summonerName"] == self.player_name:
+                    self.player_team = "ORDER"
+            elif player["team"] == "CHAOS":
+                self.team_chaos_players.append(player["summonerName"])
+                if player["summonerName"] == self.player_name:
+                    self.player_team = "CHAOS"
+
+        # Populate ally and enemy team player lists.
+        if self.player_team == "ORDER":
+            self.ally_team_players = self.team_order_players
+            self.enemy_team_players = self.team_chaos_players
+        elif self.player_team == "CHAOS":
+            self.ally_team_players = self.team_chaos_players
+            self.enemy_team_players = self.team_order_players
+
+        # Welcome announcement.
+        if self.game_time >= 26 and self.previous_game_time < 26 and self.game_time < 28:
+            self.new_events.append("Welcome")
+        # Minions spawning soon.
+        if self.game_time >= 36 and self.previous_game_time < 36 and self.game_time < 38:
+            self.new_events.append("MinionsSpawningSoon")
+
+        # Loop over all new events.
+        for event_index in range(self.previous_event_count, self.event_count):
+            event = self.events[event_index]
+            event_name = event["EventName"]
+
+            # Someone got first blood.
+            if event_name == "ChampionKill" and event_index < self.event_count - 1 and self.events[event_index + 1]["EventName"] == "FirstBlood":
+                event_index += 1
+                self.new_events.append("FirstBlood")
+            # Someone got a multikill.
+            elif event_name == "ChampionKill" and event_index < self.event_count - 1 and self.events[event_index + 1]["EventName"] == "Multikill":
+                multikill = self.events[event_index + 1]["KillStreak"]
+                # Ally got a multikill.
+                if event["KillerName"] in self.ally_team_players:
+                    if multikill == 2:
+                        self.new_events.append("AllyDoubleKill")
+                    elif multikill == 3:
+                        self.new_events.append("AllyTripleKill")
+                    elif multikill == 4:
+                        self.new_events.append("AllyQuadraKill")
+                    elif multikill == 5:
+                        self.new_events.append("AllyPentaKill")
+                # Enemy got a multikill.
+                elif event["KillerName"] in self.enemy_team_players:
+                    if multikill == 2:
+                        self.new_events.append("EnemyDoubleKill")
+                    elif multikill == 3:
+                        self.new_events.append("EnemyTripleKill")
+                    elif multikill == 4:
+                        self.new_events.append("EnemyQuadraKill")
+                    elif multikill == 5:
+                        self.new_events.append("EnemyPentaKill")
+                event_index += 1
+            # Someone got a kill.
+            elif event_name == "ChampionKill":
+                # Player got a kill.
+                if event["KillerName"] == self.player_name:
+                    self.new_events.append("PlayerKill")
+                # Ally got a kill.
+                elif event["KillerName"] in self.ally_team_players:
+                    self.new_events.append("AllyKill")
+                # Enemy got a kill.
+                elif event["KillerName"] in self.enemy_team_players:
+                    # Player was killed.
+                    if event["VictimName"] == self.player_name:
+                        self.new_events.append("PlayerDeath")
+                    # Ally was killed.
+                    else:
+                        self.new_events.append("AllyDeath")
+                # Someone got executed.
+                else:
+                    self.new_events.append("Executed")
+            # A team scored an ace.
+            elif event_name == "Ace":
+                # Ally team scored an ace.
+                if event["AcingTeam"] == self.player_team:
+                    self.new_events.append("AllyAce")
+                # Enemy team scored an ace.
+                else:
+                    self.new_events.append("EnemyAce")
+            # A turret was killed.
+            elif event_name == "TurretKilled":
+                turret_name = event["TurretKilled"]
+                # Ally team got a turret kill.
+                if turret_name[7:9] == "T2" and self.player_team == "ORDER" or turret_name[7:9] == "T1" and self.player_team == "CHAOS":
+                    self.new_events.append("AllyTurretKill")
+                # Enemy team got a turret kill.
+                elif turret_name[7:9] == "T1" and self.player_team == "ORDER" or turret_name[7:9] == "T2" and self.player_team == "CHAOS":
+                    self.new_events.append("EnemyTurretKill")
+            # A turret was killed.
+            elif event_name == "InhibKilled":
+                inhib_name = event["InhibKilled"]
+                # Ally team got a turret kill.
+                if inhib_name[9:11] == "T2" and self.player_team == "ORDER" or inhib_name[9:11] == "T1" and self.player_team == "CHAOS":
+                    self.new_events.append("AllyInhibitorKill")
+                # Enemy team got a turret kill.
+                elif inhib_name[9:11] == "T1" and self.player_team == "ORDER" or inhib_name[9:11] == "T2" and self.player_team == "CHAOS":
+                    self.new_events.append("EnemyInhibitorKill")
+            # An inhibitor is respawning soon.
+            elif event_name == "InhibRespawningSoon":
+                inhib_name = event["InhibRespawningSoon"]
+                # Ally team's inhibitor is respawning soon.
+                if inhib_name[9:11] == "T1" and self.player_team == "ORDER" or inhib_name[9:11] == "T2" and self.player_team == "CHAOS":
+                    self.new_events.append("AllyInhibitorRespawningSoon")
+                # Enemy team's inhibitor is respawning soon.
+                elif inhib_name[9:11] == "T2" and self.player_team == "ORDER" or inhib_name[9:11] == "T1" and self.player_team == "CHAOS":
+                    self.new_events.append("EnemyInhibitorRespawningSoon")
+            # An inhibitor has respawned.
+            elif event_name == "InhibRespawned":
+                inhib_name = event["InhibRespawned"]
+                # Ally team's inhibitor has respawned.
+                if inhib_name[9:11] == "T1" and self.player_team == "ORDER" or inhib_name[9:11] == "T2" and self.player_team == "CHAOS":
+                    self.new_events.append("AllyInhibitorRespawned")
+                # Enemy team's inhibitor has respawned.
+                elif inhib_name[9:11] == "T2" and self.player_team == "ORDER" or inhib_name[9:11] == "T1" and self.player_team == "CHAOS":
+                    self.new_events.append("EnemyInhibitorRespawned")
+            # Minions have spawned.
+            elif event_name == "MinionsSpawning":
+                self.new_events.append("MinionsSpawning")
+            # Game has ended.
+            elif event_name == "GameEnd":
+                # Victory
+                if event["Result"] == "Win":
+                    self.new_events.append("Victory")
+                # Defeat
+                elif event["Result"] == "Lose":
+                    self.new_events.append("Defeat")
+            # TODO: killing streaks
+        self.previous_game_time = self.game_time
+        self.previous_event_count = self.event_count
+        logger.debug(self.new_events)
+        return self.new_events
diff --git a/announcer/main.py b/announcer/main.py
new file mode 100644 (file)
index 0000000..dc6df37
--- /dev/null
@@ -0,0 +1,22 @@
+import sys
+import logging
+import logging.config
+from .window import MainWindow
+from .constants import LOGGING_DICT, SOUND_PACKS
+from PyQt5 import QtWidgets
+
+logging.config.dictConfig(LOGGING_DICT)
+logger = logging.getLogger(__name__)
+
+
+def main():
+    logger.info(SOUND_PACKS)
+    app = QtWidgets.QApplication(sys.argv)
+    window = MainWindow()
+    window.setup_connections()
+    window.show()
+    sys.exit(app.exec_())
+
+
+if __name__ == "__main__":
+    main()
diff --git a/announcer/sounds/peks/AllyAce/allyace.mp3 b/announcer/sounds/peks/AllyAce/allyace.mp3
new file mode 100644 (file)
index 0000000..5554d9c
Binary files /dev/null and b/announcer/sounds/peks/AllyAce/allyace.mp3 differ
diff --git a/announcer/sounds/peks/AllyDeath/anallyhasbeenslain1.mp3 b/announcer/sounds/peks/AllyDeath/anallyhasbeenslain1.mp3
new file mode 100644 (file)
index 0000000..81afb19
Binary files /dev/null and b/announcer/sounds/peks/AllyDeath/anallyhasbeenslain1.mp3 differ
diff --git a/announcer/sounds/peks/AllyDeath/anallyhasbeenslain2.mp3 b/announcer/sounds/peks/AllyDeath/anallyhasbeenslain2.mp3
new file mode 100644 (file)
index 0000000..5f83b60
Binary files /dev/null and b/announcer/sounds/peks/AllyDeath/anallyhasbeenslain2.mp3 differ
diff --git a/announcer/sounds/peks/AllyDoubleKill/doublekill1.mp3 b/announcer/sounds/peks/AllyDoubleKill/doublekill1.mp3
new file mode 100644 (file)
index 0000000..8394dbb
Binary files /dev/null and b/announcer/sounds/peks/AllyDoubleKill/doublekill1.mp3 differ
diff --git a/announcer/sounds/peks/AllyDoubleKill/doublekill2.mp3 b/announcer/sounds/peks/AllyDoubleKill/doublekill2.mp3
new file mode 100644 (file)
index 0000000..4437f04
Binary files /dev/null and b/announcer/sounds/peks/AllyDoubleKill/doublekill2.mp3 differ
diff --git a/announcer/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor1.mp3 b/announcer/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor1.mp3
new file mode 100644 (file)
index 0000000..d66d59b
Binary files /dev/null and b/announcer/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor1.mp3 differ
diff --git a/announcer/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor2.mp3 b/announcer/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor2.mp3
new file mode 100644 (file)
index 0000000..90c3ed9
Binary files /dev/null and b/announcer/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor2.mp3 differ
diff --git a/announcer/sounds/peks/AllyInhibitorRespawned/yourinhibitorhasrespawned.mp3 b/announcer/sounds/peks/AllyInhibitorRespawned/yourinhibitorhasrespawned.mp3
new file mode 100644 (file)
index 0000000..52bb78e
Binary files /dev/null and b/announcer/sounds/peks/AllyInhibitorRespawned/yourinhibitorhasrespawned.mp3 differ
diff --git a/announcer/sounds/peks/AllyInhibitorRespawningSoon/yourinhibitorisrespawningsoon.mp3 b/announcer/sounds/peks/AllyInhibitorRespawningSoon/yourinhibitorisrespawningsoon.mp3
new file mode 100644 (file)
index 0000000..6bbc671
Binary files /dev/null and b/announcer/sounds/peks/AllyInhibitorRespawningSoon/yourinhibitorisrespawningsoon.mp3 differ
diff --git a/announcer/sounds/peks/AllyKill/anenemyhasbeenslain1.mp3 b/announcer/sounds/peks/AllyKill/anenemyhasbeenslain1.mp3
new file mode 100644 (file)
index 0000000..b723516
Binary files /dev/null and b/announcer/sounds/peks/AllyKill/anenemyhasbeenslain1.mp3 differ
diff --git a/announcer/sounds/peks/AllyKill/anenemyhasbeenslain2.mp3 b/announcer/sounds/peks/AllyKill/anenemyhasbeenslain2.mp3
new file mode 100644 (file)
index 0000000..28e4f82
Binary files /dev/null and b/announcer/sounds/peks/AllyKill/anenemyhasbeenslain2.mp3 differ
diff --git a/announcer/sounds/peks/AllyKill/anenemyhasbeenslain3.mp3 b/announcer/sounds/peks/AllyKill/anenemyhasbeenslain3.mp3
new file mode 100644 (file)
index 0000000..6ff29c5
Binary files /dev/null and b/announcer/sounds/peks/AllyKill/anenemyhasbeenslain3.mp3 differ
diff --git a/announcer/sounds/peks/AllyPentaKill/pentakill1.mp3 b/announcer/sounds/peks/AllyPentaKill/pentakill1.mp3
new file mode 100644 (file)
index 0000000..1dbcf6a
Binary files /dev/null and b/announcer/sounds/peks/AllyPentaKill/pentakill1.mp3 differ
diff --git a/announcer/sounds/peks/AllyPentaKill/pentakill2.mp3 b/announcer/sounds/peks/AllyPentaKill/pentakill2.mp3
new file mode 100644 (file)
index 0000000..c0e2535
Binary files /dev/null and b/announcer/sounds/peks/AllyPentaKill/pentakill2.mp3 differ
diff --git a/announcer/sounds/peks/AllyQuadraKill/quadrakill.mp3 b/announcer/sounds/peks/AllyQuadraKill/quadrakill.mp3
new file mode 100644 (file)
index 0000000..49e7cd5
Binary files /dev/null and b/announcer/sounds/peks/AllyQuadraKill/quadrakill.mp3 differ
diff --git a/announcer/sounds/peks/AllyTripleKill/triplekill.mp3 b/announcer/sounds/peks/AllyTripleKill/triplekill.mp3
new file mode 100644 (file)
index 0000000..9113f7c
Binary files /dev/null and b/announcer/sounds/peks/AllyTripleKill/triplekill.mp3 differ
diff --git a/announcer/sounds/peks/AllyTurretKill/yourteamhasdestroyedaturret.mp3 b/announcer/sounds/peks/AllyTurretKill/yourteamhasdestroyedaturret.mp3
new file mode 100644 (file)
index 0000000..9f18350
Binary files /dev/null and b/announcer/sounds/peks/AllyTurretKill/yourteamhasdestroyedaturret.mp3 differ
diff --git a/announcer/sounds/peks/Defeat/defeat.mp3 b/announcer/sounds/peks/Defeat/defeat.mp3
new file mode 100644 (file)
index 0000000..f46cbad
Binary files /dev/null and b/announcer/sounds/peks/Defeat/defeat.mp3 differ
diff --git a/announcer/sounds/peks/EnemyAce/enemyace.mp3 b/announcer/sounds/peks/EnemyAce/enemyace.mp3
new file mode 100644 (file)
index 0000000..b9d5dff
Binary files /dev/null and b/announcer/sounds/peks/EnemyAce/enemyace.mp3 differ
diff --git a/announcer/sounds/peks/EnemyDoubleKill/enemydoublekill.mp3 b/announcer/sounds/peks/EnemyDoubleKill/enemydoublekill.mp3
new file mode 100644 (file)
index 0000000..2476788
Binary files /dev/null and b/announcer/sounds/peks/EnemyDoubleKill/enemydoublekill.mp3 differ
diff --git a/announcer/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed1.mp3 b/announcer/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed1.mp3
new file mode 100644 (file)
index 0000000..35d81bf
Binary files /dev/null and b/announcer/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed1.mp3 differ
diff --git a/announcer/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed2.mp3 b/announcer/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed2.mp3
new file mode 100644 (file)
index 0000000..7f337b1
Binary files /dev/null and b/announcer/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed2.mp3 differ
diff --git a/announcer/sounds/peks/EnemyInhibitorRespawned/enemyinhibitorhasrespawned.mp3 b/announcer/sounds/peks/EnemyInhibitorRespawned/enemyinhibitorhasrespawned.mp3
new file mode 100644 (file)
index 0000000..be06933
Binary files /dev/null and b/announcer/sounds/peks/EnemyInhibitorRespawned/enemyinhibitorhasrespawned.mp3 differ
diff --git a/announcer/sounds/peks/EnemyInhibitorRespawningSoon/enemyinhibitorisrespawningsoon.mp3 b/announcer/sounds/peks/EnemyInhibitorRespawningSoon/enemyinhibitorisrespawningsoon.mp3
new file mode 100644 (file)
index 0000000..d343ed0
Binary files /dev/null and b/announcer/sounds/peks/EnemyInhibitorRespawningSoon/enemyinhibitorisrespawningsoon.mp3 differ
diff --git a/announcer/sounds/peks/EnemyPentaKill/enemypentakill.mp3 b/announcer/sounds/peks/EnemyPentaKill/enemypentakill.mp3
new file mode 100644 (file)
index 0000000..81260e0
Binary files /dev/null and b/announcer/sounds/peks/EnemyPentaKill/enemypentakill.mp3 differ
diff --git a/announcer/sounds/peks/EnemyQuadraKill/enemyquadrakill.mp3 b/announcer/sounds/peks/EnemyQuadraKill/enemyquadrakill.mp3
new file mode 100644 (file)
index 0000000..69fb6b4
Binary files /dev/null and b/announcer/sounds/peks/EnemyQuadraKill/enemyquadrakill.mp3 differ
diff --git a/announcer/sounds/peks/EnemyTripleKill/enemytriplekill.mp3 b/announcer/sounds/peks/EnemyTripleKill/enemytriplekill.mp3
new file mode 100644 (file)
index 0000000..f62f4ff
Binary files /dev/null and b/announcer/sounds/peks/EnemyTripleKill/enemytriplekill.mp3 differ
diff --git a/announcer/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed1.mp3 b/announcer/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed1.mp3
new file mode 100644 (file)
index 0000000..2e6849c
Binary files /dev/null and b/announcer/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed1.mp3 differ
diff --git a/announcer/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed2.mp3 b/announcer/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed2.mp3
new file mode 100644 (file)
index 0000000..cf6ffff
Binary files /dev/null and b/announcer/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed2.mp3 differ
diff --git a/announcer/sounds/peks/Executed/executed1.mp3 b/announcer/sounds/peks/Executed/executed1.mp3
new file mode 100644 (file)
index 0000000..a10c0b3
Binary files /dev/null and b/announcer/sounds/peks/Executed/executed1.mp3 differ
diff --git a/announcer/sounds/peks/Executed/executed2.mp3 b/announcer/sounds/peks/Executed/executed2.mp3
new file mode 100644 (file)
index 0000000..3194924
Binary files /dev/null and b/announcer/sounds/peks/Executed/executed2.mp3 differ
diff --git a/announcer/sounds/peks/Executed/executed3.mp3 b/announcer/sounds/peks/Executed/executed3.mp3
new file mode 100644 (file)
index 0000000..71d8327
Binary files /dev/null and b/announcer/sounds/peks/Executed/executed3.mp3 differ
diff --git a/announcer/sounds/peks/FirstBlood/firstblood.mp3 b/announcer/sounds/peks/FirstBlood/firstblood.mp3
new file mode 100644 (file)
index 0000000..ce8b872
Binary files /dev/null and b/announcer/sounds/peks/FirstBlood/firstblood.mp3 differ
diff --git a/announcer/sounds/peks/MinionsSpawning/minionshavespawned.mp3 b/announcer/sounds/peks/MinionsSpawning/minionshavespawned.mp3
new file mode 100644 (file)
index 0000000..c003749
Binary files /dev/null and b/announcer/sounds/peks/MinionsSpawning/minionshavespawned.mp3 differ
diff --git a/announcer/sounds/peks/MinionsSpawningSoon/30secondsuntilminionsspawn.mp3 b/announcer/sounds/peks/MinionsSpawningSoon/30secondsuntilminionsspawn.mp3
new file mode 100644 (file)
index 0000000..af05cd6
Binary files /dev/null and b/announcer/sounds/peks/MinionsSpawningSoon/30secondsuntilminionsspawn.mp3 differ
diff --git a/announcer/sounds/peks/PlayerDeath/youhavebeenslain1.mp3 b/announcer/sounds/peks/PlayerDeath/youhavebeenslain1.mp3
new file mode 100644 (file)
index 0000000..a830368
Binary files /dev/null and b/announcer/sounds/peks/PlayerDeath/youhavebeenslain1.mp3 differ
diff --git a/announcer/sounds/peks/PlayerDeath/youhavebeenslain2.mp3 b/announcer/sounds/peks/PlayerDeath/youhavebeenslain2.mp3
new file mode 100644 (file)
index 0000000..78cd20b
Binary files /dev/null and b/announcer/sounds/peks/PlayerDeath/youhavebeenslain2.mp3 differ
diff --git a/announcer/sounds/peks/PlayerKill/youhaveslainanenemy1.mp3 b/announcer/sounds/peks/PlayerKill/youhaveslainanenemy1.mp3
new file mode 100644 (file)
index 0000000..589b618
Binary files /dev/null and b/announcer/sounds/peks/PlayerKill/youhaveslainanenemy1.mp3 differ
diff --git a/announcer/sounds/peks/PlayerKill/youhaveslainanenemy2.mp3 b/announcer/sounds/peks/PlayerKill/youhaveslainanenemy2.mp3
new file mode 100644 (file)
index 0000000..57f0bd1
Binary files /dev/null and b/announcer/sounds/peks/PlayerKill/youhaveslainanenemy2.mp3 differ
diff --git a/announcer/sounds/peks/PlayerKill/youhaveslainanenemy3.mp3 b/announcer/sounds/peks/PlayerKill/youhaveslainanenemy3.mp3
new file mode 100644 (file)
index 0000000..f010fdd
Binary files /dev/null and b/announcer/sounds/peks/PlayerKill/youhaveslainanenemy3.mp3 differ
diff --git a/announcer/sounds/peks/Victory/victory.mp3 b/announcer/sounds/peks/Victory/victory.mp3
new file mode 100644 (file)
index 0000000..8f4dd82
Binary files /dev/null and b/announcer/sounds/peks/Victory/victory.mp3 differ
diff --git a/announcer/sounds/peks/Welcome/welcometosummonersrift.mp3 b/announcer/sounds/peks/Welcome/welcometosummonersrift.mp3
new file mode 100644 (file)
index 0000000..6f36a86
Binary files /dev/null and b/announcer/sounds/peks/Welcome/welcometosummonersrift.mp3 differ
diff --git a/announcer/window.py b/announcer/window.py
new file mode 100644 (file)
index 0000000..9db5be0
--- /dev/null
@@ -0,0 +1,108 @@
+import os
+import random
+import logging
+
+from .constants import SOUND_PACKS
+from .events import Event
+
+from PyQt5 import QtWidgets
+from PyQt5.QtCore import QObject, QThread, QUrl, Qt, pyqtSignal
+from PyQt5.QtMultimedia import QMediaPlayer, QMediaContent
+
+
+logger = logging.getLogger(__name__)
+
+
+class EventPlayer(QObject):
+    # finished = pyqtSignal()
+    progress = pyqtSignal(str)
+
+    def poll_league(self):
+        self.lol_events = Event()
+        while True:
+            events_in_string = ";".join(self.lol_events.event_polling())
+            self.progress.emit(events_in_string)
+        # self.finished.emit()
+
+
+class MainWindow(QtWidgets.QMainWindow):
+    def __init__(self):
+        super().__init__()
+        self.setWindowTitle("Peks Announcer")
+        self.setFixedSize(250, 150)
+
+        self.volume_slider = QtWidgets.QSlider(Qt.Horizontal)
+        self.mute_button = QtWidgets.QPushButton("Mute")
+        self.test_volume_button = QtWidgets.QPushButton("Test sound")
+        self.headerlabel = QtWidgets.QLabel("Hello World")
+        self.vollabel = QtWidgets.QLabel("Volume")
+        self.packlabel = QtWidgets.QLabel("Sound Pack:")
+        self.sound_pack = QtWidgets.QComboBox()
+        self.sound_pack.addItems(SOUND_PACKS)
+        self.central_widget = QtWidgets.QWidget()
+        self.setCentralWidget(self.central_widget)
+
+        self.layout = QtWidgets.QGridLayout(self.central_widget)
+        self.layout.addWidget(self.headerlabel, 0, 1)
+        self.layout.addWidget(self.vollabel, 1, 1)
+        self.layout.addWidget(self.volume_slider, 2, 1)
+        self.layout.addWidget(self.mute_button, 1, 0)
+        self.layout.addWidget(self.test_volume_button, 1, 2)
+        self.layout.addWidget(self.packlabel, 3, 0)
+        self.layout.addWidget(self.sound_pack, 3, 1)
+
+        self.media_player = QMediaPlayer()
+
+        self.event_player = EventPlayer()
+        self.event_player_thread = QThread()
+        self.event_player.moveToThread(self.event_player_thread)
+
+        self.event_player_thread.started.connect(self.event_player.poll_league)
+        # self.event_player.finished.connect(self.thread.quit)
+        # self.event_player.finished.connect(self.worker.deleteLater)
+        self.event_player_thread.finished.connect(self.event_player_thread.deleteLater)
+        self.event_player.progress.connect(self.play_events_sound)
+
+        self.event_player_thread.start()
+
+    def setup_connections(self):
+        self.volume_slider.valueChanged.connect(self.update_volume)
+        self.mute_button.clicked.connect(self.mute)
+        self.test_volume_button.clicked.connect(self.play_random_sound)
+
+    def mute(self):
+        pass
+
+    def update_volume(self):
+        pass
+
+    def play_random_sound(self):
+        sound_pack_dir = SOUND_PACKS[self.sound_pack.currentText()]
+        events = os.listdir(sound_pack_dir)
+        try:
+            event = random.choice(events)
+        except IndexError as e:
+            logger.exception(e)
+            return
+        self.play_event_sound(event)
+
+    def play_events_sound(self, events: str):
+        logger.debug(events)
+        for event in events.split(";"):
+            if not event:
+                break
+            self.play_event_sound(event)
+
+    def play_event_sound(self, event: str):
+        event_sounds = os.path.join(SOUND_PACKS[self.sound_pack.currentText()], event)
+        try:
+            sound = random.choice(os.listdir(event_sounds))
+        except IndexError as e:
+            logger.exception(e)
+            return
+        sound_path = os.path.join(event_sounds, sound)
+        logger.debug(sound_path)
+        url = QUrl.fromLocalFile(sound_path)
+        content = QMediaContent(url)
+        self.media_player.setMedia(content)
+        self.media_player.play()
index 9ad84a7bb672b64d9d745101952026299ea49d5d..919780dadcf51fe00bc782ed16bb8d2ccbd6c666 100644 (file)
@@ -1,8 +1,10 @@
+announcer==0.0.1
 audioplayer==0.6
 certifi==2022.12.7
 charset-normalizer==3.0.1
 idna==3.4
-pycairo==1.23.0
-PyGObject==3.42.2
+PyQt5==5.15.7
+PyQt5-Qt5==5.15.2
+PyQt5-sip==12.11.0
 requests==2.28.2
 urllib3==1.26.14
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..5c9a5bf
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,20 @@
+from setuptools import setup
+
+setup(
+    name="announcer",
+    version="0.0.1",
+    packages=["announcer"],
+    entry_points={
+        "console_scripts": [
+            "announcer=announcer.main:main",
+        ],
+    },
+    install_requires=[
+        "PyQT5",
+        "requests",
+        "audioplayer",
+    ],
+    package_data={
+        "announcer": ["sounds/**"],
+    }
+)
diff --git a/sounds/peks/AllyAce/allyace.mp3 b/sounds/peks/AllyAce/allyace.mp3
deleted file mode 100644 (file)
index 5554d9c..0000000
Binary files a/sounds/peks/AllyAce/allyace.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyDeath/anallyhasbeenslain1.mp3 b/sounds/peks/AllyDeath/anallyhasbeenslain1.mp3
deleted file mode 100644 (file)
index 81afb19..0000000
Binary files a/sounds/peks/AllyDeath/anallyhasbeenslain1.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyDeath/anallyhasbeenslain2.mp3 b/sounds/peks/AllyDeath/anallyhasbeenslain2.mp3
deleted file mode 100644 (file)
index 5f83b60..0000000
Binary files a/sounds/peks/AllyDeath/anallyhasbeenslain2.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyDoubleKill/doublekill1.mp3 b/sounds/peks/AllyDoubleKill/doublekill1.mp3
deleted file mode 100644 (file)
index 8394dbb..0000000
Binary files a/sounds/peks/AllyDoubleKill/doublekill1.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyDoubleKill/doublekill2.mp3 b/sounds/peks/AllyDoubleKill/doublekill2.mp3
deleted file mode 100644 (file)
index 4437f04..0000000
Binary files a/sounds/peks/AllyDoubleKill/doublekill2.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor1.mp3 b/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor1.mp3
deleted file mode 100644 (file)
index d66d59b..0000000
Binary files a/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor1.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor2.mp3 b/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor2.mp3
deleted file mode 100644 (file)
index 90c3ed9..0000000
Binary files a/sounds/peks/AllyInhibitorKill/yourteamhasdestroyedaninhibitor2.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyInhibitorRespawned/yourinhibitorhasrespawned.mp3 b/sounds/peks/AllyInhibitorRespawned/yourinhibitorhasrespawned.mp3
deleted file mode 100644 (file)
index 52bb78e..0000000
Binary files a/sounds/peks/AllyInhibitorRespawned/yourinhibitorhasrespawned.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyInhibitorRespawningSoon/yourinhibitorisrespawningsoon.mp3 b/sounds/peks/AllyInhibitorRespawningSoon/yourinhibitorisrespawningsoon.mp3
deleted file mode 100644 (file)
index 6bbc671..0000000
Binary files a/sounds/peks/AllyInhibitorRespawningSoon/yourinhibitorisrespawningsoon.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyKill/anenemyhasbeenslain1.mp3 b/sounds/peks/AllyKill/anenemyhasbeenslain1.mp3
deleted file mode 100644 (file)
index b723516..0000000
Binary files a/sounds/peks/AllyKill/anenemyhasbeenslain1.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyKill/anenemyhasbeenslain2.mp3 b/sounds/peks/AllyKill/anenemyhasbeenslain2.mp3
deleted file mode 100644 (file)
index 28e4f82..0000000
Binary files a/sounds/peks/AllyKill/anenemyhasbeenslain2.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyKill/anenemyhasbeenslain3.mp3 b/sounds/peks/AllyKill/anenemyhasbeenslain3.mp3
deleted file mode 100644 (file)
index 6ff29c5..0000000
Binary files a/sounds/peks/AllyKill/anenemyhasbeenslain3.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyPentaKill/pentakill1.mp3 b/sounds/peks/AllyPentaKill/pentakill1.mp3
deleted file mode 100644 (file)
index 1dbcf6a..0000000
Binary files a/sounds/peks/AllyPentaKill/pentakill1.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyPentaKill/pentakill2.mp3 b/sounds/peks/AllyPentaKill/pentakill2.mp3
deleted file mode 100644 (file)
index c0e2535..0000000
Binary files a/sounds/peks/AllyPentaKill/pentakill2.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyQuadraKill/quadrakill.mp3 b/sounds/peks/AllyQuadraKill/quadrakill.mp3
deleted file mode 100644 (file)
index 49e7cd5..0000000
Binary files a/sounds/peks/AllyQuadraKill/quadrakill.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyTripleKill/triplekill.mp3 b/sounds/peks/AllyTripleKill/triplekill.mp3
deleted file mode 100644 (file)
index 9113f7c..0000000
Binary files a/sounds/peks/AllyTripleKill/triplekill.mp3 and /dev/null differ
diff --git a/sounds/peks/AllyTurretKill/yourteamhasdestroyedaturret.mp3 b/sounds/peks/AllyTurretKill/yourteamhasdestroyedaturret.mp3
deleted file mode 100644 (file)
index 9f18350..0000000
Binary files a/sounds/peks/AllyTurretKill/yourteamhasdestroyedaturret.mp3 and /dev/null differ
diff --git a/sounds/peks/Defeat/defeat.mp3 b/sounds/peks/Defeat/defeat.mp3
deleted file mode 100644 (file)
index f46cbad..0000000
Binary files a/sounds/peks/Defeat/defeat.mp3 and /dev/null differ
diff --git a/sounds/peks/EnemyAce/enemyace.mp3 b/sounds/peks/EnemyAce/enemyace.mp3
deleted file mode 100644 (file)
index b9d5dff..0000000
Binary files a/sounds/peks/EnemyAce/enemyace.mp3 and /dev/null differ
diff --git a/sounds/peks/EnemyDoubleKill/enemydoublekill.mp3 b/sounds/peks/EnemyDoubleKill/enemydoublekill.mp3
deleted file mode 100644 (file)
index 2476788..0000000
Binary files a/sounds/peks/EnemyDoubleKill/enemydoublekill.mp3 and /dev/null differ
diff --git a/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed1.mp3 b/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed1.mp3
deleted file mode 100644 (file)
index 35d81bf..0000000
Binary files a/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed1.mp3 and /dev/null differ
diff --git a/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed2.mp3 b/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed2.mp3
deleted file mode 100644 (file)
index 7f337b1..0000000
Binary files a/sounds/peks/EnemyInhibitorKill/yourinhibitorhasbeendestroyed2.mp3 and /dev/null differ
diff --git a/sounds/peks/EnemyInhibitorRespawned/enemyinhibitorhasrespawned.mp3 b/sounds/peks/EnemyInhibitorRespawned/enemyinhibitorhasrespawned.mp3
deleted file mode 100644 (file)
index be06933..0000000
Binary files a/sounds/peks/EnemyInhibitorRespawned/enemyinhibitorhasrespawned.mp3 and /dev/null differ
diff --git a/sounds/peks/EnemyInhibitorRespawningSoon/enemyinhibitorisrespawningsoon.mp3 b/sounds/peks/EnemyInhibitorRespawningSoon/enemyinhibitorisrespawningsoon.mp3
deleted file mode 100644 (file)
index d343ed0..0000000
Binary files a/sounds/peks/EnemyInhibitorRespawningSoon/enemyinhibitorisrespawningsoon.mp3 and /dev/null differ
diff --git a/sounds/peks/EnemyPentaKill/enemypentakill.mp3 b/sounds/peks/EnemyPentaKill/enemypentakill.mp3
deleted file mode 100644 (file)
index 81260e0..0000000
Binary files a/sounds/peks/EnemyPentaKill/enemypentakill.mp3 and /dev/null differ
diff --git a/sounds/peks/EnemyQuadraKill/enemyquadrakill.mp3 b/sounds/peks/EnemyQuadraKill/enemyquadrakill.mp3
deleted file mode 100644 (file)
index 69fb6b4..0000000
Binary files a/sounds/peks/EnemyQuadraKill/enemyquadrakill.mp3 and /dev/null differ
diff --git a/sounds/peks/EnemyTripleKill/enemytriplekill.mp3 b/sounds/peks/EnemyTripleKill/enemytriplekill.mp3
deleted file mode 100644 (file)
index f62f4ff..0000000
Binary files a/sounds/peks/EnemyTripleKill/enemytriplekill.mp3 and /dev/null differ
diff --git a/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed1.mp3 b/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed1.mp3
deleted file mode 100644 (file)
index 2e6849c..0000000
Binary files a/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed1.mp3 and /dev/null differ
diff --git a/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed2.mp3 b/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed2.mp3
deleted file mode 100644 (file)
index cf6ffff..0000000
Binary files a/sounds/peks/EnemyTurretKill/yourturrethasbeendestroyed2.mp3 and /dev/null differ
diff --git a/sounds/peks/Executed/executed1.mp3 b/sounds/peks/Executed/executed1.mp3
deleted file mode 100644 (file)
index a10c0b3..0000000
Binary files a/sounds/peks/Executed/executed1.mp3 and /dev/null differ
diff --git a/sounds/peks/Executed/executed2.mp3 b/sounds/peks/Executed/executed2.mp3
deleted file mode 100644 (file)
index 3194924..0000000
Binary files a/sounds/peks/Executed/executed2.mp3 and /dev/null differ
diff --git a/sounds/peks/Executed/executed3.mp3 b/sounds/peks/Executed/executed3.mp3
deleted file mode 100644 (file)
index 71d8327..0000000
Binary files a/sounds/peks/Executed/executed3.mp3 and /dev/null differ
diff --git a/sounds/peks/FirstBlood/firstblood.mp3 b/sounds/peks/FirstBlood/firstblood.mp3
deleted file mode 100644 (file)
index ce8b872..0000000
Binary files a/sounds/peks/FirstBlood/firstblood.mp3 and /dev/null differ
diff --git a/sounds/peks/MinionsSpawning/minionshavespawned.mp3 b/sounds/peks/MinionsSpawning/minionshavespawned.mp3
deleted file mode 100644 (file)
index c003749..0000000
Binary files a/sounds/peks/MinionsSpawning/minionshavespawned.mp3 and /dev/null differ
diff --git a/sounds/peks/MinionsSpawningSoon/30secondsuntilminionsspawn.mp3 b/sounds/peks/MinionsSpawningSoon/30secondsuntilminionsspawn.mp3
deleted file mode 100644 (file)
index af05cd6..0000000
Binary files a/sounds/peks/MinionsSpawningSoon/30secondsuntilminionsspawn.mp3 and /dev/null differ
diff --git a/sounds/peks/PlayerDeath/youhavebeenslain1.mp3 b/sounds/peks/PlayerDeath/youhavebeenslain1.mp3
deleted file mode 100644 (file)
index a830368..0000000
Binary files a/sounds/peks/PlayerDeath/youhavebeenslain1.mp3 and /dev/null differ
diff --git a/sounds/peks/PlayerDeath/youhavebeenslain2.mp3 b/sounds/peks/PlayerDeath/youhavebeenslain2.mp3
deleted file mode 100644 (file)
index 78cd20b..0000000
Binary files a/sounds/peks/PlayerDeath/youhavebeenslain2.mp3 and /dev/null differ
diff --git a/sounds/peks/PlayerKill/youhaveslainanenemy1.mp3 b/sounds/peks/PlayerKill/youhaveslainanenemy1.mp3
deleted file mode 100644 (file)
index 589b618..0000000
Binary files a/sounds/peks/PlayerKill/youhaveslainanenemy1.mp3 and /dev/null differ
diff --git a/sounds/peks/PlayerKill/youhaveslainanenemy2.mp3 b/sounds/peks/PlayerKill/youhaveslainanenemy2.mp3
deleted file mode 100644 (file)
index 57f0bd1..0000000
Binary files a/sounds/peks/PlayerKill/youhaveslainanenemy2.mp3 and /dev/null differ
diff --git a/sounds/peks/PlayerKill/youhaveslainanenemy3.mp3 b/sounds/peks/PlayerKill/youhaveslainanenemy3.mp3
deleted file mode 100644 (file)
index f010fdd..0000000
Binary files a/sounds/peks/PlayerKill/youhaveslainanenemy3.mp3 and /dev/null differ
diff --git a/sounds/peks/Victory/victory.mp3 b/sounds/peks/Victory/victory.mp3
deleted file mode 100644 (file)
index 8f4dd82..0000000
Binary files a/sounds/peks/Victory/victory.mp3 and /dev/null differ
diff --git a/sounds/peks/Welcome/welcometosummonersrift.mp3 b/sounds/peks/Welcome/welcometosummonersrift.mp3
deleted file mode 100644 (file)
index 6f36a86..0000000
Binary files a/sounds/peks/Welcome/welcometosummonersrift.mp3 and /dev/null differ