From aa6ac5e7162558409417d8eb7e3152ad3d3b3134 Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 15 May 2025 08:14:26 +0200 Subject: Add more commands --- LibMatrix | 2 +- MiniUtils.sln.DotSettings.user | 1 + MiniUtils/Commands/DeleteRoomCommand.cs | 47 +++++++++++++++++++++++++++++ MiniUtils/Commands/MakePolicyListCommand.cs | 47 +++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 MiniUtils/Commands/DeleteRoomCommand.cs create mode 100644 MiniUtils/Commands/MakePolicyListCommand.cs diff --git a/LibMatrix b/LibMatrix index c830542..dae1a25 160000 --- a/LibMatrix +++ b/LibMatrix @@ -1 +1 @@ -Subproject commit c83054203dda13035028e4ea824d74e213ec9972 +Subproject commit dae1a25664606415e054f3e3b20bbbfabdbb0e99 diff --git a/MiniUtils.sln.DotSettings.user b/MiniUtils.sln.DotSettings.user index 76198cf..2946aec 100644 --- a/MiniUtils.sln.DotSettings.user +++ b/MiniUtils.sln.DotSettings.user @@ -7,6 +7,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded \ No newline at end of file diff --git a/MiniUtils/Commands/DeleteRoomCommand.cs b/MiniUtils/Commands/DeleteRoomCommand.cs new file mode 100644 index 0000000..41dbfb3 --- /dev/null +++ b/MiniUtils/Commands/DeleteRoomCommand.cs @@ -0,0 +1,47 @@ +using ArcaneLibs.Extensions; +using LibMatrix.EventTypes.Common; +using LibMatrix.EventTypes.Spec.State.RoomInfo; +using LibMatrix.Helpers; +using LibMatrix.Responses; +using LibMatrix.RoomTypes; +using LibMatrix.Utilities.Bot.Interfaces; + +namespace MiniUtils.Commands; + +public class DeleteRoomCommand() : ICommand { + public string Name => "delete room"; + + public string[]? Aliases => ["deleteroom"]; + + public string Description => "Delete a room"; + + public bool Unlisted => false; + + public async Task Invoke(CommandContext ctx) { + var creationContent = new CreateRoomRequest() { + Name = ctx.Args[0], + RoomAliasName = ctx.Args[0], + Visibility = "private", + CreationContent = new() { + { "type", PolicyRoom.TypeName }, + { "room_version", 11 } + }, + PowerLevelContentOverride = new RoomPowerLevelEventContent() { + EventsDefault = 50, + Invite = 50 + }, + InitialState = [ + new() { + Type = MjolnirShortcodeEventContent.EventId, + StateKey = "", + TypedContent = new MjolnirShortcodeEventContent() { + Shortcode = ctx.Args[0] + } + } + ] + }; + + var result = await ctx.Homeserver.CreateRoom(creationContent); + await ctx.Room.SendMessageEventAsync(new MessageBuilder().WithMention($"#{ctx.Args[0]}:{ctx.Homeserver.ServerName}").Build()); + } +} \ No newline at end of file diff --git a/MiniUtils/Commands/MakePolicyListCommand.cs b/MiniUtils/Commands/MakePolicyListCommand.cs new file mode 100644 index 0000000..0498712 --- /dev/null +++ b/MiniUtils/Commands/MakePolicyListCommand.cs @@ -0,0 +1,47 @@ +using ArcaneLibs.Extensions; +using LibMatrix.EventTypes.Common; +using LibMatrix.EventTypes.Spec.State.RoomInfo; +using LibMatrix.Helpers; +using LibMatrix.Responses; +using LibMatrix.RoomTypes; +using LibMatrix.Utilities.Bot.Interfaces; + +namespace MiniUtils.Commands; + +public class MakePolicyListCommand() : ICommand { + public string Name => "makepolicylist"; + + public string[]? Aliases => ["make policy list"]; + + public string Description => "Make a new policy list"; + + public bool Unlisted => false; + + public async Task Invoke(CommandContext ctx) { + var creationContent = new CreateRoomRequest() { + Name = ctx.Args[0], + RoomAliasName = ctx.Args[0], + Visibility = "private", + CreationContent = new() { + { "type", PolicyRoom.TypeName }, + { "room_version", 11 } + }, + PowerLevelContentOverride = new RoomPowerLevelEventContent() { + EventsDefault = 50, + Invite = 50 + }, + InitialState = [ + new() { + Type = MjolnirShortcodeEventContent.EventId, + StateKey = "", + TypedContent = new MjolnirShortcodeEventContent() { + Shortcode = ctx.Args[0] + } + } + ] + }; + + var result = await ctx.Homeserver.CreateRoom(creationContent); + await ctx.Room.SendMessageEventAsync(new MessageBuilder().WithMention($"#{ctx.Args[0]}:{ctx.Homeserver.ServerName}").Build()); + } +} \ No newline at end of file -- cgit 1.5.1