From 771c2745dc36177d66411a04f9a12ed6f90e5740 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 4 Dec 2021 15:45:04 +0100 Subject: [PATCH] .crypto now supports top 5k coins. closes #138 --- .../Modules/Searches/CryptoCommands.cs | 2 +- .../Searches/Services/CryptoService.cs | 25 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/NadekoBot/Modules/Searches/CryptoCommands.cs b/src/NadekoBot/Modules/Searches/CryptoCommands.cs index e56220775..79f189009 100644 --- a/src/NadekoBot/Modules/Searches/CryptoCommands.cs +++ b/src/NadekoBot/Modules/Searches/CryptoCommands.cs @@ -20,7 +20,7 @@ namespace NadekoBot.Modules.Searches var (crypto, nearest) = await _service.GetCryptoData(name).ConfigureAwait(false); - if (nearest != null) + if (nearest is not null) { var embed = _eb.Create() .WithTitle(GetText(strs.crypto_not_found)) diff --git a/src/NadekoBot/Modules/Searches/Services/CryptoService.cs b/src/NadekoBot/Modules/Searches/Services/CryptoService.cs index cb063146f..480167179 100644 --- a/src/NadekoBot/Modules/Searches/Services/CryptoService.cs +++ b/src/NadekoBot/Modules/Searches/Services/CryptoService.cs @@ -35,6 +35,9 @@ namespace NadekoBot.Modules.Searches.Services name = name.ToUpperInvariant(); var cryptos = await CryptoData().ConfigureAwait(false); + if (cryptos is null) + return (null, null); + var crypto = cryptos ?.FirstOrDefault(x => x.Id.ToUpperInvariant() == name || x.Name.ToUpperInvariant() == name || x.Symbol.ToUpperInvariant() == name); @@ -42,7 +45,8 @@ namespace NadekoBot.Modules.Searches.Services (CryptoResponseData Elem, int Distance)? nearest = null; if (crypto is null) { - nearest = cryptos.Select(x => (x, Distance: x.Name.ToUpperInvariant().LevenshteinDistance(name))) + nearest = cryptos + .Select(x => (x, Distance: x.Name.ToUpperInvariant().LevenshteinDistance(name))) .OrderBy(x => x.Distance) .Where(x => x.Distance <= 2) .FirstOrDefault(); @@ -68,18 +72,17 @@ namespace NadekoBot.Modules.Searches.Services { try { - using (var _http = _httpFactory.CreateClient()) - { - var strData = await _http.GetStringAsync(new Uri($"https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?" + - $"CMC_PRO_API_KEY={_creds.CoinmarketcapApiKey}" + - $"&start=1" + - $"&limit=500" + - $"&convert=USD")); + using var _http = _httpFactory.CreateClient(); + var strData = await _http.GetStringAsync( + $"https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?" + + $"CMC_PRO_API_KEY={_creds.CoinmarketcapApiKey}" + + $"&start=1" + + $"&limit=5000" + + $"&convert=USD"); - JsonConvert.DeserializeObject(strData); // just to see if its' valid + JsonConvert.DeserializeObject(strData); // just to see if its' valid - return strData; - } + return strData; } catch (Exception ex) {