Now detects bots

This commit is contained in:
Jacob Henry 2019-03-02 22:25:30 -05:00
parent 3c01e1782a
commit d75d72b6d5
2 changed files with 13 additions and 0 deletions

View File

@ -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"])

View File

@ -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)