diff options
author | Emma [it/its]@Rory& <root@rory.gay> | 2024-01-11 07:31:09 +0100 |
---|---|---|
committer | Emma [it/its]@Rory& <root@rory.gay> | 2024-01-11 07:31:09 +0100 |
commit | 8dadf547033d71480fd7756809992c0f32549f59 (patch) | |
tree | a23631cc840047e3ad9e32dda9c043511af1a583 /ExampleBots/ModerationBot/Commands/ReloadPoliciesCommand.cs | |
parent | Try-create factory for RemoteHomeserver, more reliable RemoteHomeserver creation (diff) | |
download | LibMatrix-8dadf547033d71480fd7756809992c0f32549f59.tar.xz |
Cleanup, more message formatters, messagebuilder start
Diffstat (limited to 'ExampleBots/ModerationBot/Commands/ReloadPoliciesCommand.cs')
-rw-r--r-- | ExampleBots/ModerationBot/Commands/ReloadPoliciesCommand.cs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/ExampleBots/ModerationBot/Commands/ReloadPoliciesCommand.cs b/ExampleBots/ModerationBot/Commands/ReloadPoliciesCommand.cs new file mode 100644 index 0000000..b876145 --- /dev/null +++ b/ExampleBots/ModerationBot/Commands/ReloadPoliciesCommand.cs @@ -0,0 +1,37 @@ +using LibMatrix.EventTypes.Spec; +using LibMatrix.Helpers; +using LibMatrix.Services; +using LibMatrix.Utilities.Bot.Interfaces; +using ModerationBot.AccountData; + +namespace ModerationBot.Commands; + +public class ReloadPoliciesCommand(IServiceProvider services, HomeserverProviderService hsProvider, HomeserverResolverService hsResolver, PolicyEngine engine) : ICommand { + public string Name { get; } = "reloadpolicies"; + public string Description { get; } = "Reload policies"; + + public async Task<bool> CanInvoke(CommandContext ctx) { + if (ctx.MessageEvent.Sender == "@cadence:cadence.moe") return true; + //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) { + + var botData = await ctx.Homeserver.GetAccountDataAsync<BotData>("gay.rory.moderation_bot_data"); + var policyRoom = ctx.Homeserver.GetRoom(botData.DefaultPolicyRoom ?? botData.ControlRoom); + var logRoom = ctx.Homeserver.GetRoom(botData.LogRoom ?? botData.ControlRoom); + + await logRoom.SendMessageEventAsync(MessageFormatter.FormatSuccess($"Reloading policy lists due to manual invocation!!!!")); + await engine.ReloadActivePolicyLists(); + } +} |