public async Task HandleCalculatorModalInput(string currencyCode, VzlaCalculatorModal 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;
                    }

                    Currencies currency = Enum.Parse <Currencies>(currencyCode);
                    VzlaResponse result = currency switch
                    {
                        Currencies.Dolar => await VzlaService.GetDollarRates(),
                        Currencies.Euro => await VzlaService.GetEuroRates(),
                        _ => throw new NotImplementedException(),
                    };
                    if (result != null)
                    {
                        EmbedBuilder embed = await VzlaService.CreateVzlaEmbedAsync(result, amount);
                        await SendDeferredEmbedAsync(embed.Build());
                    }
                    else
                    {
                        await SendDeferredApiErrorResponseAsync();
                    }
                }
                catch (Exception ex)
                {
                    await SendDeferredErrorResponseAsync(ex);
                }
            });
        }
示例#2
0
        public async Task GetDollarRatesAsync()
        {
            try
            {
                using (Context.Channel.EnterTypingState())
                {
                    VzlaResponse result = await VzlaService.GetDollarRates();

                    if (result != null)
                    {
                        EmbedBuilder embed = await VzlaService.CreateVzlaEmbedAsync(result);

                        embed.AddCommandDeprecationNotice(Configuration);
                        await ReplyAsync(embed : embed.Build());
                    }
                    else
                    {
                        await ReplyAsync(REQUEST_ERROR_MESSAGE);
                    }
                }
            }
            catch (Exception ex)
            {
                await SendErrorReply(ex);
            }
        }