Exemplo n.º 1
0
 public async Task HandleCalculatorModalInput(string currencyCode, FiatCurrencyCalculatorModal calculatorModal)
 {
     await DeferAsync().ContinueWith(async(task) =>
     {
         try
         {
             bool isNumeric = decimal.TryParse(calculatorModal.Value.Replace(",", "."), NumberStyles.Any, DolarBotApiService.GetApiCulture(), out decimal amount);
             if (!isNumeric || amount <= 0)
             {
                 amount = 1;
             }
             List <WorldCurrencyCodeResponse> currenciesList = await FiatCurrencyService.GetWorldCurrenciesList();
             WorldCurrencyCodeResponse worldCurrencyCode     = currenciesList.FirstOrDefault(x => x.Code.Equals(currencyCode, StringComparison.OrdinalIgnoreCase));
             if (worldCurrencyCode != null)
             {
                 WorldCurrencyResponse currencyResponse = await FiatCurrencyService.GetCurrencyValue(currencyCode);
                 EmbedBuilder embed = await FiatCurrencyService.CreateWorldCurrencyEmbedAsync(currencyResponse, worldCurrencyCode.Name, amount);
                 await SendDeferredEmbedAsync(embed.Build());
             }
         }
         catch (Exception ex)
         {
             await SendDeferredErrorResponseAsync(ex);
         }
     });
 }
Exemplo n.º 2
0
        /// <summary>
        /// Replies with an embed message for a single currency value.
        /// </summary>
        /// <param name="currencyCode">The currency 3-digit code.</param>
        /// <param name="currenciesList">The collection of valid currency codes.</param>
        private async Task SendCurrencyValueAsync(string currencyCode, List <WorldCurrencyCodeResponse> currenciesList)
        {
            WorldCurrencyCodeResponse worldCurrencyCode = currenciesList.FirstOrDefault(x => x.Code.Equals(currencyCode, StringComparison.OrdinalIgnoreCase));

            if (worldCurrencyCode != null)
            {
                WorldCurrencyResponse currencyResponse = await FiatCurrencyService.GetCurrencyValue(currencyCode);

                EmbedBuilder embed = await FiatCurrencyService.CreateWorldCurrencyEmbedAsync(currencyResponse, worldCurrencyCode.Name);

                embed.AddCommandDeprecationNotice(Configuration);
                await ReplyAsync(embed : embed.Build());
            }
            else
            {
                await SendInvalidCurrencyCodeAsync(currencyCode);
            }
        }