sharp-chat/SharpChat/Commands/BanListCommand.cs

37 lines
1.3 KiB
C#
Raw Normal View History

using SharpChat.Misuzu;
using SharpChat.Packet;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace SharpChat.Commands {
public class BanListCommand : IChatCommand {
private readonly MisuzuClient Misuzu;
public BanListCommand(MisuzuClient msz) {
Misuzu = msz ?? throw new ArgumentNullException(nameof(msz));
}
public bool IsMatch(ChatCommandContext ctx) {
return ctx.NameEquals("bans")
|| ctx.NameEquals("banned");
}
public void Dispatch(ChatCommandContext ctx) {
if(!ctx.User.Permissions.HasFlag(ChatUserPermissions.KickUser)
&& !ctx.User.Permissions.HasFlag(ChatUserPermissions.BanUser)) {
ctx.Chat.SendTo(ctx.User, new CommandNotAllowedErrorPacket(ctx.Name));
return;
}
Task.Run(async () => {
2024-05-14 22:17:25 +00:00
ctx.Chat.SendTo(ctx.User, new BanListResponsePacket(
2024-05-10 19:18:55 +00:00
(await Misuzu.GetBanListAsync() ?? Array.Empty<MisuzuBanInfo>()).Select(
ban => string.IsNullOrEmpty(ban.UserName) ? (string.IsNullOrEmpty(ban.RemoteAddress) ? string.Empty : ban.RemoteAddress) : ban.UserName
).ToArray()
));
}).Wait();
}
}
}