From e45a521c20e01158941d773e2076c958967f43a7 Mon Sep 17 00:00:00 2001 From: PortableProgrammer Date: Fri, 30 Jun 2023 12:43:37 -0600 Subject: [PATCH] Slack: Fix `SLACK_CUSTOM_AVAILABLE_STATUS` default. - Default value was a single-element array with an empty string rather than an empty array. - This caused _all_ custom statuses to fall into the `Active` status. Add better debug logging for custom statuses. --- status-light/sources/collaboration/slack.py | 26 ++++++++++++++------- status-light/utility/env.py | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/status-light/sources/collaboration/slack.py b/status-light/sources/collaboration/slack.py index 084e7eb..a2136f8 100755 --- a/status-light/sources/collaboration/slack.py +++ b/status-light/sources/collaboration/slack.py @@ -55,7 +55,7 @@ def get_user_presence(self) -> enum.Status: 'Slack Exception while getting user presence: %s', ex.response['error']) logger.exception(ex) return_value = enum.Status.UNKNOWN - except Exception as ex: # pylint: disable=broad-except + except Exception as ex: # pylint: disable=broad-except logger.warning( 'Exception while getting Slack user presence: %s', ex) logger.exception(ex) @@ -80,7 +80,7 @@ def _get_user_info(self, client: WebClient) -> dict | None: 'Slack Exception while getting user info: %s', ex.response['error']) logger.exception(ex) return None - except Exception as ex: # pylint: disable=broad-except + except Exception as ex: # pylint: disable=broad-except logger.warning('Exception while getting Slack user info: %s', ex) logger.exception(ex) return None @@ -103,25 +103,35 @@ def _parse_custom_status(self, client: WebClient, # For each of the Slack custom statuses, check them in reverse precedence order # Off, Available, Scheduled, Busy - if self.custom_off_status and custom_status.startswith(tuple(self.custom_off_status)): + if len(self.custom_off_status) > 0 and \ + custom_status.startswith(tuple(self.custom_off_status)): + logger.debug( + 'Custom status matched custom_off_status: %s', custom_status) return_value = self.custom_off_status_map - if self.custom_available_status and \ + if len(self.custom_available_status) > 0 and \ custom_status.startswith(tuple(self.custom_available_status)): + logger.debug( + 'Custom status matched custom_available_status: %s', custom_status) return_value = self.custom_available_status_map - if self.custom_scheduled_status and \ + if len(self.custom_scheduled_status) > 0 and \ custom_status.startswith(tuple(self.custom_scheduled_status)): + logger.debug( + 'Custom status matched custom_scheduled_status: %s', custom_status) return_value = self.custom_scheduled_status_map - if self.custom_busy_status and \ + if len(self.custom_busy_status) > 0 and \ custom_status.startswith(tuple(self.custom_busy_status)): + logger.debug( + 'Custom status matched custom_busy_status: %s', custom_status) return_value = self.custom_busy_status_map # Check for Huddle and Call if user_info['profile']['huddle_state'] == 'in_a_huddle' or \ user_info['profile']['status_emoji'] == ':slack_call:': - + logger.debug('Custom status indicates Huddle (%s) or Call (%s)', + user_info['profile']['huddle_state'], custom_status) return_value = enum.Status.CALL except (SystemExit, KeyboardInterrupt): @@ -131,7 +141,7 @@ def _parse_custom_status(self, client: WebClient, 'Slack Exception while parsing custom status: %s', ex.response['error']) logger.exception(ex) return_value = enum.Status.UNKNOWN - except Exception as ex: # pylint: disable=broad-except + except Exception as ex: # pylint: disable=broad-except logger.warning( 'Exception while parsing Slack custom status: %s', ex) logger.exception(ex) diff --git a/status-light/utility/env.py b/status-light/utility/env.py index 0f06af8..4492af5 100755 --- a/status-light/utility/env.py +++ b/status-light/utility/env.py @@ -37,7 +37,7 @@ class Environment: # 66 - Add Slack custom status support slack_off_status: list[str] = [ ':no_entry: Out of Office', ':airplane:', ':palm_tree: Vacationing'] - slack_available_status: list[str] = [''] + slack_available_status: list[str] = [] slack_scheduled_status: list[str] = [':spiral_calendar_pad: In a meeting'] slack_busy_status: list[str] = [ ':no_entry_sign:', ':no_entry: Do not Disturb']