25 lines
902 B
C#
25 lines
902 B
C#
using SharpChat.Packet;
|
|
|
|
namespace SharpChat.Commands {
|
|
public class ChannelPasswordCommand : IChatCommand {
|
|
public bool IsMatch(ChatCommandContext ctx) {
|
|
return ctx.NameEquals("pwd")
|
|
|| ctx.NameEquals("password");
|
|
}
|
|
|
|
public void Dispatch(ChatCommandContext ctx) {
|
|
if(!ctx.User.Permissions.HasFlag(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;
|
|
|
|
ctx.Chat.UpdateChannel(ctx.Channel, password: chanPass);
|
|
ctx.Chat.SendTo(ctx.User, new ChannelPasswordChangedResponsePacket());
|
|
}
|
|
}
|
|
}
|