using SharpChat.Users; using System.Globalization; using System.Text; namespace SharpChat.ClientCommands; public class AFKClientCommand : ClientCommand { private const string DEFAULT = "AFK"; public const int MAX_GRAPHEMES = 5; public const int MAX_BYTES = MAX_GRAPHEMES * 10; public bool IsMatch(ClientCommandContext ctx) { return ctx.NameEquals("afk"); } public async Task Dispatch(ClientCommandContext ctx) { string? statusText = ctx.Args.FirstOrDefault(); statusText = string.IsNullOrWhiteSpace(statusText) ? DEFAULT : statusText.TruncateIfTooLong(MAX_GRAPHEMES, MAX_BYTES).Trim(); await ctx.Chat.UpdateUser( ctx.User, status: UserStatus.Away, statusText: statusText ); } }