38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|