Log config on startupg
1 files changed, 48 insertions, 0 deletions
diff --git a/MatrixAntiDmSpam.Core/AntiDmSpamStartup.cs b/MatrixAntiDmSpam.Core/AntiDmSpamStartup.cs
new file mode 100644
index 0000000..6182e29
--- /dev/null
+++ b/MatrixAntiDmSpam.Core/AntiDmSpamStartup.cs
@@ -0,0 +1,48 @@
+using LibMatrix.Helpers;
+using LibMatrix.Homeservers;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+
+namespace MatrixAntiDmSpam.Core;
+
+public class AntiDmSpamStartup(ILogger<AntiDmSpamStartup> logger, AuthenticatedHomeserverGeneric homeserver, AntiDmSpamConfiguration config) : IHostedService {
+ public async Task StartAsync(CancellationToken cancellationToken) {
+ if (string.IsNullOrWhiteSpace(config.LogRoom)) {
+ logger.LogWarning("LogRoom is not set in the configuration, no logging will be done.");
+ return;
+ }
+
+ var policyListList = string.Join("<br/>", config.PolicyLists.Select(x => $"<a href=\"matrix:roomid/{x.RoomId[1..]}\">{x.Name}</a>"));
+
+ var startupMessage = new MessageBuilder()
+ .WithColoredBody("#00FF00", "MatrixAntiDmSpam is starting up!")
+ .WithTable(tb => tb
+ .WithTitle("Configuration", 3)
+ .WithRow(rb => rb
+ .WithCell(nameof(config.LogInviteDataAsFile))
+ .WithCell(MessageBuilder.GetColoredBody(config.LogInviteDataAsFile ? "#00FF00" : "#FF0000", config.LogInviteDataAsFile.ToString()))
+ .WithCell("Include invite data as a downloadable file"))
+ .WithRow(rb => rb
+ .WithCell(nameof(config.ReportBlockedInvites))
+ .WithCell(MessageBuilder.GetColoredBody(config.ReportBlockedInvites ? "#00FF00" : "#FF0000", config.ReportBlockedInvites.ToString()))
+ .WithCell($"Automatically report blocked invites to {homeserver.ServerName}"))
+ .WithRow(rb => rb
+ .WithCell(nameof(config.IgnoreBannedUsers))
+ .WithCell(MessageBuilder.GetColoredBody(config.IgnoreBannedUsers ? "#00FF00" : "#FF0000", config.IgnoreBannedUsers.ToString()))
+ .WithCell("Automatically add banned users to your ignore list"))
+ .WithRow(rb => rb
+ .WithCell(nameof(config.MinimumSyncTime))
+ .WithCell(config.MinimumSyncTime?.ToString() ?? "Instant (dangerous!)")
+ .WithCell("Minimum time between checking for server updates"))
+ .WithRow(rb => rb
+ .WithCell(nameof(config.PolicyLists))
+ .WithCell(policyListList)
+ .WithCell("Policy lists to match against"))
+ );
+
+ var logRoom = homeserver.GetRoom(config.LogRoom);
+ await logRoom.SendMessageEventAsync(startupMessage.Build());
+ }
+
+ public async Task StopAsync(CancellationToken cancellationToken) { }
+}
\ No newline at end of file
|