Merge pull request 'fix: explicit m.mentions for ticket notifications and roasts (ahead of Synapse 1.164)' (#42) from fix/explicit-mentions into main
Lint / JS (eslint) (push) Successful in 10s
Lint / Shell (shellcheck) (push) Successful in 10s
Lint / Landing page is rendered (matrix (push) Successful in 5s
Lint / No secrets in webhook configs (push) Successful in 5s
Lint / Python (ruff) (push) Successful in 8s
Lint / Secret scan (gitleaks) (push) Successful in 6s
Lint / Python deps (pip-audit) (push) Successful in 42s
Lint / JS (eslint) (push) Successful in 10s
Lint / Shell (shellcheck) (push) Successful in 10s
Lint / Landing page is rendered (matrix (push) Successful in 5s
Lint / No secrets in webhook configs (push) Successful in 5s
Lint / Python (ruff) (push) Successful in 8s
Lint / Secret scan (gitleaks) (push) Successful in 6s
Lint / Python deps (pip-audit) (push) Successful in 42s
This commit was merged in pull request #42.
This commit is contained in:
@@ -77,4 +77,13 @@ if (event === 'ticket_created') {
|
|||||||
html = '[tinker-tickets] event: <code>' + event + '</code> ticket #' + id;
|
html = '[tinker-tickets] event: <code>' + event + '</code> ticket #' + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = { version: 'v2', plain: plain, html: html, msgtype: 'm.text' };
|
// Explicit mentions (m.mentions): from Synapse 1.164 the legacy push rules
|
||||||
|
// that pinged on a user ID or display name in the body are off by default
|
||||||
|
// (MSC4210), so the people to notify must be listed here.
|
||||||
|
result = {
|
||||||
|
version: 'v2',
|
||||||
|
plain: plain,
|
||||||
|
html: html,
|
||||||
|
msgtype: 'm.text',
|
||||||
|
mentions: { user_ids: notifyUsers }
|
||||||
|
};
|
||||||
|
|||||||
@@ -2273,7 +2273,9 @@ async def cmd_roast(client: AsyncClient, room_id: str, sender: str, args: str):
|
|||||||
f'<blockquote>{roast}</blockquote>'
|
f'<blockquote>{roast}</blockquote>'
|
||||||
f'<sup><em>via {_model_label(CREATIVE_MODEL)}</em></sup>'
|
f'<sup><em>via {_model_label(CREATIVE_MODEL)}</em></sup>'
|
||||||
)
|
)
|
||||||
await send_html(client, room_id, plain, html)
|
# Ping the person being roasted when they were named by Matrix ID.
|
||||||
|
target_id = target_raw if re.fullmatch(r"@[^\s:]+:[^\s]+", target_raw) else None
|
||||||
|
await send_html(client, room_id, plain, html, mention_user_ids=[target_id] if target_id else None)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|||||||
+15
-7
@@ -70,17 +70,25 @@ async def send_text(client: AsyncClient, room_id: str, text: str):
|
|||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
async def send_html(client: AsyncClient, room_id: str, plain: str, html: str):
|
async def send_html(
|
||||||
|
client: AsyncClient, room_id: str, plain: str, html: str, mention_user_ids: list[str] | None = None
|
||||||
|
):
|
||||||
logger = logging.getLogger("matrixbot")
|
logger = logging.getLogger("matrixbot")
|
||||||
|
content = {
|
||||||
|
"msgtype": "m.text",
|
||||||
|
"body": plain,
|
||||||
|
"format": "org.matrix.custom.html",
|
||||||
|
"formatted_body": html,
|
||||||
|
}
|
||||||
|
# Explicit mentions (m.mentions). From Synapse 1.164 a name or user ID in
|
||||||
|
# the body no longer pings anyone (MSC4210), so a message that should
|
||||||
|
# notify someone has to say so.
|
||||||
|
if mention_user_ids:
|
||||||
|
content["m.mentions"] = {"user_ids": mention_user_ids}
|
||||||
resp = await _room_send_trusted(
|
resp = await _room_send_trusted(
|
||||||
client, room_id,
|
client, room_id,
|
||||||
message_type="m.room.message",
|
message_type="m.room.message",
|
||||||
content={
|
content=content,
|
||||||
"msgtype": "m.text",
|
|
||||||
"body": plain,
|
|
||||||
"format": "org.matrix.custom.html",
|
|
||||||
"formatted_body": html,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
if not isinstance(resp, RoomSendResponse):
|
if not isinstance(resp, RoomSendResponse):
|
||||||
logger.error("send_html failed: %s", resp)
|
logger.error("send_html failed: %s", resp)
|
||||||
|
|||||||
Reference in New Issue
Block a user