31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
using SharpChat.Misuzu;
|
|
using SharpChat.S2CPackets;
|
|
|
|
namespace SharpChat.Commands {
|
|
public class BanListCommand(MisuzuClient msz) : IChatCommand {
|
|
private readonly MisuzuClient Misuzu = msz ?? throw new ArgumentNullException(nameof(msz));
|
|
|
|
public bool IsMatch(ChatCommandContext ctx) {
|
|
return ctx.NameEquals("bans")
|
|
|| ctx.NameEquals("banned");
|
|
}
|
|
|
|
public void Dispatch(ChatCommandContext ctx) {
|
|
long msgId = ctx.Chat.RandomSnowflake.Next();
|
|
|
|
if(!ctx.User.Can(ChatUserPermissions.BanUser | ChatUserPermissions.KickUser)) {
|
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
|
return;
|
|
}
|
|
|
|
Task.Run(async () => {
|
|
MisuzuBanInfo[]? mbi = await Misuzu.GetBanListAsync();
|
|
|
|
if(mbi is null)
|
|
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.GENERIC_ERROR, true));
|
|
else
|
|
ctx.Chat.SendTo(ctx.User, new BanListS2CPacket(msgId, mbi));
|
|
}).Wait();
|
|
}
|
|
}
|
|
}
|