sharp-chat/SharpChat/ClientCommandContext.cs

43 lines
1.3 KiB
C#
Raw Permalink Normal View History

using Microsoft.Extensions.Logging;
using SharpChat.Channels;
using SharpChat.Sessions;
using SharpChat.Users;
namespace SharpChat;
public class ClientCommandContext {
public string Name { get; }
public string[] Args { get; }
public Context Chat { get; }
public User User { get; }
public Session Session { get; }
public SockChatConnection Connection { get; }
public Channel Channel { get; }
public ILogger Logger => Session.Logger;
public ClientCommandContext(
string text,
Context chat,
User user,
Session session,
SockChatConnection connection,
Channel channel
) {
ArgumentNullException.ThrowIfNull(text);
Chat = chat ?? throw new ArgumentNullException(nameof(chat));
User = user ?? throw new ArgumentNullException(nameof(user));
Connection = connection ?? throw new ArgumentNullException(nameof(connection));
Channel = channel ?? throw new ArgumentNullException(nameof(channel));
Session = session ?? throw new ArgumentNullException(nameof(session));
string[] parts = text[1..].Split(' ');
Name = parts.First().Replace(".", string.Empty);
Args = [.. parts.Skip(1)];
}
public bool NameEquals(string name) {
return Name.Equals(name, StringComparison.Ordinal);
}
}