sharp-chat/SharpChat.Protocol.IRC/ClientCommands/AwayCommand.cs

30 lines
854 B
C#
Raw Permalink Normal View History

2022-08-30 15:05:29 +00:00
using SharpChat.Users;
using System;
using System.Linq;
namespace SharpChat.Protocol.IRC.ClientCommands {
public class AwayCommand : IClientCommand {
public const string NAME = @"AWAY";
public string CommandName => NAME;
public bool RequireSession => true;
private UserManager Users { get; }
public AwayCommand(UserManager users) {
Users = users ?? throw new ArgumentNullException(nameof(users));
}
public void HandleCommand(ClientCommandContext ctx) {
string line = ctx.Arguments.FirstOrDefault() ?? string.Empty;
bool isAway = !string.IsNullOrEmpty(line);
Users.Update(
ctx.User,
status: isAway ? UserStatus.Away : UserStatus.Online,
statusMessage: line
);
}
}
}