Finish function-specific blocking

Added ability to block events per-function for added customization
pull/1/head
Mason10198 3 years ago
parent eb80a7ea43
commit 03db1bb015

1
.gitignore vendored

@ -4,6 +4,7 @@
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# User-specific files # User-specific files
template.ini
*.rsuser *.rsuser
*.suo *.suo
*.user *.user

@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}

@ -57,7 +57,9 @@ if not os.path.exists(tmp_dir):
# List of blocked events # List of blocked events
global_blocked_events = config["Blocking"].get("GlobalBlockedEvents").split(",") global_blocked_events = config["Blocking"].get("GlobalBlockedEvents").split(",")
sayalert_blocked_events = config["Blocking"].get("SayAlertBlockedEvents").split(",") sayalert_blocked_events = config["Blocking"].get("SayAlertBlockedEvents").split(",")
tailmessage_blocked_events = config["Blocking"].get("TailmessageBlockedEvents").split(",") tailmessage_blocked_events = (
config["Blocking"].get("TailmessageBlockedEvents").split(",")
)
# Configuration for tailmessage # Configuration for tailmessage
tailmessage_config = config["Tailmessage"] tailmessage_config = config["Tailmessage"]
# Flag to enable/disable tailmessage # Flag to enable/disable tailmessage
@ -255,6 +257,8 @@ logger.debug("Temporary directory: {}".format(tmp_dir))
logger.debug("Sounds path: {}".format(sounds_path)) logger.debug("Sounds path: {}".format(sounds_path))
logger.debug("Tailmessage path: {}".format(tailmessage_file)) logger.debug("Tailmessage path: {}".format(tailmessage_file))
logger.debug("Global Blocked events: {}".format(global_blocked_events)) logger.debug("Global Blocked events: {}".format(global_blocked_events))
logger.debug("SayAlert Blocked events: {}".format(sayalert_blocked_events))
logger.debug("Tailmessage Blocked events: {}".format(tailmessage_blocked_events))
def getAlerts(countyCodes): def getAlerts(countyCodes):
@ -297,7 +301,9 @@ def getAlerts(countyCodes):
for global_blocked_event in global_blocked_events: for global_blocked_event in global_blocked_events:
if fnmatch.fnmatch(event, global_blocked_event): if fnmatch.fnmatch(event, global_blocked_event):
logger.debug( logger.debug(
"Globally Blocking {} as per configuration".format(event) "Globally Blocking {} as per configuration".format(
event
)
) )
break break
else: else:
@ -330,10 +336,12 @@ def sayAlert(alerts):
os.path.join(sounds_path, "ALERTS", "SWP95.wav") os.path.join(sounds_path, "ALERTS", "SWP95.wav")
) )
alert_count = 0 # Counter for alerts added to combined_sound
for alert in alerts: for alert in alerts:
# Check if alert is in the SayAlertBlockedEvents list # Check if alert is in the SayAlertBlockedEvents list
if alert in sayalert_blocked_events: if alert in sayalert_blocked_events:
logger.debug("Alert blocked by SayAlertBlockedEvents: {}".format(alert)) logger.debug("SayAlert blocking {} as per configuration".format(alert))
continue continue
try: try:
@ -343,6 +351,7 @@ def sayAlert(alerts):
) )
combined_sound += sound_effect + audio_file combined_sound += sound_effect + audio_file
logger.debug("Added {} (SWP{}.wav) to alert sound".format(alert, WA[index])) logger.debug("Added {} (SWP{}.wav) to alert sound".format(alert, WA[index]))
alert_count += 1 # Increment the counter
except ValueError: except ValueError:
logger.error("Alert not found: {}".format(alert)) logger.error("Alert not found: {}".format(alert))
except FileNotFoundError: except FileNotFoundError:
@ -352,6 +361,9 @@ def sayAlert(alerts):
) )
) )
if alert_count == 0: # Check the counter instead of combined_sound.empty()
logger.debug("SayAlert: All alerts were blocked, not broadcasting any alerts.")
else:
logger.debug("Exporting alert sound to {}".format(alert_file)) logger.debug("Exporting alert sound to {}".format(alert_file))
converted_combined_sound = convert_audio(combined_sound) converted_combined_sound = convert_audio(combined_sound)
converted_combined_sound.export(alert_file, format="wav") converted_combined_sound.export(alert_file, format="wav")
@ -408,6 +420,11 @@ def buildTailmessage(alerts):
os.path.join(sounds_path, "ALERTS", "SWP95.wav") os.path.join(sounds_path, "ALERTS", "SWP95.wav")
) )
for alert in alerts: for alert in alerts:
# Check if alert is in the TailmessageBlockedEvents list
if alert in tailmessage_blocked_events:
logger.debug("Alert blocked by TailmessageBlockedEvents: {}".format(alert))
continue
try: try:
index = WS.index(alert) index = WS.index(alert)
audio_file = AudioSegment.from_wav( audio_file = AudioSegment.from_wav(
@ -423,6 +440,11 @@ def buildTailmessage(alerts):
sounds_path, WA[index] sounds_path, WA[index]
) )
) )
if combined_sound.empty():
logger.debug(
"BuildTailmessage: All alerts were blocked, creating silent tailmessage"
)
combined_sound = AudioSegment.silent(duration=100)
logger.debug("Exporting tailmessage to {}".format(tailmessage_file)) logger.debug("Exporting tailmessage to {}".format(tailmessage_file))
converted_combined_sound = convert_audio(combined_sound) converted_combined_sound = convert_audio(combined_sound)
converted_combined_sound.export(tailmessage_file, format="wav") converted_combined_sound.export(tailmessage_file, format="wav")

Loading…
Cancel
Save

Powered by TurnKey Linux.