le async has arrived
This commit is contained in:
parent
2eba089a21
commit
7bdf41a047
27 changed files with 282 additions and 309 deletions
SharpChat/ClientCommands
|
@ -1,6 +1,5 @@
|
|||
using SharpChat.Bans;
|
||||
using SharpChat.S2CPackets;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SharpChat.ClientCommands {
|
||||
public class PardonUserClientCommand(BansClient bansClient) : ClientCommand {
|
||||
|
@ -9,17 +8,17 @@ namespace SharpChat.ClientCommands {
|
|||
|| ctx.NameEquals("unban");
|
||||
}
|
||||
|
||||
public void Dispatch(ClientCommandContext ctx) {
|
||||
public async Task 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}"));
|
||||
await ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_NOT_ALLOWED, true, $"/{ctx.Name}"));
|
||||
return;
|
||||
}
|
||||
|
||||
string? unbanUserTarget = ctx.Args.FirstOrDefault();
|
||||
if(string.IsNullOrWhiteSpace(unbanUserTarget)) {
|
||||
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_FORMAT_ERROR));
|
||||
await ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.COMMAND_FORMAT_ERROR));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -32,18 +31,16 @@ namespace SharpChat.ClientCommands {
|
|||
unbanUserDisplay = unbanUser.UserName;
|
||||
}
|
||||
|
||||
Task.Run(async () => {
|
||||
BanInfo? banInfo = await bansClient.BanGetAsync(unbanUserTarget);
|
||||
if(banInfo?.Kind != BanKind.User) {
|
||||
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_NOT_BANNED, true, unbanUserDisplay));
|
||||
return;
|
||||
}
|
||||
BanInfo? banInfo = await bansClient.BanGetAsync(unbanUserTarget);
|
||||
if(banInfo?.Kind != BanKind.User) {
|
||||
await ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_NOT_BANNED, true, unbanUserDisplay));
|
||||
return;
|
||||
}
|
||||
|
||||
if(await bansClient.BanRevokeAsync(banInfo))
|
||||
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_UNBANNED, false, unbanUserDisplay));
|
||||
else
|
||||
ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_NOT_BANNED, true, unbanUserDisplay));
|
||||
}).Wait();
|
||||
if(await bansClient.BanRevokeAsync(banInfo))
|
||||
await ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_UNBANNED, false, unbanUserDisplay));
|
||||
else
|
||||
await ctx.Chat.SendTo(ctx.User, new CommandResponseS2CPacket(msgId, LCR.USER_NOT_BANNED, true, unbanUserDisplay));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue