/// <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));
        }
Exemplo n.º 2
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));
        }