Пример #1
0
        public async Task GetEuroRatesAsync()
        {
            try
            {
                using (Context.Channel.EnterTypingState())
                {
                    VzlaResponse result = await VzlaService.GetEuroRates();

                    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);
            }
        }
Пример #2
0
        public async Task GetRiesgoPaisValueAsync()
        {
            try
            {
                using (Context.Channel.EnterTypingState())
                {
                    CountryRiskResponse result = await BcraService.GetCountryRisk();

                    if (result != null)
                    {
                        EmbedBuilder embed = await BcraService.CreateCountryRiskEmbedAsync(result);

                        embed.AddCommandDeprecationNotice(Configuration);
                        await ReplyAsync(embed : embed.Build());
                    }
                    else
                    {
                        await ReplyAsync(REQUEST_ERROR_MESSAGE);
                    }
                }
            }
            catch (Exception ex)
            {
                await SendErrorReply(ex);
            }
        }
Пример #3
0
        public async Task GetDateAsync()
        {
            try
            {
                Emoji        timeEmoji         = new("\u23F0");
                string       infoImageUrl      = Configuration.GetSection("images")?.GetSection("info")?["64"];
                TimeZoneInfo localTimeZoneInfo = GlobalConfiguration.GetLocalTimeZoneInfo();
                string       localTimestamp    = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, localTimeZoneInfo).ToString("yyyy/MM/dd - HH:mm:ss");
                string       serverTimestamp   = DateTime.Now.ToString("yyyy/MM/dd - HH:mm:ss");

                EmbedBuilder embed = new EmbedBuilder()
                                     .WithTitle("Fecha y Hora")
                                     .WithColor(GlobalConfiguration.Colors.Info)
                                     .WithThumbnailUrl(infoImageUrl)
                                     .WithDescription(GlobalConfiguration.Constants.BLANK_SPACE)
                                     .AddField($"Fecha y hora del servidor", $"{timeEmoji} {serverTimestamp} ({Format.Italics(TimeZoneInfo.Local.StandardName)})".AppendLineBreak())
                                     .AddField($"Fecha y hora del bot", $"{timeEmoji} {localTimestamp} ({Format.Italics(localTimeZoneInfo.StandardName)})");

                embed.AddCommandDeprecationNotice(Configuration);
                await ReplyAsync(embed : embed.Build());
            }
            catch (Exception ex)
            {
                await SendErrorReply(ex);
            }
        }
Пример #4
0
        public async Task GetInviteLink()
        {
            try
            {
                string infoImageUrl  = Configuration.GetSection("images")?.GetSection("info")?["64"];
                string inviteLink    = Configuration["inviteLink"];
                var    emojis        = Configuration.GetSection("customEmojis");
                Emoji  dolarbotEmoji = new(emojis["dolarbot"]);

                if (string.IsNullOrWhiteSpace(inviteLink))
                {
                    inviteLink = Environment.GetEnvironmentVariable(GlobalConfiguration.GetInviteLinkEnvVarName());
                }

                EmbedBuilder embed = new EmbedBuilder()
                                     .WithTitle($"{dolarbotEmoji} DolarBot")
                                     .WithColor(GlobalConfiguration.Colors.Info)
                                     .WithThumbnailUrl(infoImageUrl)
                                     .WithDescription($"Invita al bot haciendo {Format.Url("click aquí", inviteLink)}");

                embed.AddCommandDeprecationNotice(Configuration);
                await ReplyAsync(embed : embed.Build());
            }
            catch (Exception ex)
            {
                await SendErrorReply(ex);
            }
        }
Пример #5
0
        /// <summary>
        /// Replies with an embed message containing a specific standard rate for this currency.
        /// </summary>
        /// <param name="response">The currency response containing the data.</param>
        /// <param name="description">The embed message description.</param>
        protected async Task SendStandardRate(TypeResponse response, string description)
        {
            if (response != null)
            {
                EmbedBuilder embed = await Service.CreateEmbedAsync(response, description);

                embed.AddCommandDeprecationNotice(Configuration);
                await ReplyAsync(embed : embed.Build());
            }
            else
            {
                await ReplyAsync(REQUEST_ERROR_MESSAGE);
            }
        }
        /// <summary>
        /// Replies with an embed message containing the rate for the current cryptocurrency.
        /// </summary>
        /// <param name="response">The crypto response with the data.</param>
        /// <param name="cryptoCurrencyName">A custom cryptocurrency name.</param>
        protected async Task SendCryptoReply(CryptoResponse response, string cryptoCurrencyName = null)
        {
            if (response != null)
            {
                EmbedBuilder embed = await CryptoService.CreateCryptoEmbedAsync(response, cryptoCurrencyName);

                embed.AddCommandDeprecationNotice(Configuration);
                await ReplyAsync(embed : embed.Build());
            }
            else
            {
                await ReplyAsync(REQUEST_ERROR_MESSAGE);
            }
        }
Пример #7
0
        public async Task GetApiStatus()
        {
            try
            {
                string statusText = await InfoService.GetApiStatus();

                EmbedBuilder embed = InfoService.CreateStatusEmbed(statusText, Context.Client.Latency);
                embed.AddCommandDeprecationNotice(Configuration);
                await ReplyAsync(embed : embed.Build());
            }
            catch (Exception ex)
            {
                await SendErrorReply(ex);
            }
        }
Пример #8
0
        /// <summary>
        /// Replies with an embed message containing a specific bank rate for this currency.
        /// </summary>
        /// <param name="bank">The bank which rate must be replied.</param>
        protected async Task SendBankRate(Banks bank, string description)
        {
            string       thumbnailUrl = Service.GetBankThumbnailUrl(bank);
            TypeResponse result       = await Service.GetByBank(bank);

            if (result != null)
            {
                EmbedBuilder embed = await Service.CreateEmbedAsync(result, description, thumbnailUrl : thumbnailUrl);

                embed.AddCommandDeprecationNotice(Configuration);
                await ReplyAsync(embed : embed.Build());
            }
            else
            {
                await ReplyAsync(REQUEST_ERROR_MESSAGE);
            }
        }
Пример #9
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);
            }
        }
Пример #10
0
        public async Task GetAbout()
        {
            try
            {
                var   emojis             = Configuration.GetSection("customEmojis");
                Emoji blueHeartEmoji     = new("\uD83D\uDC99");
                Emoji versionEmoji       = new(emojis["dolarbot"]);
                Emoji supportServerEmoji = new("\uD83D\uDCAC");
                Emoji checkEmoji         = new("\u2705");
                Emoji voteEmoji          = new(emojis["arrowUpRed"]);
                Emoji hourglassEmoji     = new("\u23F3");

                Version  version            = Assembly.GetEntryAssembly().GetName().Version;
                string   infoImageUrl       = Configuration.GetSection("images")?.GetSection("info")?["64"];
                string   dolarBotImageUrl   = Configuration.GetSection("images")?.GetSection("dolarbot")?["32"];
                string   websiteUrl         = Configuration["websiteUrl"];
                string   githubUrl          = Configuration["githubUrl"];
                string   playStoreUrl       = Configuration["playStoreLink"];
                string   supportServerUrl   = Configuration["supportServerUrl"];
                string   voteUrl            = Configuration["voteUrl"];
                string   versionDescription = Format.Bold(version.ToString(3));
                int      serverCount        = Context.Client.Guilds.Count;
                TimeSpan uptime             = GlobalConfiguration.GetUptime();

                EmbedBuilder embed = new EmbedBuilder()
                                     .WithTitle("DolarBot")
                                     .WithColor(GlobalConfiguration.Colors.Info)
                                     .WithThumbnailUrl(infoImageUrl)
                                     .WithDescription($"{versionEmoji} Versión {versionDescription}".AppendLineBreak())
                                     .AddField("Status", $"{checkEmoji} {Format.Bold("Online")} en {Format.Bold(serverCount.ToString())} {(serverCount > 1 ? "servidores" : "servidor")}".AppendLineBreak())
                                     .AddField("Uptime (Desde último reinicio)", $"{hourglassEmoji} {Format.Bold(uptime.Days.ToString())}d {Format.Bold(uptime.Hours.ToString())}h {Format.Bold(uptime.Minutes.ToString())}m {Format.Bold(uptime.Seconds.ToString())}s".AppendLineBreak())
                                     .AddField("¿Dudas o sugerencias?", $"{supportServerEmoji} Unite al {Format.Url("servidor oficial de DolarBot", supportServerUrl)}".AppendLineBreak())
                                     .AddField("Web", InfoService.GetWebsiteEmbedDescription().AppendLineBreak())
                                     .AddField("¿Te gusta DolarBot?", new StringBuilder().AppendLine($"{voteEmoji} {Format.Url("Votalo en top.gg", voteUrl)}").AppendLineBreak())
                                     .WithFooter($"Hecho con {blueHeartEmoji} en {RuntimeInformation.FrameworkDescription}");

                embed.AddCommandDeprecationNotice(Configuration);
                await ReplyAsync(embed : embed.Build());
            }
            catch (Exception ex)
            {
                await SendErrorReply(ex);
            }
        }
Пример #11
0
 public async Task SendHelp(string command = null)
 {
     try
     {
         if (SlashCommandExists(command))
         {
             EmbedBuilder embed = GenerateEmbeddedSlashCommandHelp(command);
             embed.AddCommandDeprecationNotice(Configuration);
             await ReplyAsync(embed : embed.Build());
         }
         else
         {
             await SendPagedHelpReplyAsync();
         }
     }
     catch (Exception ex)
     {
         await SendErrorReply(ex);
     }
 }
Пример #12
0
        public async Task GetServerId()
        {
            try
            {
                string       infoImageUrl = Configuration.GetSection("images")?.GetSection("info")?["64"];
                string       sid          = Format.Bold(Context.Guild.Id.ToString());
                EmbedBuilder embed        = new EmbedBuilder()
                                            .WithTitle("Server ID")
                                            .WithColor(GlobalConfiguration.Colors.Info)
                                            .WithThumbnailUrl(infoImageUrl)
                                            .WithDescription($"El ID del servidor es {sid}");

                embed.AddCommandDeprecationNotice(Configuration);
                await ReplyAsync(embed : embed.Build());
            }
            catch (Exception ex)
            {
                await SendErrorReply(ex);
            }
        }
Пример #13
0
        /// <summary>
        /// Replies with an embed message containing all available standard rates for this currency.
        /// </summary>
        protected async Task SendAllStandardRates()
        {
            TypeResponse[] responses = await Service.GetAllStandardRates();

            if (responses.Any(r => r != null))
            {
                TypeResponse[] successfulResponses = responses.Where(r => r != null).ToArray();
                EmbedBuilder   embed = Service.CreateEmbed(successfulResponses);
                embed.AddCommandDeprecationNotice(Configuration);

                if (responses.Length != successfulResponses.Length)
                {
                    await ReplyAsync($"{Format.Bold("Atención")}: No se pudieron obtener algunas cotizaciones. Sólo se mostrarán aquellas que no presentan errores.");
                }
                await ReplyAsync(embed : embed.Build());
            }
            else
            {
                await ReplyAsync(REQUEST_ERROR_MESSAGE);
            }
        }
Пример #14
0
        public async Task GetEvolucionAsync([Summary("Indica el tipo de cotización a obtener")] string cotizacion = null)
        {
            try
            {
                using (Context.Channel.EnterTypingState())
                {
                    if (cotizacion == null)
                    {
                        await ReplyAsync(GetEvolucionInvalidParamsMessage());
                    }
                    else
                    {
                        string userInput = Format.Sanitize(cotizacion).RemoveFormat(true);
                        if (!userInput.IsNumeric() && Enum.TryParse(userInput, true, out HistoricalRatesParamEndpoints historicalRateParam))
                        {
                            HistoricalRatesResponse result = await HistoricalRatesService.GetHistoricalRates(historicalRateParam);

                            if (result != null && result.Meses != null && result.Meses.Count > 0)
                            {
                                EmbedBuilder embed = HistoricalRatesService.CreateHistoricalRatesEmbed(result, historicalRateParam);
                                embed.AddCommandDeprecationNotice(Configuration);
                                await ReplyAsync(embed : embed.Build());
                            }
                            else
                            {
                                await ReplyAsync(REQUEST_ERROR_MESSAGE);
                            }
                        }
                        else
                        {
                            await ReplyAsync(GetEvolucionInvalidParamsMessage());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                await SendErrorReply(ex);
            }
        }
Пример #15
0
        public async Task Ping()
        {
            try
            {
                string       infoImageUrl = Configuration.GetSection("images")?.GetSection("info")?["64"];
                EmbedBuilder embed        = new EmbedBuilder()
                                            .WithTitle("Procesando...")
                                            .WithColor(GlobalConfiguration.Colors.Info);

                Stopwatch sw = new();
                sw.Start();
                var message = await ReplyAsync(embed : embed.Build());

                sw.Stop();

                string responseTime = $"{Context.Client.Latency} ms";
                string latency      = $"{sw.ElapsedMilliseconds} ms";
                await message.ModifyAsync(x =>
                {
                    Emoji pingEmoji    = new("\uD83D\uDCE1");
                    Emoji gatewayEmoji = new("\uD83D\uDEAA");

                    embed.WithTitle($"Resultado del {Format.Code("ping")}")
                    .WithThumbnailUrl(infoImageUrl)
                    .AddInlineField("Tiempo de respuesta", $"{pingEmoji} {responseTime}")
                    .AddInlineField()
                    .AddInlineField("Latencia del gateway", $"{gatewayEmoji} {latency}");

                    embed.AddCommandDeprecationNotice(Configuration);
                    x.Embed = embed.Build();
                });
            }
            catch (Exception ex)
            {
                await SendErrorReply(ex);
            }
        }
Пример #16
0
        public async Task GetVoteLink()
        {
            try
            {
                string infoImageUrl  = Configuration.GetSection("images")?.GetSection("info")?["64"];
                string voteLink      = Configuration["voteUrl"];
                var    emojis        = Configuration.GetSection("customEmojis");
                Emoji  dolarbotEmoji = new(emojis["dolarbot"]);


                EmbedBuilder embed = new EmbedBuilder()
                                     .WithTitle($"{dolarbotEmoji} Votar")
                                     .WithColor(GlobalConfiguration.Colors.Info)
                                     .WithThumbnailUrl(infoImageUrl)
                                     .WithDescription($"Podes votar por {Format.Bold("DolarBot")} haciendo {Format.Url("click acá", voteLink)}. Gracias por tu apoyo!");

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