sharp-chat/SharpChat/Commands/UserAFKCommand.cs

29 lines
877 B
C#

using System.Linq;
namespace SharpChat.Commands {
public class UserAFKCommand : IUserCommand {
private const string DEFAULT = "AFK";
private const int MAX_LENGTH = 5;
public bool IsMatch(UserCommandContext ctx) {
return ctx.NameEquals("afk");
}
public void Dispatch(UserCommandContext 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
);
}
}
}