36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
using SharpChat.Misuzu;
|
|
using SharpChat.PacketsS2C;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SharpChat.Commands {
|
|
public class BanListCommand : ISockChatClientCommand {
|
|
private readonly MisuzuClient Misuzu;
|
|
|
|
public BanListCommand(MisuzuClient msz) {
|
|
Misuzu = msz;
|
|
}
|
|
|
|
public bool IsMatch(SockChatClientCommandContext ctx) {
|
|
return ctx.NameEquals("bans")
|
|
|| ctx.NameEquals("banned");
|
|
}
|
|
|
|
public void Dispatch(SockChatClientCommandContext ctx) {
|
|
if(!ctx.User.Permissions.HasFlag(UserPermissions.KickUser)
|
|
&& !ctx.User.Permissions.HasFlag(UserPermissions.BanUser)) {
|
|
ctx.Chat.SendTo(ctx.User, new CommandNotAllowedErrorS2CPacket(ctx.Name));
|
|
return;
|
|
}
|
|
|
|
Task.Run(async () => {
|
|
ctx.Chat.SendTo(ctx.User, new BanListResponseS2CPacket(
|
|
(await Misuzu.GetBanListAsync() ?? Array.Empty<MisuzuBanInfo>()).Select(
|
|
ban => string.IsNullOrEmpty(ban.UserName) ? (string.IsNullOrEmpty(ban.RemoteAddress) ? string.Empty : ban.RemoteAddress) : ban.UserName
|
|
).ToArray()
|
|
));
|
|
}).Wait();
|
|
}
|
|
}
|
|
}
|