public override BaseReactionSelection <TValue> Build() { if (Selectables == null) { throw new ArgumentException(nameof(Selectables)); } if (Selectables.Count == 0) { throw new InvalidOperationException("You need at least one selectable"); } if (AllowCancel && Selectables.Keys.Contains(CancelEmote)) { throw new InvalidOperationException("Found duplicate emotes! (Cancel Emote)"); } if (Selectables.Distinct().Count() != Selectables.Count) { throw new InvalidOperationException("Found duplicate emotes!"); } if (AllowCancel && CancelEmote == null) { throw new ArgumentNullException(nameof(CancelEmote)); } if (EnableDefaultSelectionDescription) { var builder = new StringBuilder(); foreach (var selectable in Selectables) { string option = StringConverter.Invoke(selectable.Value); builder.AppendLine($"{selectable.Key} - {option}"); } SelectionPage.AddField(Title, builder.ToString()); } return(new ReactionSelection <TValue>( Selectables.AsReadOnly(), Users?.AsReadOnly() ?? throw new ArgumentException(nameof(Users)), SelectionPage?.Build() ?? throw new ArgumentNullException(nameof(SelectionPage)), CancelledPage?.Build(), TimeoutedPage?.Build(), AllowCancel, CancelEmote, Deletion )); }
public override BaseMessageSelection <TValue> Build() { if (Selectables == null) { throw new ArgumentException(nameof(Selectables)); } if (Selectables.Count == 0) { throw new InvalidOperationException("You need at least one selectable"); } var selectableDictionary = new Dictionary <string[], TValue>(); var descriptionBuilder = new StringBuilder(); for (int i = 0; i < Selectables.Count; i++) { var selectable = Selectables[i]; string text = StringConverter.Invoke(selectable); selectableDictionary.Add(new string[] { $"{i + 1}", $"#{i + 1}", text, $"#{i + 1} - {text}" }, selectable); if (EnableDefaultSelectionDescription) { descriptionBuilder.AppendLine($"#{i + 1} - {text}"); } } if (AllowCancel) { selectableDictionary.Add(new string[] { $"{Selectables.Count + 1}", $"#{Selectables.Count + 1}", CancelMessage, $"#{Selectables.Count + 1} - {CancelMessage}" }, default); if (EnableDefaultSelectionDescription) { descriptionBuilder.Append($"#{Selectables.Count + 1} - {CancelMessage}"); } } if (EnableDefaultSelectionDescription) { SelectionPage.AddField(Title, descriptionBuilder.ToString()); } return(new MessageSelection <TValue>( selectableDictionary.AsReadOnly(), Users?.AsReadOnly() ?? throw new ArgumentException(nameof(Users)), SelectionPage?.Build() ?? throw new ArgumentNullException(nameof(SelectionPage)), CancelledPage?.Build(), TimeoutedPage?.Build(), AllowCancel, CancelMessage, Deletion )); }