Reintroduces separate contexts for users, channels, connections (now split into sessions and connections) and user-channel associations. It builds which is as much assurance as I can give about the stability of this commit, but its also the bare minimum of what i like to commit sooooo A lot of things still need to be broadcast through events throughout the application in order to keep states consistent but we'll cross that bridge when we get to it. I really need to stop using that phrase thingy, I'm overusing it.
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
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);
|
|
}
|
|
}
|