Name adjustments and moved some things to the common lib.
This commit is contained in:
parent
b8ec381f3b
commit
0cc5d46ea9
50 changed files with 323 additions and 323 deletions
SharpChat/ClientCommands
37
SharpChat/ClientCommands/BanListClientCommand.cs
Normal file
37
SharpChat/ClientCommands/BanListClientCommand.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using SharpChat.Misuzu;
|
||||
using SharpChat.S2CPackets;
|
||||
|
||||
namespace SharpChat.ClientCommands {
|
||||
public class BanListClientCommand(MisuzuClient msz) : ClientCommand {
|
||||
private readonly MisuzuClient Misuzu = msz ?? throw new ArgumentNullException(nameof(msz));
|
||||
|
||||
public bool IsMatch(ClientCommandContext ctx) {
|
||||
return ctx.NameEquals("bans")
|
||||
|| ctx.NameEquals("banned");
|
||||
}
|
||||
|
||||
public void Dispatch(ClientCommandContext ctx) {
|
||||
long msgId = ctx.Chat.RandomSnowflake.Next();
|
||||
|
||||
if(!ctx.User.Can(UserPermissions.BanUser | UserPermissions.KickUser)) {
|
||||
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
||||
return;
|
||||
}
|
||||
|
||||
Task.Run(async () => {
|
||||
MisuzuBanInfo[]? mbis = await Misuzu.GetBanListAsync();
|
||||
if(mbis is null)
|
||||
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.GENERIC_ERROR, true));
|
||||
else
|
||||
ctx.Chat.SendTo(ctx.User, new BanListS2CPacket(
|
||||
msgId,
|
||||
mbis.Where(mbi => mbi.IsBanned && !mbi.HasExpired)
|
||||
.Select(mbi => new BanListS2CPacket.Entry(
|
||||
BanListS2CPacket.Type.UserName, // Misuzu currently only does username bans so we can just do this
|
||||
mbi.UserName ?? $"({mbi.UserId})"
|
||||
))
|
||||
));
|
||||
}).Wait();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue