Log config on startupg
3 files changed, 49 insertions, 0 deletions
diff --git a/LibMatrix b/LibMatrix
-Subproject 8ade05a37f0f4d283d80d7f8d844787a4487c51
+Subproject 94b6b1e845cc867681d88e6d6673ce71f67a889
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
diff --git a/MatrixAntiDmSpam/Program.cs b/MatrixAntiDmSpam/Program.cs
index 0be6825..51850a1 100644
--- a/MatrixAntiDmSpam/Program.cs
+++ b/MatrixAntiDmSpam/Program.cs
@@ -10,6 +10,7 @@ builder.Services.AddRoryLibMatrixServices()
.AddMatrixBot()
.WithInviteHandler<RoomInviteHandler>();
+builder.Services.AddHostedService<AntiDmSpamStartup>();
builder.Services.AddHostedService<PolicyListFetcher>();
builder.Services.AddSingleton<InviteManager>();
builder.Services.AddHostedService<InviteManager>(sp => sp.GetRequiredService<InviteManager>());
|