2024-05-19 21:02:17 +00:00
|
|
|
|
using System.Linq;
|
2022-08-30 15:00:58 +00:00
|
|
|
|
|
2024-05-20 23:40:34 +00:00
|
|
|
|
namespace SharpChat.SockChat.Commands {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public class UserAFKCommand : ISockChatClientCommand {
|
2023-02-08 03:17:07 +00:00
|
|
|
|
private const string DEFAULT = "AFK";
|
2022-08-30 15:00:58 +00:00
|
|
|
|
private const int MAX_LENGTH = 5;
|
|
|
|
|
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public bool IsMatch(SockChatClientCommandContext ctx) {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return ctx.NameEquals("afk");
|
2022-08-30 15:00:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public void Dispatch(SockChatClientCommandContext ctx) {
|
2024-05-10 19:18:55 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2023-02-22 00:28:53 +00:00
|
|
|
|
ctx.Chat.UpdateUser(
|
|
|
|
|
ctx.User,
|
2024-05-19 02:17:51 +00:00
|
|
|
|
status: UserStatus.Away,
|
2023-02-22 00:28:53 +00:00
|
|
|
|
statusText: statusText
|
|
|
|
|
);
|
2022-08-30 15:00:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|