From d133a168c17d605236e967ff63728420ddb0ed98 Mon Sep 17 00:00:00 2001 From: Rory& Date: Wed, 31 Jan 2024 18:50:16 +0100 Subject: Repo split --- .../Commands/DbgAllRoomsArePolicyListsCommand.cs | 58 ---------------------- 1 file changed, 58 deletions(-) delete mode 100644 ExampleBots/ModerationBot/Commands/DbgAllRoomsArePolicyListsCommand.cs (limited to 'ExampleBots/ModerationBot/Commands/DbgAllRoomsArePolicyListsCommand.cs') diff --git a/ExampleBots/ModerationBot/Commands/DbgAllRoomsArePolicyListsCommand.cs b/ExampleBots/ModerationBot/Commands/DbgAllRoomsArePolicyListsCommand.cs deleted file mode 100644 index cd0bf6b..0000000 --- a/ExampleBots/ModerationBot/Commands/DbgAllRoomsArePolicyListsCommand.cs +++ /dev/null @@ -1,58 +0,0 @@ -using LibMatrix.EventTypes.Spec; -using LibMatrix.Helpers; -using LibMatrix.RoomTypes; -using LibMatrix.Services; -using LibMatrix.Utilities.Bot.Interfaces; -using ModerationBot.AccountData; - -namespace ModerationBot.Commands; - -public class DbgAllRoomsArePolicyListsCommand - (IServiceProvider services, HomeserverProviderService hsProvider, HomeserverResolverService hsResolver, PolicyEngine engine) : ICommand { - public string Name { get; } = "dbg-allroomsarepolicy"; - public string Description { get; } = "[Debug] mark all rooms as trusted policy rooms"; - private GenericRoom logRoom { get; set; } - - public async Task CanInvoke(CommandContext ctx) { -// #if !DEBUG -// return false; -// #endif - - //check if user is admin in control room - var botData = await ctx.Homeserver.GetAccountDataAsync("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("gay.rory.moderation_bot_data"); - logRoom = ctx.Homeserver.GetRoom(botData.LogRoom ?? botData.ControlRoom); - - var joinedRooms = await ctx.Homeserver.GetJoinedRooms(); - - await ctx.Homeserver.SetAccountDataAsync("gay.rory.moderation_bot.policy_lists", joinedRooms.ToDictionary(x => x.RoomId, x => new PolicyList() { - Trusted = true - })); - - await engine.ReloadActivePolicyLists(); - } - - private async Task JoinRoom(GenericRoom memberRoom, string reason, List servers) { - try { - await memberRoom.JoinAsync(servers.ToArray(), reason); - await logRoom.SendMessageEventAsync(MessageFormatter.FormatSuccess($"Joined room {memberRoom.RoomId}")); - } - catch (Exception e) { - await logRoom.SendMessageEventAsync(MessageFormatter.FormatException($"Failed to join {memberRoom.RoomId}", e)); - } - - return true; - } -} -- cgit 1.4.1