sharp-chat/SharpChat.SockChat/Commands/UserAFKCommand.cs

31 lines
971 B
C#

using SharpChat.Events;
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.Events.Dispatch(
"user:status",
ctx.User,
new UserStatusUpdateEventData(UserStatus.Away, statusText)
);
}
}
}