Split out the Flashii interaction code into a separate library.

This commit is contained in:
flash 2025-04-26 19:42:23 +00:00
commit 2eba089a21
Signed by: flash
GPG key ID: 2C9C2C574D47FE3E
55 changed files with 769 additions and 552 deletions
SharpChat/ClientCommands

View file

@ -1,10 +1,8 @@
using SharpChat.Misuzu;
using SharpChat.Bans;
using SharpChat.S2CPackets;
namespace SharpChat.ClientCommands {
public class BanListClientCommand(MisuzuClient msz) : ClientCommand {
private readonly MisuzuClient Misuzu = msz ?? throw new ArgumentNullException(nameof(msz));
public class BanListClientCommand(BansClient bansClient) : ClientCommand {
public bool IsMatch(ClientCommandContext ctx) {
return ctx.NameEquals("bans")
|| ctx.NameEquals("banned");
@ -19,18 +17,15 @@ namespace SharpChat.ClientCommands {
}
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
try {
BanInfo[] banInfos = await bansClient.BanGetListAsync();
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})"
))
banInfos.Select(bi => new BanListS2CPacket.Entry(bi.Kind, bi.ToString()))
));
} catch(Exception) {
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.GENERIC_ERROR, true));
}
}).Wait();
}
}