From a15e13ae5f8eea6975780315922042eacb018bd7 Mon Sep 17 00:00:00 2001 From: bg Date: Thu, 25 Jan 2024 07:10:15 +0000 Subject: [PATCH 1/3] Don't terminate after first match --- reactbot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reactbot/bot.py b/reactbot/bot.py index a31fa31..1016312 100644 --- a/reactbot/bot.py +++ b/reactbot/bot.py @@ -106,4 +106,4 @@ async def event_handler(self, evt: MessageEvent) -> None: await rule.execute(evt, match) except Exception: self.log.exception(f"Failed to execute {name} in {evt.room_id}") - return + From 2e5d9424b91835912b292be96f0d9feece36c1dd Mon Sep 17 00:00:00 2001 From: bg Date: Thu, 25 Jan 2024 07:46:54 +0000 Subject: [PATCH 2/3] Add rule option `continue_after_match` (defaults to `True`) --- reactbot/bot.py | 3 ++- reactbot/config.py | 1 + reactbot/rule.py | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/reactbot/bot.py b/reactbot/bot.py index 1016312..6281e4f 100644 --- a/reactbot/bot.py +++ b/reactbot/bot.py @@ -106,4 +106,5 @@ async def event_handler(self, evt: MessageEvent) -> None: await rule.execute(evt, match) except Exception: self.log.exception(f"Failed to execute {name} in {evt.room_id}") - + if not rule.continue_after_match: + return diff --git a/reactbot/config.py b/reactbot/config.py index b264a6b..a8b11bb 100644 --- a/reactbot/config.py +++ b/reactbot/config.py @@ -64,6 +64,7 @@ def _make_rule(self, name: str, rule: Dict[str, Any]) -> Rule: type=EventType.find(rule["type"]) if "type" in rule else None, template=self.templates[rule["template"]], variables=self._parse_variables(rule), + continue_after_match=rule.get("continue_after_match", True), ) except Exception as e: raise ConfigError(f"Failed to load {name}") from e diff --git a/reactbot/rule.py b/reactbot/rule.py index 07e714d..cff295a 100644 --- a/reactbot/rule.py +++ b/reactbot/rule.py @@ -35,6 +35,7 @@ class Rule: template: Template type: Optional[EventType] variables: Dict[str, Any] + continue_after_match: bool def _check_not_match(self, body: str) -> bool: for pattern in self.not_matches: From 8180815b38fa09fb8cd778551305bd68c7dd5500 Mon Sep 17 00:00:00 2001 From: bg Date: Thu, 25 Jan 2024 07:55:51 +0000 Subject: [PATCH 3/3] Add example to illustrate the `continue_after_match` feature. --- samples/your-opinion.yaml | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 samples/your-opinion.yaml diff --git a/samples/your-opinion.yaml b/samples/your-opinion.yaml new file mode 100644 index 0000000..c9ed543 --- /dev/null +++ b/samples/your-opinion.yaml @@ -0,0 +1,44 @@ +templates: + reaction: + type: m.reaction + variables: + react_to_event: '{{event.content.get_reply_to() or event.event_id}}' + content: + m.relates_to: + rel_type: m.annotation + event_id: $${react_to_event} + key: $${reaction} + + +default_flags: +- ignorecase +antispam: + room: + max: 60 + delay: 60 + user: + max: 60 + delay: 60 + +rules: + opinon_up: + raw: false + matches: '#youropinion\b(?!`)' + template: reaction + continue_after_match: true + variables: + reaction: 👍 + opinion_down: + raw: false + matches: '#youropinion\b(?!`)' + template: reaction + continue_after_match: true + variables: + reaction: 👎 + opinon_shrug: + raw: false + matches: '#youropinion\b(?!`)' + template: reaction + variables: + reaction: 🤷 +