.crypto now supports top 5k coins. closes #138

This commit is contained in:
Kwoth
2021-12-04 15:45:04 +01:00
parent 59c0f2f4b3
commit 771c2745dc
2 changed files with 15 additions and 12 deletions

View File

@@ -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))

View File

@@ -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<CryptoResponse>(strData); // just to see if its' valid
JsonConvert.DeserializeObject<CryptoResponse>(strData); // just to see if its' valid
return strData;
}
return strData;
}
catch (Exception ex)
{