Use backreferences in variables
Building on the nitter sample, it would be pretty neat if we could do this:
templates:
issue:
type: m.room.message
content:
msgtype: m.text
body: ${{URL}}
default_flags:
- ignorecase
rules:
github:
matches:
- \#(\d+)
template: issue
variables:
URL: https://github.com/my/project/issue/${{1}}
jira:
matches:
- [^#](\d+)
template: issue
variables:
URL: https://jira.atlassian.com/browse/ABC-${{1}}
Rule variables are meant to be static. Just rename the rule variable to url_prefix and move the reference from the variable to the template. You could even have the variable itself be a primitive template which is evaluated inside the template (you can have jinja2 in template variables or as the template content, e.g. https://github.com/maubot/reactbot/blob/master/samples/random-reaction.yaml#L6)
Just rename the rule variable to url_prefix
right, that works for the given case. my example does not cover this, but as you have more complex cases (e.g. URLs aren't just prefixes anymore) or are made up of multiple parts, I'm back to code/yaml duplication, no?