Exemplo n.º 1
0
        public async Task ListPinnedMessagesAsync(CommandContext ctx,
                                                  [Description("desc-chn-pins")] DiscordChannel?chn = null)
        {
            chn ??= ctx.Channel;
            if (!chn.PermissionsFor(ctx.Member).HasPermission(Permissions.AccessChannels))
            {
                throw new CommandFailedException(ctx, "cmd-chk-perms-usr", Permissions.AccessChannels);
            }

            IReadOnlyList <DiscordMessage> pinned = await ctx.Channel.GetPinnedMessagesAsync();

            if (!pinned.Any())
            {
                throw new CommandFailedException(ctx, "cmd-err-pinned-none");
            }

            IEnumerable <Page> pages = pinned.Select(m => new Page(
                                                         $"{Formatter.Bold(m.Author.Username)} @ {this.Localization.GetLocalizedTimeString(ctx.Guild.Id, m.CreationTimestamp)}",
                                                         // TODO
                                                         GetFirstEmbedOrDefaultAsBuilder(m).AddField("URL", Formatter.MaskedUrl(this.Localization.GetString(ctx.Guild.Id, "str-jumplink"), m.JumpLink))
                                                         ));

            await ctx.Client.GetInteractivity().SendPaginatedMessageAsync(ctx.Channel, ctx.User, pages);

            DiscordEmbedBuilder GetFirstEmbedOrDefaultAsBuilder(DiscordMessage m)
            {
                DiscordEmbed?em = m.Embeds.FirstOrDefault();

                if (em is { })
                {
                    return(new DiscordEmbedBuilder(em));
                }

                var emb = new LocalizedEmbedBuilder(this.Localization, ctx.Guild.Id);

                if (!string.IsNullOrWhiteSpace(m.Content))
                {
                    emb.WithDescription(m.Content);
                }
                return(emb.GetBuilder());
            }