diff --git a/slack_util.py b/slack_util.py index c5deb76..2eb0664 100644 --- a/slack_util.py +++ b/slack_util.py @@ -69,6 +69,7 @@ class Event: message: Optional[MessageContext] = None thread: Optional[ThreadContext] = None interaction: Optional[InteractiveContext] = None + bot: Optional[BotContext] = None # If this was posted in a specific channel or conversation @@ -89,6 +90,12 @@ class UserContext: return get_slack().get_user(self.user_id) +# Same but for bots +@dataclass +class BotContext: + bot_id: str + + # Whether or not this is a threadable text message @dataclass class MessageContext: @@ -168,6 +175,8 @@ def message_dict_to_event(update: dict) -> Event: event.conversation = ConversationContext(update["channel"]) if "user" in update: event.user = UserContext(update["user"]) + if "bot_id" in update: + event.bot = BotContext(update["bot_id"]) if "thread_ts" in update: event.thread = ThreadContext(update["thread_ts"]) diff --git a/slavestothemachine.py b/slavestothemachine.py index fcfc5b6..a3b813b 100644 --- a/slavestothemachine.py +++ b/slavestothemachine.py @@ -16,6 +16,10 @@ def fmt_work_dict(work_dict: dict) -> str: # noinspection PyUnusedLocal async def count_work_callback(event: slack_util.Event, match: Match) -> None: + # If no user, continue + if event.user is None: + return + # Make an error wrapper verb = slack_util.VerboseWrapper(event)