sharp-chat/SharpChat.Protocol.SockChat/Commands/BanListCommand.cs

38 lines
1.3 KiB
C#
Raw Permalink Normal View History

2022-08-30 15:05:29 +00:00
using SharpChat.Bans;
using SharpChat.Protocol.SockChat.Packets;
using SharpChat.Users;
using System;
using System.Collections.Generic;
namespace SharpChat.Protocol.SockChat.Commands {
public class BanListCommand : ICommand {
private BanManager Bans { get; }
private IUser Sender { get; }
public BanListCommand(BanManager bans, IUser sender) {
Bans = bans ?? throw new ArgumentNullException(nameof(bans));
Sender = sender ?? throw new ArgumentNullException(nameof(sender));
}
public bool IsCommandMatch(string name, IEnumerable<string> args)
=> name is @"bans" or @"banned";
public bool DispatchCommand(CommandContext ctx) {
if(!ctx.User.Can(UserPermissions.BanUser | UserPermissions.KickUser)) {
ctx.Connection.SendPacket(new CommandNotAllowedErrorPacket(Sender, ctx.Args));
return true;
}
Bans.GetBanList(b => {
ctx.Connection.SendPacket(new BanListPacket(Sender, b));
}, ex => {
Logger.Write(@"Error during ban list retrieval.");
Logger.Write(ex);
ctx.Connection.SendPacket(new GenericErrorPacket(Sender));
});
return true;
}
}
}