about summary refs log tree commit diff
path: root/ModerationBot/Commands/DbgDumpActivePoliciesCommand.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-10-30 02:49:12 +0100
committerRory& <root@rory.gay>2025-10-30 02:49:12 +0100
commitaf6d1c7e11b2e9b4108ae8b693650b2a18cd2001 (patch)
treeebf189b0c9009fcf8b6dacd18e31cbb99afb0fff /ModerationBot/Commands/DbgDumpActivePoliciesCommand.cs
parentFix event fetch call (diff)
downloadModerationBot-af6d1c7e11b2e9b4108ae8b693650b2a18cd2001.tar.xz
Old work
Diffstat (limited to 'ModerationBot/Commands/DbgDumpActivePoliciesCommand.cs')
-rw-r--r--ModerationBot/Commands/DbgDumpActivePoliciesCommand.cs39
1 files changed, 39 insertions, 0 deletions
diff --git a/ModerationBot/Commands/DbgDumpActivePoliciesCommand.cs b/ModerationBot/Commands/DbgDumpActivePoliciesCommand.cs
new file mode 100644

index 0000000..81e81a0 --- /dev/null +++ b/ModerationBot/Commands/DbgDumpActivePoliciesCommand.cs
@@ -0,0 +1,39 @@ +using ArcaneLibs.Extensions; +using LibMatrix.EventTypes.Spec; +using LibMatrix.RoomTypes; +using LibMatrix.Services; +using LibMatrix.Utilities.Bot.Interfaces; +using ModerationBot.AccountData; + +namespace ModerationBot.Commands; + +public class DbgDumpActivePoliciesCommand(IServiceProvider services, HomeserverProviderService hsProvider, HomeserverResolverService hsResolver, PolicyEngine engine) : ICommand { + public string Name { get; } = "dbg-dumppolicies"; + public string[]? Aliases { get; } + public string Description { get; } = "[Debug] Dump all active policies"; + public bool Unlisted { get; } + private GenericRoom logRoom { get; set; } + + public async Task<bool> CanInvoke(CommandContext ctx) { +#if !DEBUG + return false; +#endif + + //check if user is admin in control room + var botData = await ctx.Homeserver.GetAccountDataAsync<BotData>("gay.rory.moderation_bot_data"); + var controlRoom = ctx.Homeserver.GetRoom(botData.ControlRoom); + var isAdmin = (await controlRoom.GetPowerLevelsAsync())!.UserHasStatePermission(ctx.MessageEvent.Sender, "m.room.ban"); + if (!isAdmin) { + // await ctx.Reply("You do not have permission to use this command!"); + await ctx.Homeserver.GetRoom(botData.LogRoom!).SendMessageEventAsync( + new RoomMessageEventContent(body: $"User {ctx.MessageEvent.Sender} tried to use command {Name} but does not have permission!", messageType: "m.text")); + } + + return isAdmin; + } + + public async Task Invoke(CommandContext ctx) { + await ctx.Room.SendFileAsync("all.json", new MemoryStream(engine.ActivePolicies.ToJson().AsBytes().ToArray()), contentType: "application/json"); + await ctx.Room.SendFileAsync("by-type.json", new MemoryStream(engine.ActivePoliciesByType.ToJson().AsBytes().ToArray()), contentType: "application/json"); + } +} \ No newline at end of file