2023-02-16 20:34:59 +00:00
|
|
|
|
using SharpChat.Packet;
|
|
|
|
|
|
|
|
|
|
namespace SharpChat.Commands {
|
2024-05-14 22:17:25 +00:00
|
|
|
|
public class ChannelPasswordCommand : IChatCommand {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
public bool IsMatch(ChatCommandContext ctx) {
|
|
|
|
|
return ctx.NameEquals("pwd")
|
|
|
|
|
|| ctx.NameEquals("password");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispatch(ChatCommandContext ctx) {
|
2023-02-22 00:28:53 +00:00
|
|
|
|
if(!ctx.User.Can(ChatUserPermissions.SetChannelPassword) || ctx.Channel.IsOwner(ctx.User)) {
|
2024-05-14 19:11:09 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new CommandNotAllowedErrorPacket(ctx.Name));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
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());
|
2023-02-16 20:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|