Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions omnibot/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,13 @@ def _process_reaction_message_handlers(reaction: Reaction):
handler_called = False
item_channel = reaction.item_channel
item_ts = reaction.item_ts
item_user = reaction.item_user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we differentiating reaction user too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the user who made the reaction is set in BaseMessage using user field


if not _is_message_from_bot(bot, item_channel, item_ts):
if item_user is not None:
if item_user != bot.user_id:
statsd.incr("event.ignored")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we get called with irrelevant events?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, an event is sent for every bot that is in the channel.

return
elif not _is_message_from_bot(bot, item_channel, item_ts): # Fallback check
statsd.incr("event.ignored")
return

Expand Down Expand Up @@ -179,8 +184,11 @@ def _is_message_from_bot(bot: Bot, channel: str, ts: str):
Some events, like reactions, do not have all the ids we need to determine who wrote the message.
"""
message = get_message(bot, channel, ts)
if not message or "bot_id" not in message:
logger.warning("Failed to retrieve valid message or 'bot_id' is missing")
if not message:
logger.warning("Failed to retrieve valid message")
return False
elif "bot_id" not in message:
logger.debug("Message is not from a bot")
return False
# There can be multiple bot_ids for the same bot
bot_info = get_bot_info(bot, message["bot_id"])
Expand Down
13 changes: 11 additions & 2 deletions omnibot/services/slack/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, bot: Bot, event: dict, event_trace: dict):
self._payload["emoji_name"] = event["reaction"]
except Exception:
logger.error(
"Reaction event is missing reaction attribute.",
"Reaction event is missing reaction attribute",
extra=self.event_trace,
)
raise
Expand All @@ -31,10 +31,11 @@ def __init__(self, bot: Bot, event: dict, event_trace: dict):
self._payload["item_ts"] = event["item"]["ts"]
except Exception:
logger.error(
"Reaction event is missing a item attribute.",
"Reaction event is missing item attribute",
extra=self.event_trace,
)
raise
self._payload["item_user"] = event.get("item_user")
self._payload["channel_id"] = self.item_channel

def _check_unsupported(self):
Expand Down Expand Up @@ -75,6 +76,14 @@ def item_ts(self):
"""
return self._payload["item_ts"]

@property
def item_user(self):
"""
The user who created the item (e.g. "message", "file", etc.) that was reacted to.
This is not always present, such as in reaction events to slack command responses.
"""
return self._payload["item_user"]

@property
def emoji_name(self):
"""
Expand Down