2023-02-16 20:34:59 +00:00
|
|
|
|
using SharpChat.Misuzu;
|
2024-05-20 23:40:34 +00:00
|
|
|
|
using SharpChat.SockChat.PacketsS2C;
|
2023-02-16 20:34:59 +00:00
|
|
|
|
using System;
|
2024-05-10 18:29:48 +00:00
|
|
|
|
using System.Linq;
|
2023-02-16 20:34:59 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-05-20 23:40:34 +00:00
|
|
|
|
namespace SharpChat.SockChat.Commands {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public class BanListCommand : ISockChatClientCommand {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
private readonly MisuzuClient Misuzu;
|
|
|
|
|
|
|
|
|
|
public BanListCommand(MisuzuClient msz) {
|
2024-05-19 01:53:14 +00:00
|
|
|
|
Misuzu = msz;
|
2023-02-16 20:34:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public bool IsMatch(SockChatClientCommandContext ctx) {
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return ctx.NameEquals("bans")
|
|
|
|
|
|| ctx.NameEquals("banned");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-20 23:00:47 +00:00
|
|
|
|
public void Dispatch(SockChatClientCommandContext ctx) {
|
2024-05-19 02:17:51 +00:00
|
|
|
|
if(!ctx.User.Permissions.HasFlag(UserPermissions.KickUser)
|
|
|
|
|
&& !ctx.User.Permissions.HasFlag(UserPermissions.BanUser)) {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new CommandNotAllowedErrorS2CPacket(ctx.Name));
|
2023-02-16 20:34:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Task.Run(async () => {
|
2024-05-20 23:00:47 +00:00
|
|
|
|
ctx.Chat.SendTo(ctx.User, new BanListResponseS2CPacket(
|
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
|
2024-05-10 18:29:48 +00:00
|
|
|
|
).ToArray()
|
2023-02-16 20:34:59 +00:00
|
|
|
|
));
|
|
|
|
|
}).Wait();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|