Add option to exclude specific rooms from a rule
This commit is contained in:
parent
50141c8a92
commit
217351d141
2 changed files with 4 additions and 0 deletions
|
@ -53,6 +53,7 @@ class Config(BaseProxyConfig):
|
|||
def _make_rule(self, name: str, rule: Dict[str, Any]) -> Rule:
|
||||
try:
|
||||
return Rule(rooms=set(rule.get("rooms", [])),
|
||||
not_rooms=set(rule.get("not_rooms", [])),
|
||||
matches=self._compile_all(rule["matches"]),
|
||||
not_matches=self._compile_all(rule.get("not_matches", [])),
|
||||
type=EventType.find(rule["type"]) if "type" in rule else None,
|
||||
|
|
|
@ -31,6 +31,7 @@ RPattern = Union[Pattern, SimplePattern]
|
|||
@dataclass
|
||||
class Rule:
|
||||
rooms: Set[RoomID]
|
||||
not_rooms: Set[RoomID]
|
||||
matches: List[RPattern]
|
||||
not_matches: List[RPattern]
|
||||
template: Template
|
||||
|
@ -46,6 +47,8 @@ class Rule:
|
|||
def match(self, evt: MessageEvent) -> Optional[Match]:
|
||||
if len(self.rooms) > 0 and evt.room_id not in self.rooms:
|
||||
return None
|
||||
elif evt.room_id in self.not_rooms:
|
||||
return None
|
||||
for pattern in self.matches:
|
||||
match = pattern.search(evt.content.body)
|
||||
if match:
|
||||
|
|
Loading…
Reference in a new issue