2025-05-03 02:49:51 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using SharpChat.Channels;
|
|
|
|
using SharpChat.Sessions;
|
|
|
|
using SharpChat.Users;
|
2025-04-27 02:53:56 +00:00
|
|
|
|
|
|
|
namespace SharpChat;
|
2023-02-16 21:34:59 +01:00
|
|
|
|
2025-04-26 23:15:54 +00:00
|
|
|
public class ClientCommandContext {
|
|
|
|
public string Name { get; }
|
|
|
|
public string[] Args { get; }
|
|
|
|
public Context Chat { get; }
|
|
|
|
public User User { get; }
|
2025-05-03 02:49:51 +00:00
|
|
|
public Session Session { get; }
|
|
|
|
public SockChatConnection Connection { get; }
|
2025-04-26 23:15:54 +00:00
|
|
|
public Channel Channel { get; }
|
2025-05-03 02:49:51 +00:00
|
|
|
public ILogger Logger => Session.Logger;
|
2023-02-16 21:34:59 +01:00
|
|
|
|
2025-04-26 23:15:54 +00:00
|
|
|
public ClientCommandContext(
|
|
|
|
string text,
|
|
|
|
Context chat,
|
|
|
|
User user,
|
2025-05-03 02:49:51 +00:00
|
|
|
Session session,
|
|
|
|
SockChatConnection connection,
|
2025-04-26 23:15:54 +00:00
|
|
|
Channel channel
|
|
|
|
) {
|
|
|
|
ArgumentNullException.ThrowIfNull(text);
|
2023-02-16 21:34:59 +01:00
|
|
|
|
2025-04-26 23:15:54 +00:00
|
|
|
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));
|
2025-05-03 02:49:51 +00:00
|
|
|
Session = session ?? throw new ArgumentNullException(nameof(session));
|
2023-02-16 21:34:59 +01:00
|
|
|
|
2025-04-26 23:15:54 +00:00
|
|
|
string[] parts = text[1..].Split(' ');
|
|
|
|
Name = parts.First().Replace(".", string.Empty);
|
|
|
|
Args = [.. parts.Skip(1)];
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool NameEquals(string name) {
|
2025-05-03 02:49:51 +00:00
|
|
|
return Name.Equals(name, StringComparison.Ordinal);
|
2023-02-16 21:34:59 +01:00
|
|
|
}
|
|
|
|
}
|