Пример #1
0
        public async Task GetCurrencies
        (
            [Summary("Código de la moneda a mostrar. Si no se especifica, mostrará la lista de todos los códigos de monedas disponibles.")]
            string codigo = null
        )
        {
            try
            {
                IDisposable typingState = Context.Channel.EnterTypingState();
                List <WorldCurrencyCodeResponse> currenciesList = await FiatCurrencyService.GetWorldCurrenciesList();

                if (codigo != null)
                {
                    string currencyCode = Format.Sanitize(codigo).RemoveFormat(true).ToUpper().Trim();
                    await SendCurrencyValueAsync(currencyCode, currenciesList);

                    typingState.Dispose();
                }
                else
                {
                    string commandPrefix   = Configuration["commandPrefix"];
                    int    replyTimeout    = Convert.ToInt32(Configuration["interactiveMessageReplyTimeout"]);
                    string currencyCommand = GetType().GetMethod(nameof(GetCurrencies)).GetCustomAttributes(true).OfType <CommandAttribute>().First().Text;

                    List <EmbedBuilder> embeds = FiatCurrencyService.CreateWorldCurrencyListEmbedAsync(currenciesList, currencyCommand, Context.User.Username, true);
                    await SendPagedReplyAsync(embeds, true);

                    typingState.Dispose();

                    SocketMessage userResponse = await NextMessageAsync(timeout : TimeSpan.FromSeconds(replyTimeout));

                    if (userResponse != null)
                    {
                        string currencyCode = Format.Sanitize(userResponse.Content).RemoveFormat(true).Trim();
                        if (!currencyCode.StartsWith(commandPrefix))
                        {
                            using (Context.Channel.EnterTypingState())
                            {
                                await SendCurrencyValueAsync(currencyCode, currenciesList);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                await SendErrorReply(ex);
            }
        }
Пример #2
0
        public async Task GetCurrenciesAsync(
            [Summary("moneda", "Código de la moneda. Si no se especifica, mostrará todos los códigos de monedas disponibles.")]
            [Autocomplete(typeof(FiatCurrencyCodeAutocompleteHandler))]
            string codigo = null
            )
        {
            await DeferAsync().ContinueWith(async(task) =>
            {
                try
                {
                    List <WorldCurrencyCodeResponse> currenciesList = await FiatCurrencyService.GetWorldCurrenciesList();

                    if (codigo != null)
                    {
                        string currencyCode = Format.Sanitize(codigo).ToUpper().Trim();
                        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);
                            await SendDeferredEmbedAsync(embed.Build(), components: new CalculatorComponentBuilder(currencyCode, CalculatorTypes.FiatCurrency, Configuration).Build());
                        }
                        else
                        {
                            await SendInvalidCurrencyCodeAsync(currencyCode);
                        }
                    }
                    else
                    {
                        string commandPrefix   = Configuration["commandPrefix"];
                        int replyTimeout       = Convert.ToInt32(Configuration["interactiveMessageReplyTimeout"]);
                        string currencyCommand = GetType().GetMethod(nameof(GetCurrenciesAsync)).GetCustomAttributes(true).OfType <SlashCommandAttribute>().First().Name;

                        EmbedBuilder[] embeds = FiatCurrencyService.CreateWorldCurrencyListEmbedAsync(currenciesList, currencyCommand, Context.User.Username).ToArray();
                        await SendDeferredPaginatedEmbedAsync(embeds);
                    }
                }
                catch (Exception ex)
                {
                    await SendDeferredErrorResponseAsync(ex);
                }
            });
        }