about summary refs log tree commit diff
path: root/MiniUtils/Commands/JoinCommand.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MiniUtils/Commands/JoinCommand.cs')
-rw-r--r--MiniUtils/Commands/JoinCommand.cs26
1 files changed, 26 insertions, 0 deletions
diff --git a/MiniUtils/Commands/JoinCommand.cs b/MiniUtils/Commands/JoinCommand.cs
new file mode 100644

index 0000000..1ed51b6 --- /dev/null +++ b/MiniUtils/Commands/JoinCommand.cs
@@ -0,0 +1,26 @@ +using LibMatrix.EventTypes.Spec.State.RoomInfo; +using LibMatrix.Services; +using LibMatrix.Utilities.Bot.Interfaces; + +namespace MiniUtils.Commands; + +public class JoinCommand(MiniUtilsConfiguration config, HomeserverProviderService hsProvider) : ICommand { + public string Name => "join"; + + public string[]? Aliases => []; + + public string Description => "Redact all user's events"; + + public bool Unlisted => false; + public async Task Invoke(CommandContext ctx) { + var profile = config.ExternalProfiles[ctx.Args[0]]; + var rhs = await hsProvider.GetAuthenticatedWithToken(profile.Homeserver, profile.AccessToken, enableServer: false, useGeneric: true); + + var joinRules = await ctx.Room.GetJoinRuleAsync(); + if (joinRules?.JoinRule is not RoomJoinRulesEventContent.JoinRules.Public) { + await ctx.Room.InviteUserAsync(rhs.UserId); + } + + _ = rhs.GetRoom(ctx.Room.RoomId).JoinAsync([ctx.Homeserver.ServerName]); + } +} \ No newline at end of file