public async Task Ban(ICommand command, ILogger logger) { if (command["Users"].Repeats.Count > 10) { throw new Framework.Exceptions.IncorrectParametersCommandException("The maximum number of bans per command is 10.", false); } var banningUser = (IGuildUser)command.Author; var banningUserTopRole = banningUser.GetTopRole()?.Position ?? 0; var result = new StringBuilder(); var bans = new Dictionary <ulong, (Task Task, string User, ulong UserId)>(); foreach (var id in command["Users"].Repeats.Select(x => x.AsMentionOrId.Value)) { string userName; var guildUser = await command.Guild.GetUserAsync(id) ?? await _userFetcher.FetchGuildUserAsync(command.GuildId, id); if (guildUser != null) { userName = $"{guildUser.GetFullName()} ({guildUser.Id})"; if (!banningUser.IsOwner() && (banningUserTopRole <= (guildUser.GetTopRole()?.Position ?? 0) || guildUser.IsOwner())) { result.AppendLine(_communicator.FormatFailure($"You don't have permission to ban user `{userName}` on this server.")); continue; } } else { var user = (IUser)_client.GetUser(id) ?? await _userFetcher.FetchUserAsync(id); userName = user != null ? $"{user.GetFullName()} ({user.Id})" : id.ToString(); } bans[id] = (command.Guild.AddBanAsync(id, Math.Min(command["DeleteDays"].AsInt ?? 0, 7), command["Reason"].HasValue ? command["Reason"].AsString : null), userName, id); } try { await Task.WhenAll(bans.Select(x => x.Value.Task)); } catch (Exception) { // Handled below } foreach (var ban in bans.Values) { if (ban.Task.Exception != null && ban.Task.Exception.InnerException is Discord.Net.HttpException ex && ex.HttpCode == HttpStatusCode.Forbidden) { result.AppendLine(_communicator.FormatFailure($"Missing permissions to ban user `{ban.User}`.")); }
public async Task Server(ICommand command) { var guild = (SocketGuild)command.Guild; var embed = new EmbedBuilder() .WithTitle(guild.Name) .WithUrl(guild.GetAnimatedIconUrl() ?? guild.IconUrl) .WithThumbnailUrl(guild.GetAnimatedIconUrl() ?? guild.IconUrl) .WithFooter($"#{guild.Id} • times in UTC"); var owner = (IGuildUser)guild.Owner ?? await _userFetcher.FetchGuildUserAsync(guild.Id, guild.OwnerId); embed.AddField(x => x.WithName("Created on").WithValue($"{guild.CreatedAt.ToUniversalTime().ToString("f", GlobalDefinitions.Culture)} ({Math.Floor((DateTimeOffset.Now - guild.CreatedAt).TotalDays)} days ago)")); embed.AddField(x => x.WithName("Owner").WithValue($"{owner.Username}#{owner.Discriminator}")); embed.AddField(x => x.WithName("Members").WithValue($"{guild.MemberCount}").WithIsInline(true)); embed.AddField(x => x.WithName("Channels").WithValue($"{guild.TextChannels.Count()} text, {guild.VoiceChannels.Count()} voice").WithIsInline(true)); embed.AddField(x => x.WithName("Emotes").WithValue($"{guild.Emotes.Where(y => !y.Animated).Count()} static, {guild.Emotes.Where(y => y.Animated).Count()} animated").WithIsInline(true)); await command.Reply(embed.Build()); }