diff --git a/src/DolarBot.API/DolarBot.API.csproj b/src/DolarBot.API/DolarBot.API.csproj
index c848f18..1071952 100644
--- a/src/DolarBot.API/DolarBot.API.csproj
+++ b/src/DolarBot.API/DolarBot.API.csproj
@@ -3,9 +3,9 @@
net6.0
10.0
- 3.2.4.0
- 3.2.4.0
- 3.2.4
+ 3.2.5.0
+ 3.2.5.0
+ 3.2.5
enable
diff --git a/src/DolarBot.API/Services/DolarBotApi/DolarBotApiService.cs b/src/DolarBot.API/Services/DolarBotApi/DolarBotApiService.cs
index 4e09061..f741c5f 100644
--- a/src/DolarBot.API/Services/DolarBotApi/DolarBotApiService.cs
+++ b/src/DolarBot.API/Services/DolarBotApi/DolarBotApiService.cs
@@ -149,11 +149,12 @@ internal DolarBotApiService(IConfiguration configuration, ResponseCache cache, A
/// Queries the API and returns the historical values for a particular .
///
/// The currency 3-digit code.
+ /// The historical rate date.
/// A task that contains a collection of normalized objects.
- public async Task?> GetWorldCurrencyHistoricalValues(string currencyCode)
+ public async Task GetWorldCurrencyHistoricalValue(string currencyCode, DateTime date)
{
- string endpoint = $"{WorldCurrencyEndpoints.Historical.GetDescription()}/{currencyCode.ToUpper()}";
- List? cachedResponse = Cache.GetObject>(endpoint);
+ string endpoint = $"{WorldCurrencyEndpoints.Historical.GetDescription()}/{currencyCode.ToUpper()}/{date:yyyy-MM-dd}";
+ WorldCurrencyResponse? cachedResponse = Cache.GetObject(endpoint);
if (cachedResponse != null)
{
return cachedResponse;
@@ -161,11 +162,11 @@ internal DolarBotApiService(IConfiguration configuration, ResponseCache cache, A
else
{
RestRequest request = new(endpoint);
- RestResponse> response = await Client.ExecuteGetAsync>(request);
- if (response.IsSuccessful && response.Data != null && response.Data.Count > 0)
+ RestResponse response = await Client.ExecuteGetAsync(request);
+ if (response.IsSuccessful && response.Data != null)
{
- List data = response.Data;
- data.ForEach(x => x.Code = currencyCode.ToUpper().Trim());
+ WorldCurrencyResponse data = response.Data;
+ data.Code = currencyCode.ToUpper().Trim();
Cache.SaveObject(endpoint, data, Cache.GetCurrencyListExpiration());
return data;
}
diff --git a/src/DolarBot.Addons/DolarBot.Addons.csproj b/src/DolarBot.Addons/DolarBot.Addons.csproj
index c688f3b..2ad4b8c 100644
--- a/src/DolarBot.Addons/DolarBot.Addons.csproj
+++ b/src/DolarBot.Addons/DolarBot.Addons.csproj
@@ -2,9 +2,9 @@
net6.0
- 3.2.4
- 3.2.4.0
- 3.2.4.0
+ 3.2.5
+ 3.2.5.0
+ 3.2.5.0
Guido Spadavecchia
DolarBot.Addons
https://github.com/PassiveModding/Discord.Addons.Interactive
diff --git a/src/DolarBot.Modules/DolarBot.Modules.csproj b/src/DolarBot.Modules/DolarBot.Modules.csproj
index 23242a4..c10dcad 100644
--- a/src/DolarBot.Modules/DolarBot.Modules.csproj
+++ b/src/DolarBot.Modules/DolarBot.Modules.csproj
@@ -3,9 +3,9 @@
net6.0
10.0
- 3.2.4.0
- 3.2.4.0
- 3.2.4
+ 3.2.5.0
+ 3.2.5.0
+ 3.2.5
diff --git a/src/DolarBot.Modules/InteractiveCommands/Autocompletion/Crypto/CryptoAutocompleteHandler.cs b/src/DolarBot.Modules/InteractiveCommands/Autocompletion/Crypto/CryptoAutocompleteHandler.cs
index e0f4f1a..ba12425 100644
--- a/src/DolarBot.Modules/InteractiveCommands/Autocompletion/Crypto/CryptoAutocompleteHandler.cs
+++ b/src/DolarBot.Modules/InteractiveCommands/Autocompletion/Crypto/CryptoAutocompleteHandler.cs
@@ -56,7 +56,7 @@ public override async Task GenerateSuggestionsAsync(IInter
currencyCodes = currencyCodes.Take(MAX_AUTOCOMPLETE_RESULTS).ToList();
}
- IEnumerable autocompletionCollection = currencyCodes.Select(x => new AutocompleteResult($"[{x.Symbol.ToUpper()}] {x.Name}", x.Code)).OrderBy(x => x.Name);
+ IEnumerable autocompletionCollection = currencyCodes.Select(x => new AutocompleteResult($"[{x.Symbol?.ToUpper()}] {x.Name}", x.Code)).OrderBy(x => x.Name);
return AutocompletionResult.FromSuccess(autocompletionCollection);
}
}
diff --git a/src/DolarBot.Modules/InteractiveCommands/FiatCurrencyInteractiveModule.cs b/src/DolarBot.Modules/InteractiveCommands/FiatCurrencyInteractiveModule.cs
index 3be9f00..3970124 100644
--- a/src/DolarBot.Modules/InteractiveCommands/FiatCurrencyInteractiveModule.cs
+++ b/src/DolarBot.Modules/InteractiveCommands/FiatCurrencyInteractiveModule.cs
@@ -2,6 +2,7 @@
using Discord.Interactions;
using DolarBot.API;
using DolarBot.API.Models;
+using DolarBot.API.Models.Base;
using DolarBot.API.Services.DolarBotApi;
using DolarBot.Modules.Attributes;
using DolarBot.Modules.InteractiveCommands.Autocompletion.FiatCurrency;
@@ -63,23 +64,13 @@ private async Task SendInvalidCurrencyCodeAsync(string userInput)
}
///
- /// Replies with a message indicating one of the date parameters was not correcly specified.
- ///
- /// The start date.
- /// The end date.
- private async Task SendInvalidDateRangeParametersAsync(DateTime startDate, DateTime endDate)
- {
- await FollowupAsync($"La {Format.Bold("fecha desde")} ({Format.Code(startDate.ToString("dd/MM/yyyy"))}) debe ser {Format.Bold("menor o igual")} a la {Format.Bold("fecha hasta")} ({Format.Code(endDate.ToString("dd/MM/yyyy"))}) y el rango debe ser {Format.Bold("menor")} a {Format.Code("1 año")}.");
- }
-
- ///
- /// Replies with a message indicating one of the date parameters was not correcly specified.
+ /// Replies with a message indicating that the date parameter was not correcly specified.
///
/// The start date.
/// The end date.
- private async Task SendNoDataForRangeAsync(DateTime startDate, DateTime endDate)
+ private async Task SendNoDataForDateAsync(DateTime date)
{
- await FollowupAsync($"No hay datos históricos para el rango de fechas {Format.Code(startDate.ToString("dd/MM/yyyy"))} - {Format.Code(endDate.ToString("dd/MM/yyyy"))}.");
+ await FollowupAsync($"No hay datos históricos para la fecha {Format.Code(date.ToString("dd/MM/yyyy"))}.");
}
///
@@ -182,10 +173,8 @@ public async Task GetHistoricalCurrencyValuesAsync(
[Summary("moneda", "Código de la moneda.")]
[Autocomplete(typeof(FiatCurrencyCodeAutocompleteHandler))]
string codigo,
- [Summary("desde", "Fecha desde.")]
- string startDate,
- [Summary("hasta", "Fecha hasta.")]
- string endDate
+ [Summary("fecha", "Fecha de la cotización.")]
+ string date
)
{
await DeferAsync().ContinueWith(async (task) =>
@@ -197,30 +186,20 @@ await DeferAsync().ContinueWith(async (task) =>
WorldCurrencyCodeResponse worldCurrencyCodeResponse = historicalCurrencyCodeList.FirstOrDefault(x => x.Code.Equals(currencyCode, StringComparison.OrdinalIgnoreCase));
if (worldCurrencyCodeResponse != null)
{
- TimeSpan oneYear = TimeSpan.FromDays(366);
- bool validStartDate = FiatCurrencyService.ParseDate(startDate, out DateTime? startDateResult) && startDateResult.HasValue;
- bool validEndDate = FiatCurrencyService.ParseDate(endDate, out DateTime? endDateResult) && endDateResult.HasValue;
- if (validStartDate && validEndDate)
+ if (FiatCurrencyService.ParseDate(date, out DateTime? dateResult) && dateResult.HasValue)
{
- DateTime dateFrom = startDateResult.Value;
- DateTime dateTo = endDateResult.Value;
- if (dateFrom <= dateTo && (dateTo.Subtract(dateFrom) <= oneYear))
+ DateTime date = dateResult.Value;
+ WorldCurrencyResponse historicalValue = await FiatCurrencyService.GetHistoricalCurrencyValue(currencyCode, date);
+ if (historicalValue != null)
{
- List historicalCurrencyValues = await FiatCurrencyService.GetHistoricalCurrencyValues(currencyCode, dateFrom, dateTo);
- if (historicalCurrencyValues != null && historicalCurrencyValues.Count > 0)
- {
- List embeds = FiatCurrencyService.CreateHistoricalValuesEmbedsAsync(historicalCurrencyValues, worldCurrencyCodeResponse.Name, dateFrom, dateTo);
- await FollowUpWithPaginatedEmbedAsync(embeds);
- }
- else
- {
- await SendNoDataForRangeAsync(dateFrom, dateTo);
- }
+ EmbedBuilder embed = await FiatCurrencyService.CreateWorldCurrencyEmbedAsync(historicalValue, worldCurrencyCodeResponse.Name, date: date);
+ await FollowupAsync(embed: embed.Build(), components: new CalculatorComponentBuilder(currencyCode, CalculatorTypes.FiatCurrency, Configuration).Build());
}
else
{
- await SendInvalidDateRangeParametersAsync(dateFrom, dateTo);
+ await SendNoDataForDateAsync(date);
}
+
}
else
{
diff --git a/src/DolarBot.Services/Currencies/FiatCurrencyService.cs b/src/DolarBot.Services/Currencies/FiatCurrencyService.cs
index 7208a91..e4e6b4e 100644
--- a/src/DolarBot.Services/Currencies/FiatCurrencyService.cs
+++ b/src/DolarBot.Services/Currencies/FiatCurrencyService.cs
@@ -69,17 +69,11 @@ public async Task GetCurrencyValue(string currencyCode)
/// Fetches a collection of historical currency values between two dates.
///
/// The currency 3-digit code.
- /// The start date.
- /// The end date.
+ /// The rate date.
/// A collection of objects.
- public async Task> GetHistoricalCurrencyValues(string currencyCode, DateTime? startDate = null, DateTime? endDate = null)
+ public async Task GetHistoricalCurrencyValue(string currencyCode, DateTime date)
{
- List historicalCurrencyValues = await Api.DolarBot.GetWorldCurrencyHistoricalValues(currencyCode);
- if ((startDate != null && startDate.Value.Date <= DateTime.Now.Date) || (endDate != null && endDate.Value.Date <= DateTime.Now.Date))
- {
- historicalCurrencyValues = historicalCurrencyValues.Where(x => (!startDate.HasValue || x.Fecha.Date >= startDate.Value.Date) && (!endDate.HasValue || x.Fecha.Date <= endDate.Value.Date)).ToList();
- }
- return historicalCurrencyValues;
+ return await Api.DolarBot.GetWorldCurrencyHistoricalValue(currencyCode, date);
}
#endregion
@@ -93,7 +87,7 @@ public async Task> GetHistoricalCurrencyValues(strin
/// The currency name.
/// The amount to rate against.
/// An object ready to be built.
- public async Task CreateWorldCurrencyEmbedAsync(WorldCurrencyResponse worldCurrencyResponse, string currencyName, decimal amount = 1)
+ public async Task CreateWorldCurrencyEmbedAsync(WorldCurrencyResponse worldCurrencyResponse, string currencyName, decimal amount = 1, DateTime? date = null)
{
var emojis = Configuration.GetSection("customEmojis");
Emoji currencyEmoji = Emoji.Parse(":flag_ar:");
@@ -111,10 +105,11 @@ public async Task CreateWorldCurrencyEmbedAsync(WorldCurrencyRespo
decimal? valuePrice = decimal.TryParse(worldCurrencyResponse?.Valor, NumberStyles.Any, DolarBotApiService.GetApiCulture(), out decimal v) ? v * amount : null;
string value = valuePrice.HasValue ? valuePrice.Value.ToString("N2", GlobalConfiguration.GetLocalCultureInfo()) : "?";
+ string description = date.HasValue ? $"Cotización de {Format.Bold($"{currencyName} ({worldCurrencyResponse.Code})")} para el día {Format.Code(date.Value.Date.ToString("dd/MM/yyyy"))} expresada en {Format.Bold("pesos argentinos")}." : $"Cotización de {Format.Bold($"{currencyName} ({worldCurrencyResponse.Code})")} expresada en {Format.Bold("pesos argentinos")}.";
string shareText = $"*{currencyName} ({worldCurrencyResponse.Code})*{Environment.NewLine}{Environment.NewLine}*{amount} {worldCurrencyResponse.Code}*{Environment.NewLine}Valor: \t$ *{value}*{Environment.NewLine}Hora: \t{lastUpdated} (UTC {utcOffset})";
EmbedBuilder embed = new EmbedBuilder().WithColor(GlobalConfiguration.Colors.Currency)
.WithTitle($"{currencyName} ({worldCurrencyResponse.Code})")
- .WithDescription($"Cotización de {Format.Bold($"{currencyName} ({worldCurrencyResponse.Code})")} expresada en {Format.Bold("pesos argentinos")}.".AppendLineBreak())
+ .WithDescription(description.AppendLineBreak())
.WithThumbnailUrl(currencyImageUrl)
.WithFooter(new EmbedFooterBuilder()
{
diff --git a/src/DolarBot.Services/DolarBot.Services.csproj b/src/DolarBot.Services/DolarBot.Services.csproj
index 0cb0486..252584f 100644
--- a/src/DolarBot.Services/DolarBot.Services.csproj
+++ b/src/DolarBot.Services/DolarBot.Services.csproj
@@ -3,9 +3,9 @@
net6.0
10.0
- 3.2.4.0
- 3.2.4.0
- 3.2.4
+ 3.2.5.0
+ 3.2.5.0
+ 3.2.5
diff --git a/src/DolarBot.Util/DolarBot.Util.csproj b/src/DolarBot.Util/DolarBot.Util.csproj
index 8d5f94a..da0f7fb 100644
--- a/src/DolarBot.Util/DolarBot.Util.csproj
+++ b/src/DolarBot.Util/DolarBot.Util.csproj
@@ -3,9 +3,9 @@
net6.0
10.0
- 3.2.4.0
- 3.2.4.0
- 3.2.4
+ 3.2.5.0
+ 3.2.5.0
+ 3.2.5
diff --git a/src/DolarBot/DolarBot.csproj b/src/DolarBot/DolarBot.csproj
index 90976bf..5589a52 100644
--- a/src/DolarBot/DolarBot.csproj
+++ b/src/DolarBot/DolarBot.csproj
@@ -5,9 +5,9 @@
net6.0
dolarbot-logo.ico
10.0
- 3.2.4.0
- 3.2.4.0
- 3.2.4
+ 3.2.5.0
+ 3.2.5.0
+ 3.2.5
Linux