diff --git a/MatrixAntiDmSpam.Core/InviteManager.cs b/MatrixAntiDmSpam.Core/InviteManager.cs
index e8a5dc1..a48cea2 100644
--- a/MatrixAntiDmSpam.Core/InviteManager.cs
+++ b/MatrixAntiDmSpam.Core/InviteManager.cs
@@ -23,7 +23,6 @@ public class InviteManager(
public List<Func<RoomInviteContext, StateEventResponse, Task>> OnInviteRejected { get; } = [];
public List<Func<RoomInviteContext, StateEventResponse, Task>> OnBeforeInviteRejected { get; } = [];
-
public async Task StartAsync(CancellationToken cancellationToken) {
roomInviteHandler.OnInviteReceived.Add(CheckPoliciesAgainstInvite);
policyStore.OnPolicyAdded.Add(CheckPolicyAgainstOutstandingInvites);
@@ -90,23 +89,25 @@ public class InviteManager(
var policyRoom = config.PolicyLists.First(x => x.RoomId == policyEvent.RoomId);
logger.LogWarning("[{}] Rejecting invite to {}, matching {} in {}: {}", homeserver.WhoAmI.UserId, invite.RoomId, policy.GetType().GetFriendlyName(),
policyRoom.Name, policy.ToJson(ignoreNull: true));
-
+
foreach (var callback in OnBeforeInviteRejected) {
await callback(invite, policyEvent);
}
if (_logRoom is not null) {
var roomName = await invite.TryGetRoomNameAsync();
-
- await roomInviteHandler.RejectInvite(invite, new MessageBuilder()
+ var logMessage = new MessageBuilder()
.WithColoredBody("#FF0000",
cb => cb.WithBody("Rejecting invite to ").WithMention(invite.RoomId, roomName)
.WithBody($", matching {policy.GetType().GetFriendlyName().ToLowerInvariant()} in {policyRoom.Name}.")
.WithNewline())
.WithCollapsibleSection("Policy JSON", cb => cb.WithCodeBlock(policy.ToJson(ignoreNull: true), "json"))
- );
+ .Build();
+ await _logRoom.SendMessageEventAsync(logMessage);
}
+ await roomInviteHandler.RejectInvite(invite);
+
foreach (var callback in OnInviteRejected) {
await callback(invite, policyEvent);
}
diff --git a/MatrixAntiDmSpam.Core/RoomInviteHandler.cs b/MatrixAntiDmSpam.Core/RoomInviteHandler.cs
index 41f4011..d4d97d6 100644
--- a/MatrixAntiDmSpam.Core/RoomInviteHandler.cs
+++ b/MatrixAntiDmSpam.Core/RoomInviteHandler.cs
@@ -55,9 +55,9 @@ public class RoomInviteHandler(ILogger<RoomInviteHandler> logger, AntiDmSpamConf
var message = new MessageBuilder()
.WithBody("Received invite to ").WithMention(invite.RoomId, await roomNameTask).WithBody(" from ").WithMention(invite.MemberEvent.Sender!, await inviterNameTask)
.Build();
-
+
message.AdditionalData!["gay.rory.invite_logger.invite_data_uri"] = JsonDocument.Parse($"\"{await inviteDataFileUriTask}\"").RootElement;
-
+
await LogRoom.SendMessageEventAsync(message);
if (config.LogInviteDataAsFile) {
@@ -71,10 +71,7 @@ public class RoomInviteHandler(ILogger<RoomInviteHandler> logger, AntiDmSpamConf
}
}
- public async Task RejectInvite(RoomInviteContext invite, MessageBuilder reason) {
- if (LogRoom is not null)
- _ = LogRoom.SendMessageEventAsync(reason.Build());
-
+ public async Task RejectInvite(RoomInviteContext invite) {
try {
await invite.Homeserver.GetRoom(invite.RoomId).LeaveAsync();
}
|