about summary refs log tree commit diff
path: root/Utilities/LibMatrix.Utilities.Bot/Interfaces/CommandContext.cs
blob: 94ea846f5e5646c849bf15c42cff648e615c9d53 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using LibMatrix.EventTypes.Spec;
using LibMatrix.Homeservers;
using LibMatrix.RoomTypes;

namespace LibMatrix.Utilities.Bot.Interfaces;

public class CommandContext {
    public required GenericRoom Room { get; set; }
    public required StateEventResponse MessageEvent { get; set; }

    public string MessageContentWithoutReply =>
        (MessageEvent.TypedContent as RoomMessageEventContent)!
        .Body.Split('\n')
        .SkipWhile(x => x.StartsWith(">"))
        .Aggregate((x, y) => $"{x}\n{y}");

    public string CommandName => MessageContentWithoutReply.Split(' ')[0][1..];
    public string[] Args => MessageContentWithoutReply.Split(' ')[1..];
    public required AuthenticatedHomeserverGeneric Homeserver { get; set; }

    public async Task<EventIdResponse> Reply(RoomMessageEventContent content) => await Room.SendMessageEventAsync(content);
}