sharp-chat/SharpChat/Commands/AFKCommand.cs

28 lines
916 B
C#

using SharpChat.Packet;
using System.Linq;
namespace SharpChat.Commands {
public class AFKCommand : IChatCommand {
private const string DEFAULT = "AFK";
private const int MAX_LENGTH = 5;
public bool IsMatch(ChatCommandContext ctx) {
return ctx.NameEquals("afk");
}
public void Dispatch(ChatCommandContext 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.User.Status = ChatUserStatus.Away;
ctx.User.StatusMessage = statusText;
ctx.Chat.SendTo(ctx.Channel, new UserUpdatePacket(ctx.User));
}
}
}