.crypto command added, and it's kinda smart as a bonus.
This commit is contained in:
parent
3d903e028a
commit
3518ebc145
@ -22,6 +22,7 @@ using NadekoBot.Modules.Searches.Common;
|
|||||||
using NadekoBot.Modules.Searches.Services;
|
using NadekoBot.Modules.Searches.Services;
|
||||||
using NadekoBot.Common.Replacements;
|
using NadekoBot.Common.Replacements;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
using NadekoBot.Core.Modules.Searches.Common;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Searches
|
namespace NadekoBot.Modules.Searches
|
||||||
{
|
{
|
||||||
@ -44,20 +45,56 @@ namespace NadekoBot.Modules.Searches
|
|||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(name))
|
if (string.IsNullOrWhiteSpace(name))
|
||||||
return;
|
return;
|
||||||
|
var cryptos = (await _service.CryptoData().ConfigureAwait(false));
|
||||||
|
var crypto = cryptos
|
||||||
|
?.FirstOrDefault(x => x.Id.ToLowerInvariant() == name || x.Name.ToLowerInvariant() == name
|
||||||
|
|| x.Symbol.ToLowerInvariant() == name);
|
||||||
|
|
||||||
var crypto = (await _service.CryptoData().ConfigureAwait(false))
|
(CryptoData Elem, int Distance)? nearest = null;
|
||||||
?.FirstOrDefault(x => x.Id.ToLowerInvariant() == name || x.Name.ToLowerInvariant() == name);
|
if (crypto == null)
|
||||||
|
{
|
||||||
|
nearest = cryptos.Select(x => (x, Distance: x.Name.ToLowerInvariant().LevenshteinDistance(name)))
|
||||||
|
.OrderBy(x => x.Distance)
|
||||||
|
.Where(x => x.Distance <= 2)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
crypto = nearest?.Elem;
|
||||||
|
}
|
||||||
|
|
||||||
if (crypto == null)
|
if (crypto == null)
|
||||||
return; //todo error message
|
{
|
||||||
|
await ReplyErrorLocalized("crypto_not_found").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nearest != null)
|
||||||
|
{
|
||||||
|
//wrap this into some class, ther'es the same code in execsql too
|
||||||
|
var msg = await Context.Channel.EmbedAsync(new EmbedBuilder()
|
||||||
|
.WithOkColor()
|
||||||
|
.WithTitle(GetText("crypto_not_found"))
|
||||||
|
.WithDescription(GetText("did_you_mean", Format.Bold($"{crypto.Name} ({crypto.Symbol})")))
|
||||||
|
.WithFooter("Y/n")).ConfigureAwait(false);
|
||||||
|
|
||||||
|
var input = await GetUserInputAsync(Context.User.Id, Context.Channel.Id);
|
||||||
|
input = input?.ToLowerInvariant().ToString();
|
||||||
|
|
||||||
|
if (input != "yes" && input != "y")
|
||||||
|
{
|
||||||
|
var __ = msg.DeleteAsync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var _ = msg.DeleteAsync();
|
||||||
|
}
|
||||||
|
|
||||||
await Context.Channel.EmbedAsync(new EmbedBuilder()
|
await Context.Channel.EmbedAsync(new EmbedBuilder()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle($"{crypto.Name} ({crypto.Id})")
|
.WithTitle($"{crypto.Name} ({crypto.Symbol})")
|
||||||
.AddField("Market Cap", $"${crypto.Market_Cap_Usd:n0}", true)
|
.WithThumbnailUrl($"https://files.coinmarketcap.com/static/img/coins/32x32/{crypto.Id}.png")
|
||||||
.AddField("Price", $"${crypto.Price_Usd}", true)
|
.AddField(GetText("market_cap"), $"${crypto.Market_Cap_Usd:n0}", true)
|
||||||
.AddField("Volume (24h)", $"${crypto._24h_Volume_Usd:n0}", true)
|
.AddField(GetText("price"), $"${crypto.Price_Usd}", true)
|
||||||
.AddField("Change (7d/24h)", $"{crypto.Percent_Change_7d}% / {crypto.Percent_Change_24h}%", true));
|
.AddField(GetText("volume_24h"), $"${crypto._24h_Volume_Usd:n0}", true)
|
||||||
|
.AddField(GetText("change_7d_24h"), $"{crypto.Percent_Change_7d}% / {crypto.Percent_Change_24h}%", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
//for anonymasen :^)
|
//for anonymasen :^)
|
||||||
|
@ -54,9 +54,12 @@ namespace NadekoBot.Extensions
|
|||||||
|
|
||||||
private static readonly IEmote arrow_left = new Emoji("⬅");
|
private static readonly IEmote arrow_left = new Emoji("⬅");
|
||||||
private static readonly IEmote arrow_right = new Emoji("➡");
|
private static readonly IEmote arrow_right = new Emoji("➡");
|
||||||
//todo update this
|
|
||||||
public static Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordSocketClient client, int currentPage, Func<int, EmbedBuilder> pageFunc, int totalElements, int itemsPerPage, bool addPaginatedFooter = true) =>
|
public static Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordSocketClient client,
|
||||||
channel.SendPaginatedConfirmAsync(client, currentPage, (x) => Task.FromResult(pageFunc(x)), totalElements, itemsPerPage, addPaginatedFooter);
|
int currentPage, Func<int, EmbedBuilder> pageFunc, int totalElements,
|
||||||
|
int itemsPerPage, bool addPaginatedFooter = true) =>
|
||||||
|
channel.SendPaginatedConfirmAsync(client, currentPage,
|
||||||
|
(x) => Task.FromResult(pageFunc(x)), totalElements, itemsPerPage, addPaginatedFooter);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// danny kamisama
|
/// danny kamisama
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -911,5 +911,11 @@
|
|||||||
"gambling_timely": "You've claimed your {0}. You can claim again in {1}h",
|
"gambling_timely": "You've claimed your {0}. You can claim again in {1}h",
|
||||||
"gambling_timely_set": "Users will be able to claim {0} every {1}h",
|
"gambling_timely_set": "Users will be able to claim {0} every {1}h",
|
||||||
"gambling_timely_set_none": "Users will not be able to claim any timely currency.",
|
"gambling_timely_set_none": "Users will not be able to claim any timely currency.",
|
||||||
"gambling_timely_reset": "All users will be able to claim timely currency again."
|
"gambling_timely_reset": "All users will be able to claim timely currency again.",
|
||||||
|
"searches_price": "Price",
|
||||||
|
"searches_market_cap": "Market Cap",
|
||||||
|
"searches_volume_24h": "Volume (24h)",
|
||||||
|
"searches_change_7d_24h": "Change (7d/24h)",
|
||||||
|
"searches_crypto_not_found": "Cryptocurrency with that name was not found.",
|
||||||
|
"searches_did_you_mean": "Did you mean {0}?"
|
||||||
}
|
}
|
@ -3090,5 +3090,13 @@
|
|||||||
"usage": [
|
"usage": [
|
||||||
"{0}novel the nine cauldrons"
|
"{0}novel the nine cauldrons"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"crypto": {
|
||||||
|
"cmd": "crypto c",
|
||||||
|
"desc": "Shows basic stats about a cryptocurrency from coinmarketcap.com. You can use either a name or an abbreviation of the currency.",
|
||||||
|
"usage": [
|
||||||
|
"{0}c btc",
|
||||||
|
"{0}c bitcoin"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user