diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index bf346d9..681b91b 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -5,10 +5,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v1 - - name: Setup python 3.8 + - name: Setup python 3.10.17 uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.10.17 - name: Install pre-commit run: pip install pre-commit - name: Run pre-commit @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.x'] + python-version: ['3.10.17'] steps: - name: Checkout uses: actions/checkout@v1 diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index dea2c34..d054fdc 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -12,10 +12,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v1 - - name: Setup python 3.8 + - name: Setup python 3.10.17 uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.10.17 - name: Install virtualenv run: pip install virtualenv - name: Build docs @@ -35,10 +35,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v1 - - name: Setup python 3.8 + - name: Setup python 3.10.17 uses: actions/setup-python@v1 with: - python-version: 3.8 + python-version: 3.10.17 - name: Add wheel dependency run: pip install wheel - name: Generate dist diff --git a/omnibot_receiver/router.py b/omnibot_receiver/router.py index e98a51c..76794e6 100644 --- a/omnibot_receiver/router.py +++ b/omnibot_receiver/router.py @@ -85,7 +85,8 @@ def handle_event(self, event): ]} """ omnibot_payload_type = event.get('omnibot_payload_type') - if self.message_router and omnibot_payload_type == 'message': + if (self.message_router and + omnibot_payload_type in {'message', 'reaction'}): return self.message_router.handle_message(event) elif (self.interactive_router and omnibot_payload_type == 'interactive_component'): @@ -258,7 +259,8 @@ def __init__(self, help='', help_as_default=True): self.default_route = None self.routes = { 'command': [], - 'regex': [] + 'regex': [], + 'reaction': [], } @staticmethod @@ -321,9 +323,11 @@ def add_message_rule(self, rule, match_type, route_func, help=''): match_type (str): The type of message this route should match against:: - command -- Match against messages directed at this bot. - regex -- Match against messages in a channel that have - been targetted at this bot by omnibot. + command -- Match against messages directed at this bot. + regex -- Match against messages in a channel that have + been targeted at this bot by omnibot. + reaction -- Match against reactions towards items + made by this bot. route_func (function): The function to call when serving this route **kwargs (dict): Keyword arguments (see below for more info) diff --git a/tests/unit/omnibot_receiver/router_test.py b/tests/unit/omnibot_receiver/router_test.py index dd9a53e..708b211 100644 --- a/tests/unit/omnibot_receiver/router_test.py +++ b/tests/unit/omnibot_receiver/router_test.py @@ -244,6 +244,16 @@ def a_to_b(message, a, b): assert message_router.handle_message(message1) == 'a is 1, b is 2' assert message_router.handle_message(message2) == 'a is 1, b is 2 to 3' + def test_reaction_route(self): + message = {'args': '+1', 'match_type': 'reaction'} + message_router = OmnibotMessageRouter() + + @message_router.route(r'\+1', match_type='reaction') + def ping(message): + return 'pong' + + assert message_router.handle_message(message) == 'pong' + class TestOmnibotInteractiveRouter(object):