sharp-chat/SharpChat/Commands/ChannelPasswordCommand.cs

26 lines
885 B
C#
Raw Normal View History

using SharpChat.Packet;
namespace SharpChat.Commands {
2024-05-14 22:17:25 +00:00
public class ChannelPasswordCommand : IChatCommand {
public bool IsMatch(ChatCommandContext ctx) {
return ctx.NameEquals("pwd")
|| ctx.NameEquals("password");
}
public void Dispatch(ChatCommandContext ctx) {
if(!ctx.User.Can(ChatUserPermissions.SetChannelPassword) || ctx.Channel.IsOwner(ctx.User)) {
ctx.Chat.SendTo(ctx.User, new CommandNotAllowedErrorPacket(ctx.Name));
return;
}
string chanPass = string.Join(' ', ctx.Args).Trim();
if(string.IsNullOrWhiteSpace(chanPass))
chanPass = string.Empty;
2023-02-19 22:27:08 +00:00
ctx.Chat.UpdateChannel(ctx.Channel, password: chanPass);
2024-05-14 22:17:25 +00:00
ctx.Chat.SendTo(ctx.User, new ChannelPasswordChangedResponsePacket());
}
}
}