2023-02-16 21:34:59 +01:00
|
|
|
|
using SharpChat.Packet;
|
2022-08-30 17:00:58 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace SharpChat.Commands {
|
|
|
|
|
public class AFKCommand : IChatCommand {
|
2023-02-08 04:17:07 +01:00
|
|
|
|
private const string DEFAULT = "AFK";
|
2022-08-30 17:00:58 +02:00
|
|
|
|
private const int MAX_LENGTH = 5;
|
|
|
|
|
|
2023-02-16 21:34:59 +01:00
|
|
|
|
public bool IsMatch(ChatCommandContext ctx) {
|
|
|
|
|
return ctx.NameEquals("afk");
|
2022-08-30 17:00:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-16 21:34:59 +01:00
|
|
|
|
public void Dispatch(ChatCommandContext ctx) {
|
|
|
|
|
string statusText = ctx.Args.FirstOrDefault();
|
2022-08-30 17:00:58 +02:00
|
|
|
|
if(string.IsNullOrWhiteSpace(statusText))
|
|
|
|
|
statusText = DEFAULT;
|
|
|
|
|
else {
|
|
|
|
|
statusText = statusText.Trim();
|
|
|
|
|
if(statusText.Length > MAX_LENGTH)
|
2023-02-07 16:01:56 +01:00
|
|
|
|
statusText = statusText[..MAX_LENGTH].Trim();
|
2022-08-30 17:00:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-22 01:28:53 +01:00
|
|
|
|
ctx.Chat.UpdateUser(
|
|
|
|
|
ctx.User,
|
|
|
|
|
status: ChatUserStatus.Away,
|
|
|
|
|
statusText: statusText
|
|
|
|
|
);
|
2022-08-30 17:00:58 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|