about summary refs log tree commit diff
path: root/MiniUtils/Commands/JoinCommand.cs
blob: 1ed51b645f8b1882d418e1190c77a743817887f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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]);
    }
}