sharp-chat/SharpChat/Commands/AFKCommand.cs

29 lines
904 B
C#
Raw Normal View History

using SharpChat.Packet;
2022-08-30 15:00:58 +00:00
using System.Linq;
namespace SharpChat.Commands {
public class AFKCommand : IChatCommand {
private const string DEFAULT = "AFK";
2022-08-30 15:00:58 +00:00
private const int MAX_LENGTH = 5;
public bool IsMatch(ChatCommandContext ctx) {
return ctx.NameEquals("afk");
2022-08-30 15:00:58 +00:00
}
public void Dispatch(ChatCommandContext ctx) {
string statusText = ctx.Args.FirstOrDefault();
2022-08-30 15:00:58 +00:00
if(string.IsNullOrWhiteSpace(statusText))
statusText = DEFAULT;
else {
statusText = statusText.Trim();
if(statusText.Length > MAX_LENGTH)
2023-02-07 15:01:56 +00:00
statusText = statusText[..MAX_LENGTH].Trim();
2022-08-30 15:00:58 +00:00
}
ctx.User.Status = ChatUserStatus.Away;
ctx.User.StatusMessage = statusText;
ctx.Channel.Send(new UserUpdatePacket(ctx.User));
2022-08-30 15:00:58 +00:00
}
}
}