using System.Linq; namespace SharpChat.SockChat.Commands { public class UserAFKCommand : ISockChatClientCommand { private const string DEFAULT = "AFK"; private const int MAX_LENGTH = 5; public bool IsMatch(SockChatClientCommandContext ctx) { return ctx.NameEquals("afk"); } public void Dispatch(SockChatClientCommandContext ctx) { string? statusText = ctx.Args.FirstOrDefault(); if(string.IsNullOrWhiteSpace(statusText)) statusText = DEFAULT; else { statusText = statusText.Trim(); if(statusText.Length > MAX_LENGTH) statusText = statusText[..MAX_LENGTH].Trim(); } ctx.Chat.UpdateUser( ctx.User, status: UserStatus.Away, statusText: statusText ); } } }