public override Paginator Build(int startPage = 0)
        {
            if (Pages.Count == 0)
            {
                throw new InvalidOperationException("A paginator needs at least one page!");
            }

            if (Emotes.Count == 0)
            {
                WithDefaultEmotes();
            }

            for (int i = 0; i < Pages.Count; i++)
            {
                Pages[i].WithPaginatorFooter(Footer, i, Pages.Count - 1, Users);
            }

            return(new StaticPaginator(Users?.AsReadOnly() ?? throw new ArgumentNullException(nameof(Users)),
                                       Emotes?.AsReadOnly() ?? throw new ArgumentNullException(nameof(Emotes)),
                                       CancelledEmbed?.Build(),
                                       TimeoutedEmbed?.Build(),
                                       Deletion,
                                       Pages?.Select(x => x.Build()).ToList().AsReadOnly() ?? throw new ArgumentNullException(nameof(Pages)),
                                       startPage));
        }
        /// <summary>
        /// Build the <see cref="ReactionSelectionBuilder{T}"/> to a immutable <see cref="ReactionSelection{T}"/>.
        /// </summary>
        /// <returns></returns>
        public override Selection <T, SocketReaction> Build()
        {
            if (Emotes.Count < Values.Count)
            {
                throw new InvalidOperationException("Value count larger than emote count! Please add more Emotes to the selection!");
            }
            if (Emotes.Contains(CancelEmote) == true)
            {
                throw new InvalidOperationException("Please remove the cancel emote from the selection emotes!");
            }

            if (EnableDefaultSelectionDescription == true)
            {
                var builder = new StringBuilder();

                for (int i = 0; i < Values.Count; i++)
                {
                    string possibility = StringConverter.Invoke(Values[i]);
                    builder.AppendLine($"{Emotes[i]} - {possibility}");
                }

                SelectionEmbed.AddField(Title, builder.ToString());
            }

            return(new ReactionSelection <T>(
                       Values?.AsReadOnlyCollection() ?? throw new ArgumentNullException(nameof(Values)),
                       Users?.AsReadOnlyCollection() ?? throw new ArgumentNullException(nameof(Users)),
                       SelectionEmbed?.Build() ?? throw new ArgumentNullException(nameof(SelectionEmbed)),
                       CancelledEmbed?.Build() ?? throw new ArgumentNullException(nameof(CancelledEmbed)),
                       TimeoutedEmbed?.Build() ?? throw new ArgumentNullException(nameof(TimeoutedEmbed)),
                       Deletion,
                       Emotes?.AsReadOnlyCollection() ?? throw new ArgumentNullException(nameof(Emotes)),
                       CancelEmote ?? throw new ArgumentNullException(nameof(CancelEmote)),
                       AllowCancel));
        }
示例#3
0
        /// <summary>
        /// Build the <see cref="MessageSelectionBuilder{T}"/> to a immutable <see cref="MessageSelection{T}"/>.
        /// </summary>
        /// <returns></returns>
        public override Selection <T, SocketMessage> Build()
        {
            if (Values.Count == 0)
            {
                throw new InvalidOperationException("Your Selection needs at least one value");
            }

            var possibilities = new List <string>();
            var sBuilder      = new StringBuilder();

            for (int i = 0; i < Values.Count; i++)
            {
                string possibility = StringConverter.Invoke(Values[i]);
                sBuilder.AppendLine($"#{i + 1} - {possibility}");
                possibilities.Add($"{i + 1}");
                possibilities.Add($"#{i + 1}");
                possibilities.Add(possibility);
                possibilities.Add($"#{i + 1} - {possibility}");
            }
            if (AllowCancel == true)
            {
                sBuilder.Append($"#{Values.Count + 1} - {CancelDisplayName}");
                possibilities.Add($"{Values.Count + 1}");
                possibilities.Add($"#{Values.Count + 1}");
                possibilities.Add(CancelDisplayName);
                possibilities.Add($"#{Values.Count + 1} - {CancelDisplayName}");
            }

            if (EnableDefaultSelectionDescription == true)
            {
                SelectionEmbed.AddField(Title, sBuilder.ToString());
            }

            return(new MessageSelection <T>(
                       Values?.AsReadOnlyCollection() ?? throw new ArgumentNullException(nameof(Values)),
                       Users?.AsReadOnlyCollection() ?? throw new ArgumentNullException(nameof(Users)),
                       SelectionEmbed?.Build() ?? throw new ArgumentNullException(nameof(SelectionEmbed)),
                       CancelledEmbed?.Build() ?? throw new ArgumentNullException(nameof(CancelledEmbed)),
                       TimeoutedEmbed?.Build() ?? throw new ArgumentNullException(nameof(TimeoutedEmbed)),
                       Deletion,
                       possibilities?.AsReadOnlyCollection(),
                       CancelDisplayName));
        }
示例#4
0
        public override Paginator Build(int startPage = 0)
        {
            if (Emotes.Count == 0)
            {
                WithDefaultEmotes();
            }

            return(new LazyPaginator(Users?.AsReadOnly() ?? throw new ArgumentNullException(nameof(Users)),
                                     Emotes?.AsReadOnly() ?? throw new ArgumentNullException(nameof(Emotes)),
                                     CancelledEmbed?.Build(),
                                     TimeoutedEmbed?.Build(),
                                     Deletion,
                                     AddPaginatorFooterAsync,
                                     startPage,
                                     MaxPageIndex));

            async Task <Page> AddPaginatorFooterAsync(int page)
            {
                var builder = await PageFactory.Invoke(page).ConfigureAwait(false);

                return(builder?.WithPaginatorFooter(Footer, page, MaxPageIndex, Users)
                       .Build());
            }
        }