Skip to content
Open
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
3 changes: 2 additions & 1 deletion reactbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
return
if not rule.continue_after_match:
return
1 change: 1 addition & 0 deletions reactbot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions reactbot/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
44 changes: 44 additions & 0 deletions samples/your-opinion.yaml
Original file line number Diff line number Diff line change
@@ -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: 🤷