Skip to content

Commit 8dd41d9

Browse files
committed
Merge branch 'main' into nexy7574/protections
2 parents a338b06 + 3134711 commit 8dd41d9

File tree

13 files changed

+141
-134
lines changed

13 files changed

+141
-134
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
@@ -311,7 +311,7 @@ var cmdKick = &CommandHandler{
311311
}
312312
roomStrings := make([]string, len(rooms))
313313
for i, room := range rooms {
314-
roomStrings[i] = fmt.Sprintf("[%s](%s)", room, room.URI().MatrixToURL())
314+
roomStrings[i] = format.MarkdownMentionRoomID("", room)
315315
var err error
316316
if !ce.Meta.DryRun {
317317
_, err = ce.Meta.Bot.KickUser(ce.Ctx, room, &mautrix.ReqKickUser{
@@ -348,14 +348,12 @@ func (pe *PolicyEvaluator) deduplicatePolicy(
348348
} else if rec.Recommendation == policy.Recommendation && rec.EntityOrHash() == policy.EntityOrHash() {
349349
if rec.Reason == policy.Reason {
350350
ce.Reply(
351-
"%s already has a %s recommendation in [%s](%s) for %s (sent by [%s](%s) at %s)",
351+
"%s already has a %s recommendation in %s for %s (sent by %s at %s)",
352352
format.SafeMarkdownCode(policy.EntityOrHash()),
353353
format.SafeMarkdownCode(rec.Recommendation),
354-
format.EscapeMarkdown(list.Name),
355-
list.RoomID.URI(ce.Meta.Bot.ServerName).MatrixToURL(),
354+
format.MarkdownMentionRoomID(list.Name, list.RoomID, ce.Meta.Bot.ServerName),
356355
format.SafeMarkdownCode(rec.Reason),
357-
format.EscapeMarkdown(rec.Sender.String()),
358-
rec.Sender.URI().MatrixToURL(),
356+
format.MarkdownMention(rec.Sender),
359357
time.UnixMilli(rec.Timestamp).String(),
360358
)
361359
return "", false
@@ -365,12 +363,11 @@ func (pe *PolicyEvaluator) deduplicatePolicy(
365363
} else if (policy.Recommendation != event.PolicyRecommendationUnban && rec.Recommendation == event.PolicyRecommendationUnban) ||
366364
(policy.Recommendation == event.PolicyRecommendationUnban && rec.Recommendation != event.PolicyRecommendationUnban) {
367365
ce.Reply(
368-
"%s has a conflicting %s recommendation for %s (sent by [%s](%s) at %s)",
366+
"%s has a conflicting %s recommendation for %s (sent by %s at %s)",
369367
format.SafeMarkdownCode(policy.EntityOrHash()),
370368
format.SafeMarkdownCode(rec.Recommendation),
371369
format.SafeMarkdownCode(rec.Reason),
372-
format.EscapeMarkdown(rec.Sender.String()),
373-
rec.Sender.URI().MatrixToURL(),
370+
format.MarkdownMention(rec.Sender),
374371
time.UnixMilli(rec.Timestamp).String(),
375372
)
376373
return "", false
@@ -461,7 +458,7 @@ var cmdRemovePolicy = &CommandHandler{
461458
match = ce.Meta.Store.MatchExact([]id.RoomID{list.RoomID}, entityType, target)
462459
}
463460
if len(match) == 0 {
464-
ce.Reply("No rule banning %s found in [%s](%s)", format.SafeMarkdownCode(target), format.EscapeMarkdown(list.Name), list.RoomID.URI().MatrixToURL())
461+
ce.Reply("No rule banning %s found in %s", format.SafeMarkdownCode(target), format.MarkdownMentionRoomID(list.Name, list.RoomID))
465462
return
466463
}
467464
if rec := match.Recommendations().BanOrUnban; rec != nil {
@@ -558,7 +555,7 @@ func doMatch(ce *CommandEvent, target string) {
558555
if meta != nil && meta.Name != "" {
559556
name = meta.Name
560557
}
561-
formattedRooms[i] = fmt.Sprintf("* [%s](%s)", name, roomID.URI().MatrixToURL())
558+
formattedRooms[i] = fmt.Sprintf("* %s", format.MarkdownMentionRoomID(name, roomID))
562559
}
563560
ce.Meta.protectedRoomsLock.RUnlock()
564561
ce.Reply("User is in %d protected rooms:\n\n%s", len(rooms), strings.Join(formattedRooms, "\n"))
@@ -583,10 +580,9 @@ func doMatch(ce *CommandEvent, target string) {
583580
policyRoomName = meta.Name
584581
}
585582
eventStrings[i] = fmt.Sprintf(
586-
"* [%s] [%s](%s) set recommendation %s for %s at %s for %s",
583+
"* [%s] %s set recommendation %s for %s at %s for %s",
587584
format.EscapeMarkdown(policyRoomName),
588-
policy.Sender,
589-
policy.Sender.URI().MatrixToURL(),
585+
format.MarkdownMention(policy.Sender),
590586
format.SafeMarkdownCode(policy.Recommendation),
591587
format.SafeMarkdownCode(policy.EntityOrHash()),
592588
format.EscapeMarkdown(time.UnixMilli(policy.Timestamp).String()),
@@ -638,10 +634,9 @@ var cmdSearch = &CommandHandler{
638634
policyRoomName = meta.Name
639635
}
640636
eventStrings[i] = fmt.Sprintf(
641-
"* [%s] [%s](%s) set recommendation %s for %ss matching %s at %s for %s",
637+
"* [%s] %s set recommendation %s for %ss matching %s at %s for %s",
642638
format.EscapeMarkdown(policyRoomName),
643-
policy.Sender,
644-
policy.Sender.URI().MatrixToURL(),
639+
format.MarkdownMention(policy.Sender),
645640
format.SafeMarkdownCode(policy.Recommendation),
646641
policy.EntityType,
647642
format.SafeMarkdownCode(policy.EntityOrHash()),
@@ -660,7 +655,7 @@ var cmdSearch = &CommandHandler{
660655
} else if len(users) > 0 {
661656
userStrings := make([]string, len(users))
662657
for i, user := range users {
663-
userStrings[i] = fmt.Sprintf("* [%s](%s)", user, user.URI().MatrixToURL())
658+
userStrings[i] = fmt.Sprintf("* %s", format.MarkdownMention(user))
664659
}
665660
ce.Meta.sendNotice(
666661
ce.Ctx, "Found %d users matching %s in protected rooms:\n\n%s",
@@ -691,9 +686,9 @@ var cmdSendAsBot = &CommandHandler{
691686
Body: strings.Join(ce.Args[1:], " "),
692687
})
693688
if err != nil {
694-
ce.Reply("Failed to send message to [%s](%s): %v", target, target.URI().MatrixToURL(), err)
689+
ce.Reply("Failed to send message to %s: %v", format.MarkdownMentionRoomID("", target), err)
695690
} else {
696-
ce.Reply("Sent message to [%s](%s): [%s](%s)", target, target.URI().MatrixToURL(), resp.EventID, target.EventURI(resp.EventID).MatrixToURL())
691+
ce.Reply("Sent message to %s: [%s](%s)", format.MarkdownMentionRoomID("", target), resp.EventID, target.EventURI(resp.EventID).MatrixToURL())
697692
}
698693
},
699694
}
@@ -730,7 +725,7 @@ var cmdListProtectedRooms = &CommandHandler{
730725
buf.WriteString("Protected rooms:\n\n")
731726
ce.Meta.protectedRoomsLock.RLock()
732727
for roomID, meta := range ce.Meta.protectedRooms {
733-
_, _ = fmt.Fprintf(&buf, "* [%s](%s) (%s)\n", format.EscapeMarkdown(meta.Name), roomID.URI(ce.Meta.Bot.ServerName).MatrixToURL(), format.SafeMarkdownCode(roomID))
728+
_, _ = fmt.Fprintf(&buf, "* %s (%s)\n", format.MarkdownMentionRoomID(meta.Name, roomID, ce.Meta.Bot.ServerName), format.SafeMarkdownCode(roomID))
734729
}
735730
ce.Meta.protectedRoomsLock.RUnlock()
736731
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"
@@ -63,15 +64,15 @@ func (pe *PolicyEvaluator) HandleMember(ctx context.Context, evt *event.Event) {
6364
return
6465
}
6566
if isProtecting && (content.Membership == event.MembershipLeave || content.Membership == event.MembershipBan) {
66-
pe.sendNotice(ctx, "⚠️ Bot was removed from [%s](%s)", evt.RoomID, evt.RoomID.URI().MatrixToURL())
67+
pe.sendNotice(ctx, "⚠️ Bot was removed from %s", format.MarkdownMentionRoomID("", evt.RoomID))
6768
} else if wantToProtect && (content.Membership == event.MembershipJoin || content.Membership == event.MembershipInvite) {
6869
_, err := pe.Bot.JoinRoomByID(ctx, evt.RoomID)
6970
if err != nil {
70-
pe.sendNotice(ctx, "Failed to join room [%s](%s): %v", evt.RoomID, evt.RoomID.URI().MatrixToURL(), err)
71+
pe.sendNotice(ctx, "Failed to join room %s: %v", format.MarkdownMentionRoomID("", evt.RoomID), err)
7172
} else if _, errMsg := pe.tryProtectingRoom(ctx, nil, evt.RoomID, true); errMsg != "" {
7273
pe.sendNotice(ctx, "Retried protecting room after joining room, but failed: %s", strings.TrimPrefix(errMsg, "* "))
7374
} else {
74-
pe.sendNotice(ctx, "Bot was invited to room, now protecting [%s](%s)", evt.RoomID, evt.RoomID.URI().MatrixToURL())
75+
pe.sendNotice(ctx, "Bot was invited to room, now protecting %s", format.MarkdownMentionRoomID("", evt.RoomID))
7576
}
7677
}
7778
} else {
@@ -157,24 +158,24 @@ func (pe *PolicyEvaluator) HandlePolicyListChange(ctx context.Context, policyRoo
157158
if removedAndAddedAreEquivalent {
158159
if removed.Reason == added.Reason {
159160
sendNotice(ctx,
160-
"[%s] [%s](%s) re-%s ||`%s`|| for `%s`%s",
161-
policyRoomMeta.Name, added.Sender, added.Sender.URI().MatrixToURL(),
161+
"[%s] %s re-%s ||`%s`|| for `%s`%s",
162+
policyRoomMeta.Name, format.MarkdownMention(added.Sender),
162163
addActionString(added.Recommendation), added.EntityOrHash(), added.Reason,
163164
oldEventNotice(added.Timestamp),
164165
)
165166
} else {
166167
sendNotice(ctx,
167-
"[%s] [%s](%s) changed the %s reason for ||`%s`|| from `%s` to `%s`%s",
168-
policyRoomMeta.Name, added.Sender, added.Sender.URI().MatrixToURL(),
168+
"[%s] %s changed the %s reason for ||`%s`|| from `%s` to `%s`%s",
169+
policyRoomMeta.Name, format.MarkdownMention(added.Sender),
169170
changeActionString(added.Recommendation), added.EntityOrHash(), removed.Reason, added.Reason,
170171
oldEventNotice(added.Timestamp),
171172
)
172173
}
173174
} else {
174175
if removed != nil {
175176
sendNotice(ctx,
176-
"[%s] [%s](%s) %s %ss matching ||`%s`|| for `%s`%s",
177-
policyRoomMeta.Name, removed.Sender, removed.Sender.URI().MatrixToURL(),
177+
"[%s] %s %s %ss matching ||`%s`|| for `%s`%s",
178+
policyRoomMeta.Name, format.MarkdownMention(removed.Sender),
178179
removeActionString(removed.Recommendation), removed.EntityType, removed.EntityOrHash(), removed.Reason,
179180
oldEventNotice(removed.Timestamp),
180181
)
@@ -188,8 +189,8 @@ func (pe *PolicyEvaluator) HandlePolicyListChange(ctx context.Context, policyRoo
188189
suffix += " (rule was ignored)"
189190
}
190191
sendNotice(ctx,
191-
"[%s] [%s](%s) %s %ss matching ||`%s`|| for `%s`%s",
192-
policyRoomMeta.Name, added.Sender, added.Sender.URI().MatrixToURL(),
192+
"[%s] %s %s %ss matching ||`%s`|| for `%s`%s",
193+
policyRoomMeta.Name, format.MarkdownMention(added.Sender),
193194
addActionString(added.Recommendation), added.EntityType, added.EntityOrHash(), added.Reason,
194195
suffix,
195196
)

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
@@ -8,6 +8,7 @@ import (
88
"github.com/rs/zerolog"
99

1010
"maunium.net/go/mautrix/event"
11+
"maunium.net/go/mautrix/format"
1112

1213
"go.mau.fi/meowlnir/bot"
1314
)
@@ -32,10 +33,10 @@ func (pe *PolicyEvaluator) HandleMessage(ctx context.Context, evt *event.Event)
3233
pe.Bot.SendNoticeOpts(
3334
ctx, pe.ManagementRoom,
3435
fmt.Sprintf(
35-
`@room [%s](%s) [pinged](%s) the bot in [%s](%s)`,
36-
evt.Sender, evt.Sender.URI().MatrixToURL(),
36+
`@room %s [pinged](%s) the bot in %s`,
37+
format.MarkdownMention(evt.Sender),
3738
evt.RoomID.EventURI(evt.ID).MatrixToURL(),
38-
evt.RoomID, evt.RoomID.URI().MatrixToURL(),
39+
format.MarkdownMentionRoomID("", evt.RoomID),
3940
),
4041
&bot.SendNoticeOpts{Mentions: &event.Mentions{Room: true}, SendAsText: true},
4142
)

0 commit comments

Comments
 (0)