From 516db6f00a346d3813541b00471b9e548a9a4460 Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 22 May 2025 17:20:42 +0200 Subject: Split up the different features in separate classes --- MatrixAntiDmSpam.Core/ReportManager.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 MatrixAntiDmSpam.Core/ReportManager.cs (limited to 'MatrixAntiDmSpam.Core/ReportManager.cs') diff --git a/MatrixAntiDmSpam.Core/ReportManager.cs b/MatrixAntiDmSpam.Core/ReportManager.cs new file mode 100644 index 0000000..46f0666 --- /dev/null +++ b/MatrixAntiDmSpam.Core/ReportManager.cs @@ -0,0 +1,31 @@ +using LibMatrix; +using LibMatrix.Helpers; +using LibMatrix.Homeservers; +using LibMatrix.RoomTypes; +using LibMatrix.Utilities.Bot.Interfaces; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace MatrixAntiDmSpam.Core; + +public class ReportManager( + ILogger logger, + AntiDmSpamConfiguration config, + InviteManager inviteManager, + AuthenticatedHomeserverGeneric homeserver) : IHostedService { + private readonly GenericRoom? _logRoom = string.IsNullOrWhiteSpace(config.LogRoom) ? null : homeserver.GetRoom(config.LogRoom); + + public async Task StartAsync(CancellationToken cancellationToken) { + if (config.ReportBlockedInvites) { + inviteManager.OnInviteRejected.Add(ReportRejectedInvite); + } + } + + public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; + + private async Task ReportRejectedInvite(RoomInviteContext invite, StateEventResponse policyEvent) { + logger.LogInformation("ReportRejectedInvite not implemented"); + var msgTask = _logRoom?.SendMessageEventAsync(new MessageBuilder().WithBody("meow").Build()); + if (msgTask is not null) await msgTask; + } +} \ No newline at end of file -- cgit 1.5.1