using System.Threading.Tasks; using DeukBot4.MessageHandlers.CommandHandler.RequestStructure; using DeukBot4.MessageHandlers.Permissions; using Discord; using Discord.WebSocket; namespace DeukBot4.MessageHandlers.CommandHandler { public class ModeratorCommands : CommandContainerBase { public override string Name => "Moderator"; [Command("kick", PermissionLevel.Moderator)] [CommandParameters(ParameterMatcher.ParameterType.User, ParameterMatcher.ParameterType.Remainder)] [BlockUsageInPm] public async Task KickUser(CommandRequest request) { // get the server channel object out of message. Return if it's somehow not a server channel if (!(request.OriginalMessage.Channel is IGuildChannel channel)) return; // if no parameters are found, stop if (request.Parameters.Length == 0) return; // if the first parameter is empty, stop, this means it's not a valid user id if (string.IsNullOrWhiteSpace(request.Parameters[0].AsString())) return; // get the id, this parses the string to an id var id = request.Parameters[0].AsUlong(); // get the user using this id and the channel object. var user = await channel.Guild.GetUserAsync(id); // get the permissions of the user we want to kick var userPermissions = await PermissionValidator.GetUserPermissionLevel(request.OriginalMessage.Channel, (SocketUser) user); // if the user has sufficient permissions, or is this bot, warn the user that he's not allowed to do that, and stop if (userPermissions >= PermissionLevel.Helper || user.Id == Program.Client.CurrentUser.Id) { await request.OriginalMessage.Channel.SendMessageAsync("You are not allowed to kick that user"); return; } // see if a reason was given, use that if so var reason = string.Empty; if (request.Parameters.Length >= 2) { reason = request.Parameters[1].AsString(); } // and kick await user.KickAsync(reason); } } }