public async Task <RuntimeResult> ListBansAsync()
        {
            var bans = await _bans.GetBansAsync(this.Context.Guild);

            var appearance = PaginatedAppearanceOptions.Default;

            appearance.Title = "Bans";
            appearance.Color = Color.Orange;

            var paginatedEmbed = await PaginatedEmbedFactory.PagesFromCollectionAsync
                                 (
                _feedback,
                _interactivity,
                this.Context.User,
                bans,
                async (eb, ban) =>
            {
                IUser?bannedUser = null;
                if (this.Context.Client is DiscordSocketClient socketClient)
                {
                    bannedUser = await socketClient.Rest.GetUserAsync((ulong)ban.User.DiscordID);
                }

                if (bannedUser is null)
                {
                    eb.WithTitle($"Ban #{ban.ID} for user with ID {ban.User.DiscordID}");
                }
                else
                {
                    eb.WithTitle($"Ban #{ban.ID} for {bannedUser.Username}:{bannedUser.Discriminator}");
                }

                var author = await this.Context.Guild.GetUserAsync((ulong)ban.Author.DiscordID);
                eb.WithAuthor(author);

                eb.WithDescription(ban.Reason);

                eb.AddField("Created", ban.CreatedAt);

                if (ban.CreatedAt != ban.UpdatedAt)
                {
                    eb.AddField("Last Updated", ban.UpdatedAt);
                }

                if (ban.IsTemporary)
                {
                    eb.AddField("Expires On", ban.ExpiresOn);
                }

                if (!(ban.MessageID is null))
                {
                    // TODO
                }
            },
                appearance : appearance
                                 );

            await _interactivity.SendInteractiveMessageAndDeleteAsync
            (
                this.Context.Channel,
                paginatedEmbed,
                TimeSpan.FromMinutes(5)
            );

            return(RuntimeCommandResult.FromSuccess());
        }
Beispiel #2
0
    public async Task <IResult> ListBansAsync()
    {
        var bans = await _bans.GetBansAsync(_context.GuildID.Value);

        var createPages = await PaginatedEmbedFactory.PagesFromCollectionAsync
                          (
            bans,
            async ban =>
        {
            var getBanAuthor = await _userAPI.GetUserAsync(ban.Author.DiscordID);
            if (!getBanAuthor.IsSuccess)
            {
                return(Result <Embed> .FromError(getBanAuthor));
            }

            var banAuthor = getBanAuthor.Entity;

            var getBannedUser = await _userAPI.GetUserAsync(ban.User.DiscordID);
            if (!getBannedUser.IsSuccess)
            {
                return(Result <Embed> .FromError(getBannedUser));
            }

            var bannedUser = getBanAuthor.Entity;

            var getBanAuthorAvatar = CDN.GetUserAvatarUrl(banAuthor);

            var embedFields = new List <IEmbedField>();
            var eb          = new Embed
            {
                Title  = $"Ban #{ban.ID} for {bannedUser.Username}:{bannedUser.Discriminator}",
                Colour = Color.Orange,
                Author = new EmbedAuthor(banAuthor.Username)
                {
                    Url = getBanAuthorAvatar.IsSuccess
                            ? getBanAuthorAvatar.Entity.ToString()
                            : default(Optional <string>)
                },
                Description = ban.Reason,
                Fields      = embedFields
            };

            embedFields.Add(new EmbedField("Created", ban.CreatedAt.Humanize()));

            if (ban.CreatedAt != ban.UpdatedAt)
            {
                embedFields.Add(new EmbedField("Last Updated", ban.UpdatedAt.Humanize()));
            }

            if (ban.ExpiresOn.HasValue)
            {
                embedFields.Add(new EmbedField("Expires On", ban.ExpiresOn.Humanize()));
            }

            if (ban.MessageID is not null)
            {
                // TODO
            }

            return(eb);
        }
                          );

        if (createPages.Any(p => !p.IsSuccess))
        {
            return(createPages.First(p => !p.IsSuccess));
        }

        var pages = createPages.Select(p => p.Entity).ToList();

        return((Result)await _feedback.SendContextualPaginatedMessageAsync
               (
                   _context.User.ID,
                   pages,
                   ct : this.CancellationToken
               ));
    }