Skip to content

Commit 3134711

Browse files
committed
policyeval: use helpers for making markdown mentions
1 parent 2aa3962 commit 3134711

File tree

11 files changed

+102
-104
lines changed

11 files changed

+102
-104
lines changed

cmd/meowlnir/policyserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (m *Meowlnir) PostMSC4284EventCheck(w http.ResponseWriter, r *http.Request)
6363
mautrix.MNotFound.WithMessage("Policy server error: room create event not found").Write(w)
6464
return
6565
}
66-
expectedEventID, err := parsedPDU.CalculateEventID(createEvt.RoomVersion)
66+
expectedEventID, err := parsedPDU.GetEventID(createEvt.RoomVersion)
6767
if err != nil {
6868
hlog.FromRequest(r).Err(err).Msg("Failed to calculate event ID from PDU")
6969
mautrix.MUnknown.WithMessage("Failed to calculate event ID from PDU").Write(w)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
golang.org/x/sync v0.16.0
1414
gopkg.in/yaml.v3 v3.0.1
1515
maunium.net/go/mauflag v1.0.0
16-
maunium.net/go/mautrix v0.25.1-0.20250817104534-cc80be150059
16+
maunium.net/go/mautrix v0.25.1-0.20250823214755-7e07700a6943
1717
)
1818

1919
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
9898
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
9999
maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
100100
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
101-
maunium.net/go/mautrix v0.25.1-0.20250817104534-cc80be150059 h1:ldFZJ2MKcRLje69uIs3RmxKZSW2TQVRjj1aL4Di0saY=
102-
maunium.net/go/mautrix v0.25.1-0.20250817104534-cc80be150059/go.mod h1:pDd6Ppg+1PbWrw/rg4ZQQfVYZICRGzH+DcliZ/BODvU=
101+
maunium.net/go/mautrix v0.25.1-0.20250823214755-7e07700a6943 h1:qNRr7dDDJhGUMTqkp4p1EJ18SL0yMKzB1pdzSZ2XUWo=
102+
maunium.net/go/mautrix v0.25.1-0.20250823214755-7e07700a6943/go.mod h1:pDd6Ppg+1PbWrw/rg4ZQQfVYZICRGzH+DcliZ/BODvU=

policyeval/antispam.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"go.mau.fi/util/ptr"
1111
"maunium.net/go/mautrix"
1212
"maunium.net/go/mautrix/event"
13+
"maunium.net/go/mautrix/format"
1314
"maunium.net/go/mautrix/id"
1415

1516
"go.mau.fi/meowlnir/bot"
@@ -62,10 +63,10 @@ func (pe *PolicyEvaluator) HandleUserMayInvite(ctx context.Context, inviter, inv
6263
context.WithoutCancel(ctx),
6364
pe.ManagementRoom,
6465
fmt.Sprintf(
65-
"Blocked ||[%s](%s)|| from inviting [%s](%s) to [%s](%s) due to policy banning ||`%s`|| for `%s`",
66-
inviter, inviter.URI().MatrixToURL(),
67-
invitee, invitee.URI().MatrixToURL(),
68-
roomID, roomID.URI().MatrixToURL(),
66+
"Blocked ||%s|| from inviting %s to %s due to policy banning ||`%s`|| for `%s`",
67+
format.MarkdownMention(inviter),
68+
format.MarkdownMention(invitee),
69+
format.MarkdownMentionRoomID("", roomID),
6970
rec.EntityOrHash(), rec.Reason,
7071
),
7172
// Don't mention users
@@ -152,9 +153,9 @@ func (pe *PolicyEvaluator) HandleAcceptMakeJoin(ctx context.Context, roomID id.R
152153
Msg("Blocking restricted join from banned user")
153154
go pe.sendNotice(
154155
context.WithoutCancel(ctx),
155-
"Blocked ||[%s](%s)|| from joining [%s](%s) due to policy banning ||`%s`|| for `%s`",
156-
userID, userID.URI().MatrixToURL(),
157-
roomID, roomID.URI().MatrixToURL(),
156+
"Blocked ||%s|| from joining %s due to policy banning ||`%s`|| for `%s`",
157+
format.MarkdownMention(userID),
158+
format.MarkdownMentionRoomID("", roomID),
158159
rec.EntityOrHash(), rec.Reason,
159160
)
160161
return ptr.Ptr(mautrix.MForbidden.WithMessage("You're banned from this room"))
@@ -253,10 +254,10 @@ func (pe *PolicyEvaluator) RejectPendingInvites(ctx context.Context, inviter id.
253254
ctx,
254255
pe.ManagementRoom,
255256
fmt.Sprintf(
256-
"Rejected %d/%d invites to [%s](%s) from ||[%s](%s)|| due to policy banning ||`%s`|| for `%s`",
257+
"Rejected %d/%d invites to %s from ||%s|| due to policy banning ||`%s`|| for `%s`",
257258
successfullyRejected, len(rooms),
258-
userID, userID.URI().MatrixToURL(),
259-
inviter, inviter.URI().MatrixToURL(),
259+
format.MarkdownMention(userID),
260+
format.MarkdownMention(inviter),
260261
rec.EntityOrHash(), rec.Reason,
261262
),
262263
// Don't mention users

policyeval/commands.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ var cmdKick = &CommandHandler{
315315
}
316316
roomStrings := make([]string, len(rooms))
317317
for i, room := range rooms {
318-
roomStrings[i] = fmt.Sprintf("[%s](%s)", room, room.URI().MatrixToURL())
318+
roomStrings[i] = format.MarkdownMentionRoomID("", room)
319319
var err error
320320
if !ce.Meta.DryRun {
321321
_, err = ce.Meta.Bot.KickUser(ce.Ctx, room, &mautrix.ReqKickUser{
@@ -352,14 +352,12 @@ func (pe *PolicyEvaluator) deduplicatePolicy(
352352
} else if rec.Recommendation == policy.Recommendation && rec.EntityOrHash() == policy.EntityOrHash() {
353353
if rec.Reason == policy.Reason {
354354
ce.Reply(
355-
"%s already has a %s recommendation in [%s](%s) for %s (sent by [%s](%s) at %s)",
355+
"%s already has a %s recommendation in %s for %s (sent by %s at %s)",
356356
format.SafeMarkdownCode(policy.EntityOrHash()),
357357
format.SafeMarkdownCode(rec.Recommendation),
358-
format.EscapeMarkdown(list.Name),
359-
list.RoomID.URI(ce.Meta.Bot.ServerName).MatrixToURL(),
358+
format.MarkdownMentionRoomID(list.Name, list.RoomID, ce.Meta.Bot.ServerName),
360359
format.SafeMarkdownCode(rec.Reason),
361-
format.EscapeMarkdown(rec.Sender.String()),
362-
rec.Sender.URI().MatrixToURL(),
360+
format.MarkdownMention(rec.Sender),
363361
time.UnixMilli(rec.Timestamp).String(),
364362
)
365363
return "", false
@@ -369,12 +367,11 @@ func (pe *PolicyEvaluator) deduplicatePolicy(
369367
} else if (policy.Recommendation != event.PolicyRecommendationUnban && rec.Recommendation == event.PolicyRecommendationUnban) ||
370368
(policy.Recommendation == event.PolicyRecommendationUnban && rec.Recommendation != event.PolicyRecommendationUnban) {
371369
ce.Reply(
372-
"%s has a conflicting %s recommendation for %s (sent by [%s](%s) at %s)",
370+
"%s has a conflicting %s recommendation for %s (sent by %s at %s)",
373371
format.SafeMarkdownCode(policy.EntityOrHash()),
374372
format.SafeMarkdownCode(rec.Recommendation),
375373
format.SafeMarkdownCode(rec.Reason),
376-
format.EscapeMarkdown(rec.Sender.String()),
377-
rec.Sender.URI().MatrixToURL(),
374+
format.MarkdownMention(rec.Sender),
378375
time.UnixMilli(rec.Timestamp).String(),
379376
)
380377
return "", false
@@ -465,7 +462,7 @@ var cmdRemovePolicy = &CommandHandler{
465462
match = ce.Meta.Store.MatchExact([]id.RoomID{list.RoomID}, entityType, target)
466463
}
467464
if len(match) == 0 {
468-
ce.Reply("No rule banning %s found in [%s](%s)", format.SafeMarkdownCode(target), format.EscapeMarkdown(list.Name), list.RoomID.URI().MatrixToURL())
465+
ce.Reply("No rule banning %s found in %s", format.SafeMarkdownCode(target), format.MarkdownMentionRoomID(list.Name, list.RoomID))
469466
return
470467
}
471468
if rec := match.Recommendations().BanOrUnban; rec != nil {
@@ -562,7 +559,7 @@ func doMatch(ce *CommandEvent, target string) {
562559
if meta != nil && meta.Name != "" {
563560
name = meta.Name
564561
}
565-
formattedRooms[i] = fmt.Sprintf("* [%s](%s)", name, roomID.URI().MatrixToURL())
562+
formattedRooms[i] = fmt.Sprintf("* %s", format.MarkdownMentionRoomID(name, roomID))
566563
}
567564
ce.Meta.protectedRoomsLock.RUnlock()
568565
ce.Reply("User is in %d protected rooms:\n\n%s", len(rooms), strings.Join(formattedRooms, "\n"))
@@ -587,10 +584,9 @@ func doMatch(ce *CommandEvent, target string) {
587584
policyRoomName = meta.Name
588585
}
589586
eventStrings[i] = fmt.Sprintf(
590-
"* [%s] [%s](%s) set recommendation %s for %s at %s for %s",
587+
"* [%s] %s set recommendation %s for %s at %s for %s",
591588
format.EscapeMarkdown(policyRoomName),
592-
policy.Sender,
593-
policy.Sender.URI().MatrixToURL(),
589+
format.MarkdownMention(policy.Sender),
594590
format.SafeMarkdownCode(policy.Recommendation),
595591
format.SafeMarkdownCode(policy.EntityOrHash()),
596592
format.EscapeMarkdown(time.UnixMilli(policy.Timestamp).String()),
@@ -642,10 +638,9 @@ var cmdSearch = &CommandHandler{
642638
policyRoomName = meta.Name
643639
}
644640
eventStrings[i] = fmt.Sprintf(
645-
"* [%s] [%s](%s) set recommendation %s for %ss matching %s at %s for %s",
641+
"* [%s] %s set recommendation %s for %ss matching %s at %s for %s",
646642
format.EscapeMarkdown(policyRoomName),
647-
policy.Sender,
648-
policy.Sender.URI().MatrixToURL(),
643+
format.MarkdownMention(policy.Sender),
649644
format.SafeMarkdownCode(policy.Recommendation),
650645
policy.EntityType,
651646
format.SafeMarkdownCode(policy.EntityOrHash()),
@@ -664,7 +659,7 @@ var cmdSearch = &CommandHandler{
664659
} else if len(users) > 0 {
665660
userStrings := make([]string, len(users))
666661
for i, user := range users {
667-
userStrings[i] = fmt.Sprintf("* [%s](%s)", user, user.URI().MatrixToURL())
662+
userStrings[i] = fmt.Sprintf("* %s", format.MarkdownMention(user))
668663
}
669664
ce.Meta.sendNotice(
670665
ce.Ctx, "Found %d users matching %s in protected rooms:\n\n%s",
@@ -695,9 +690,9 @@ var cmdSendAsBot = &CommandHandler{
695690
Body: strings.Join(ce.Args[1:], " "),
696691
})
697692
if err != nil {
698-
ce.Reply("Failed to send message to [%s](%s): %v", target, target.URI().MatrixToURL(), err)
693+
ce.Reply("Failed to send message to %s: %v", format.MarkdownMentionRoomID("", target), err)
699694
} else {
700-
ce.Reply("Sent message to [%s](%s): [%s](%s)", target, target.URI().MatrixToURL(), resp.EventID, target.EventURI(resp.EventID).MatrixToURL())
695+
ce.Reply("Sent message to %s: [%s](%s)", format.MarkdownMentionRoomID("", target), resp.EventID, target.EventURI(resp.EventID).MatrixToURL())
701696
}
702697
},
703698
}
@@ -734,7 +729,7 @@ var cmdListProtectedRooms = &CommandHandler{
734729
buf.WriteString("Protected rooms:\n\n")
735730
ce.Meta.protectedRoomsLock.RLock()
736731
for roomID, meta := range ce.Meta.protectedRooms {
737-
_, _ = fmt.Fprintf(&buf, "* [%s](%s) (%s)\n", format.EscapeMarkdown(meta.Name), roomID.URI(ce.Meta.Bot.ServerName).MatrixToURL(), format.SafeMarkdownCode(roomID))
732+
_, _ = fmt.Fprintf(&buf, "* %s (%s)\n", format.MarkdownMentionRoomID(meta.Name, roomID, ce.Meta.Bot.ServerName), format.SafeMarkdownCode(roomID))
738733
}
739734
ce.Meta.protectedRoomsLock.RUnlock()
740735
ce.Reply(buf.String())

policyeval/eventhandle.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/rs/zerolog"
1010
"go.mau.fi/util/exfmt"
1111
"maunium.net/go/mautrix/event"
12+
"maunium.net/go/mautrix/format"
1213
"maunium.net/go/mautrix/id"
1314

1415
"go.mau.fi/meowlnir/config"
@@ -59,15 +60,15 @@ func (pe *PolicyEvaluator) HandleMember(ctx context.Context, evt *event.Event) {
5960
return
6061
}
6162
if isProtecting && (content.Membership == event.MembershipLeave || content.Membership == event.MembershipBan) {
62-
pe.sendNotice(ctx, "⚠️ Bot was removed from [%s](%s)", evt.RoomID, evt.RoomID.URI().MatrixToURL())
63+
pe.sendNotice(ctx, "⚠️ Bot was removed from %s", format.MarkdownMentionRoomID("", evt.RoomID))
6364
} else if wantToProtect && (content.Membership == event.MembershipJoin || content.Membership == event.MembershipInvite) {
6465
_, err := pe.Bot.JoinRoomByID(ctx, evt.RoomID)
6566
if err != nil {
66-
pe.sendNotice(ctx, "Failed to join room [%s](%s): %v", evt.RoomID, evt.RoomID.URI().MatrixToURL(), err)
67+
pe.sendNotice(ctx, "Failed to join room %s: %v", format.MarkdownMentionRoomID("", evt.RoomID), err)
6768
} else if _, errMsg := pe.tryProtectingRoom(ctx, nil, evt.RoomID, true); errMsg != "" {
6869
pe.sendNotice(ctx, "Retried protecting room after joining room, but failed: %s", strings.TrimPrefix(errMsg, "* "))
6970
} else {
70-
pe.sendNotice(ctx, "Bot was invited to room, now protecting [%s](%s)", evt.RoomID, evt.RoomID.URI().MatrixToURL())
71+
pe.sendNotice(ctx, "Bot was invited to room, now protecting %s", format.MarkdownMentionRoomID("", evt.RoomID))
7172
}
7273
}
7374
} else {
@@ -139,24 +140,24 @@ func (pe *PolicyEvaluator) HandlePolicyListChange(ctx context.Context, policyRoo
139140
if removedAndAddedAreEquivalent {
140141
if removed.Reason == added.Reason {
141142
sendNotice(ctx,
142-
"[%s] [%s](%s) re-%s ||`%s`|| for `%s`%s",
143-
policyRoomMeta.Name, added.Sender, added.Sender.URI().MatrixToURL(),
143+
"[%s] %s re-%s ||`%s`|| for `%s`%s",
144+
policyRoomMeta.Name, format.MarkdownMention(added.Sender),
144145
addActionString(added.Recommendation), added.EntityOrHash(), added.Reason,
145146
oldEventNotice(added.Timestamp),
146147
)
147148
} else {
148149
sendNotice(ctx,
149-
"[%s] [%s](%s) changed the %s reason for ||`%s`|| from `%s` to `%s`%s",
150-
policyRoomMeta.Name, added.Sender, added.Sender.URI().MatrixToURL(),
150+
"[%s] %s changed the %s reason for ||`%s`|| from `%s` to `%s`%s",
151+
policyRoomMeta.Name, format.MarkdownMention(added.Sender),
151152
changeActionString(added.Recommendation), added.EntityOrHash(), removed.Reason, added.Reason,
152153
oldEventNotice(added.Timestamp),
153154
)
154155
}
155156
} else {
156157
if removed != nil {
157158
sendNotice(ctx,
158-
"[%s] [%s](%s) %s %ss matching ||`%s`|| for `%s`%s",
159-
policyRoomMeta.Name, removed.Sender, removed.Sender.URI().MatrixToURL(),
159+
"[%s] %s %s %ss matching ||`%s`|| for `%s`%s",
160+
policyRoomMeta.Name, format.MarkdownMention(removed.Sender),
160161
removeActionString(removed.Recommendation), removed.EntityType, removed.EntityOrHash(), removed.Reason,
161162
oldEventNotice(removed.Timestamp),
162163
)
@@ -170,8 +171,8 @@ func (pe *PolicyEvaluator) HandlePolicyListChange(ctx context.Context, policyRoo
170171
suffix += " (rule was ignored)"
171172
}
172173
sendNotice(ctx,
173-
"[%s] [%s](%s) %s %ss matching ||`%s`|| for `%s`%s",
174-
policyRoomMeta.Name, added.Sender, added.Sender.URI().MatrixToURL(),
174+
"[%s] %s %s %ss matching ||`%s`|| for `%s`%s",
175+
policyRoomMeta.Name, format.MarkdownMention(added.Sender),
175176
addActionString(added.Recommendation), added.EntityType, added.EntityOrHash(), added.Reason,
176177
suffix,
177178
)

policyeval/execute.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ func (pe *PolicyEvaluator) maybeApplySuspend(ctx context.Context, userID id.User
142142
err := pe.Bot.SynapseAdmin.SuspendAccount(ctx, userID, synapseadmin.ReqSuspendUser{Suspend: true})
143143
if err != nil {
144144
zerolog.Ctx(ctx).Err(err).Stringer("user_id", userID).Msg("Failed to suspend user")
145-
pe.sendNotice(ctx, "Failed to suspend [%s](%s): %v", userID, userID.URI().MatrixToURL(), err)
145+
pe.sendNotice(ctx, "Failed to suspend %s: %v", format.MarkdownMention(userID), err)
146146
} else {
147147
zerolog.Ctx(ctx).Info().Stringer("user_id", userID).Msg("Suspended user")
148-
pe.sendNotice(ctx, "Suspended [%s](%s) due to received ban policy", userID, userID.URI().MatrixToURL())
148+
pe.sendNotice(ctx, "Suspended %s due to received ban policy", format.MarkdownMention(userID))
149149
}
150150
}
151151

@@ -180,16 +180,16 @@ func (pe *PolicyEvaluator) ApplyBan(
180180
err = respErr
181181
}
182182
zerolog.Ctx(ctx).Err(err).Any("attempted_action", ta).Msg("Failed to ban user")
183-
pe.sendNotice(ctx, "Failed to ban ||[%s](%s)|| in [%s](%s) for %s: %v", userID, userID.URI().MatrixToURL(), roomID, roomID.URI().MatrixToURL(), policy.Reason, err)
183+
pe.sendNotice(ctx, "Failed to ban ||%s|| in %s for %s: %v", format.MarkdownMention(userID), format.MarkdownMentionRoomID("", roomID), policy.Reason, err)
184184
return
185185
}
186186
err = pe.DB.TakenAction.Put(ctx, ta)
187187
if err != nil {
188188
zerolog.Ctx(ctx).Err(err).Any("taken_action", ta).Msg("Failed to save taken action")
189-
pe.sendNotice(ctx, "Banned ||[%s](%s)|| in [%s](%s) for %s, but failed to save to database: %v", userID, userID.URI().MatrixToURL(), roomID, roomID.URI().MatrixToURL(), policy.Reason, err)
189+
pe.sendNotice(ctx, "Banned ||%s|| in %s for %s, but failed to save to database: %v", format.MarkdownMention(userID), format.MarkdownMentionRoomID("", roomID), policy.Reason, err)
190190
} else {
191191
zerolog.Ctx(ctx).Info().Any("taken_action", ta).Msg("Took action")
192-
pe.sendNotice(ctx, "Banned ||[%s](%s)|| in [%s](%s) for %s", userID, userID.URI().MatrixToURL(), roomID, roomID.URI().MatrixToURL(), policy.Reason)
192+
pe.sendNotice(ctx, "Banned ||%s|| in %s for %s", format.MarkdownMention(userID), format.MarkdownMentionRoomID("", roomID), policy.Reason)
193193
}
194194
}
195195

@@ -211,11 +211,11 @@ func (pe *PolicyEvaluator) UndoBan(ctx context.Context, userID id.UserID, roomID
211211
err = respErr
212212
}
213213
zerolog.Ctx(ctx).Err(err).Msg("Failed to unban user")
214-
pe.sendNotice(ctx, "Failed to unban [%s](%s) in [%s](%s): %v", userID, userID.URI().MatrixToURL(), roomID, roomID.URI().MatrixToURL(), err)
214+
pe.sendNotice(ctx, "Failed to unban %s in %s: %v", format.MarkdownMention(userID), format.MarkdownMentionRoomID("", roomID), err)
215215
return false
216216
}
217217
zerolog.Ctx(ctx).Debug().Msg("Unbanned user")
218-
pe.sendNotice(ctx, "Unbanned [%s](%s) in [%s](%s)", userID, userID.URI().MatrixToURL(), roomID, roomID.URI().MatrixToURL())
218+
pe.sendNotice(ctx, "Unbanned %s in %s", format.MarkdownMention(userID), format.MarkdownMentionRoomID("", roomID))
219219
return true
220220
}
221221

@@ -239,8 +239,8 @@ Outer:
239239
if err != nil {
240240
zerolog.Ctx(ctx).Err(err).Stringer("room_id", roomID).Msg("Failed to redact messages")
241241
errorMessages = append(errorMessages, fmt.Sprintf(
242-
"* Failed to redact events from [%s](%s) in [%s](%s): %v",
243-
userID, userID.URI().MatrixToURL(), roomID, roomID.URI().MatrixToURL(), err))
242+
"* Failed to redact events from %s in %s: %v",
243+
format.MarkdownMention(userID), format.MarkdownMentionRoomID("", roomID), err))
244244
continue Outer
245245
}
246246
hasMore = resp.IsMoreEvents
@@ -266,8 +266,8 @@ func (pe *PolicyEvaluator) redactUserSynapse(ctx context.Context, userID id.User
266266
Dur("query_duration", dur).
267267
Msg("Failed to get events to redact")
268268
pe.sendNotice(ctx,
269-
"Failed to get events to redact for [%s](%s): %v",
270-
userID, userID.URI().MatrixToURL(), err)
269+
"Failed to get events to redact for %s: %v",
270+
format.MarkdownMention(userID), err)
271271
return
272272
} else if len(events) == 0 {
273273
zerolog.Ctx(ctx).Debug().
@@ -294,8 +294,8 @@ func (pe *PolicyEvaluator) redactUserSynapse(ctx context.Context, userID id.User
294294
successCount, failedCount := pe.redactEventsInRoom(ctx, userID, roomID, roomEvents, reason)
295295
if failedCount > 0 {
296296
errorMessages = append(errorMessages, fmt.Sprintf(
297-
"* Failed to redact %d/%d events from [%s](%s) in [%s](%s)",
298-
failedCount, failedCount+successCount, userID, userID.URI().MatrixToURL(), roomID, roomID.URI().MatrixToURL()))
297+
"* Failed to redact %d/%d events from %s in %s",
298+
failedCount, failedCount+successCount, format.MarkdownMention(userID), format.MarkdownMentionRoomID("", roomID)))
299299
}
300300
redactedCount += successCount
301301
}
@@ -314,9 +314,9 @@ func (pe *PolicyEvaluator) sendRedactResult(ctx context.Context, events, rooms i
314314
// Skip sending a message if no events were redacted and there were no errors
315315
return
316316
}
317-
output := fmt.Sprintf("Redacted %s across %s from [%s](%s)",
317+
output := fmt.Sprintf("Redacted %s across %s from %s",
318318
pluralize(events, "event"), pluralize(rooms, "room"),
319-
userID, userID.URI().MatrixToURL())
319+
format.MarkdownMention(userID))
320320
if len(errorMessages) > 0 {
321321
output += "\n\n" + strings.Join(errorMessages, "\n")
322322
}
@@ -342,7 +342,7 @@ func (pe *PolicyEvaluator) RedactUser(ctx context.Context, userID id.UserID, rea
342342
continue
343343
}
344344
if redactedCount > 0 {
345-
pe.sendNotice(ctx, "Redacted %d events from [%s](%s) in [%s](%s)", redactedCount, userID, userID.URI().MatrixToURL(), roomID, roomID.URI().MatrixToURL())
345+
pe.sendNotice(ctx, "Redacted %d events from %s in %s", redactedCount, format.MarkdownMention(userID), format.MarkdownMentionRoomID("", roomID))
346346
}
347347
}
348348
}

policyeval/messagehandle.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77

88
"maunium.net/go/mautrix/event"
9+
"maunium.net/go/mautrix/format"
910

1011
"go.mau.fi/meowlnir/bot"
1112
)
@@ -27,10 +28,10 @@ func (pe *PolicyEvaluator) HandleMessage(ctx context.Context, evt *event.Event)
2728
pe.Bot.SendNoticeOpts(
2829
ctx, pe.ManagementRoom,
2930
fmt.Sprintf(
30-
`@room [%s](%s) [pinged](%s) the bot in [%s](%s)`,
31-
evt.Sender, evt.Sender.URI().MatrixToURL(),
31+
`@room %s [pinged](%s) the bot in %s`,
32+
format.MarkdownMention(evt.Sender),
3233
evt.RoomID.EventURI(evt.ID).MatrixToURL(),
33-
evt.RoomID, evt.RoomID.URI().MatrixToURL(),
34+
format.MarkdownMentionRoomID("", evt.RoomID),
3435
),
3536
&bot.SendNoticeOpts{Mentions: &event.Mentions{Room: true}, SendAsText: true},
3637
)

0 commit comments

Comments
 (0)