public async Task <ButtonParsed> GetFeatureConfig(string featureName) { var config = _featureConfig.Items?.FirstOrDefault(item => item.Key == featureName); var buttonMarkup = InlineKeyboardMarkup.Empty(); var buttonParsed = new ButtonParsed { FeatureName = featureName, Markup = buttonMarkup }; if (config == null) { _logger.LogWarning("ButtonConfig Not Found: {Key}", featureName); return(buttonParsed); } var currentEnvironment = await _botService.CurrentEnvironment(); var mergedCaption = config.Captions? .Where(caption => caption.MinimumLevel <= currentEnvironment) .Select(caption => caption.Sections.JoinStr(" ")) .JoinStr("\n\n"); List <IEnumerable <InlineKeyboardButton> > button = null; if (config.Buttons != null) { button = config .Buttons .Select ( x => x .Select(y => InlineKeyboardButton.WithUrl(y.Text, y.Url.ToString())) ) .ToList(); buttonMarkup = new InlineKeyboardMarkup(button); } buttonParsed.IsEnabled = config.IsEnabled; buttonParsed.AllowsAt = config.AllowsAt; buttonParsed.ExceptsAt = config.ExceptsAt; buttonParsed.Caption = mergedCaption; buttonParsed.Markup = buttonMarkup; buttonParsed.KeyboardButton = button; buttonParsed.IsApplyRateLimit = config.RateLimitSpan != null; if (buttonParsed.IsApplyRateLimit) { buttonParsed.RateLimitTimeSpan = config.RateLimitSpan.ToTimeSpan(); buttonParsed.NextAvailable = buttonParsed.RateLimitTimeSpan.ToDateTime(useUtc: true); } return(buttonParsed); }
public async Task <ButtonParsed> GetButtonConfig(string key) { var items = GetButtonConfigAll(); var item = items.FirstOrDefault(buttonItem => buttonItem.Key == key); var buttonMarkup = InlineKeyboardMarkup.Empty(); var buttonParsed = new ButtonParsed { Markup = buttonMarkup }; if (item == null) { _logger.LogWarning("ButtonConfig Not Found: {Key}", key); return(buttonParsed); } var currentEnvironment = await CurrentEnvironment(); var mergedCaption = item.Data?.Captions? .Where(caption => caption.MinimumLevel <= currentEnvironment) .Select(caption => caption.Sections.JoinStr("\n\n")) .JoinStr("\n\n"); if (item?.Data?.Buttons != null) { buttonMarkup = new InlineKeyboardMarkup( item .Data .Buttons .Select( x => x .Select(y => InlineKeyboardButton.WithUrl(y.Text, y.Url)) ) ); } buttonParsed.Caption = mergedCaption; buttonParsed.Markup = buttonMarkup; return(buttonParsed); }