Skip to content

Commit

Permalink
Slack: Fix SLACK_CUSTOM_AVAILABLE_STATUS default.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
PortableProgrammer committed Jun 30, 2023
1 parent 78f53f3 commit e45a521
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions status-light/sources/collaboration/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion status-light/utility/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit e45a521

Please sign in to comment.