Add Magic The Gathering card search
This commit is contained in:
parent
7592cebd12
commit
ffc1f5a061
@ -208,6 +208,51 @@ $@"🌍 **Weather for** 【{obj["target"]}】
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task MagicTheGathering(IUserMessage umsg, [Remainder] string name = null)
|
||||
{
|
||||
var channel = (ITextChannel)umsg.Channel;
|
||||
var arg = name;
|
||||
if (string.IsNullOrWhiteSpace(arg))
|
||||
{
|
||||
await channel.SendMessageAsync("💢 `Please enter a card name to search for.`").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
await umsg.Channel.TriggerTypingAsync().ConfigureAwait(false);
|
||||
string response = "";
|
||||
using (var http = new HttpClient())
|
||||
{
|
||||
http.DefaultRequestHeaders.Clear();
|
||||
response = await http.GetStringAsync($"https://api.deckbrew.com/mtg/cards?name={Uri.EscapeUriString(arg)}")
|
||||
.ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
var items = JArray.Parse(response).Shuffle().ToList();
|
||||
var images = new List<Image>();
|
||||
if (items == null)
|
||||
throw new KeyNotFoundException("Cannot find a card by that name");
|
||||
|
||||
using (var sr = await http.GetStreamAsync(items[0]["editions"][0]["image_url"].ToString()))
|
||||
{
|
||||
var imgStream = new MemoryStream();
|
||||
await sr.CopyToAsync(imgStream);
|
||||
imgStream.Position = 0;
|
||||
images.Add(new Image(imgStream));
|
||||
}
|
||||
var ms = new MemoryStream();
|
||||
images.Merge().SaveAsJpeg(ms);
|
||||
ms.Position = 0;
|
||||
await channel.SendFileAsync(ms, arg + ".jpg", null).ConfigureAwait(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
await channel.SendMessageAsync($"💢 Error could not find the card {arg}").ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Hearthstone(IUserMessage umsg, [Remainder] string name = null)
|
||||
|
35
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
35
src/NadekoBot/Resources/CommandStrings.Designer.cs
generated
@ -906,7 +906,7 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Toggles automatic deletion of bye messages..
|
||||
/// Looks up a localized string similar to Sets the time it takes (in seconds) for bye messages to be auto-deleted. Set 0 to disable automatic deletion..
|
||||
/// </summary>
|
||||
public static string byedel_desc {
|
||||
get {
|
||||
@ -915,7 +915,7 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to `{0}byedel`.
|
||||
/// Looks up a localized string similar to `{0}byedel 0` or `{0}byedel 30`.
|
||||
/// </summary>
|
||||
public static string byedel_usage {
|
||||
get {
|
||||
@ -2688,7 +2688,7 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Toggles automatic deletion of greet messages..
|
||||
/// Looks up a localized string similar to Sets the time it takes (in seconds) for greet messages to be auto-deleted. Set 0 to disable automatic deletion..
|
||||
/// </summary>
|
||||
public static string greetdel_desc {
|
||||
get {
|
||||
@ -2697,7 +2697,7 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to `{0}greetdel`.
|
||||
/// Looks up a localized string similar to `{0}greetdel 0` or `{0}greetdel 30`.
|
||||
/// </summary>
|
||||
public static string greetdel_usage {
|
||||
get {
|
||||
@ -3974,6 +3974,33 @@ namespace NadekoBot.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to magicthegathering mtg.
|
||||
/// </summary>
|
||||
public static string magicthegathering_cmd {
|
||||
get {
|
||||
return ResourceManager.GetString("magicthegathering_cmd", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Searches for a Magic The Gathering card..
|
||||
/// </summary>
|
||||
public static string magicthegathering_desc {
|
||||
get {
|
||||
return ResourceManager.GetString("magicthegathering_desc", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to `{0}magicthegathering about face` or `{0}mtg about face`.
|
||||
/// </summary>
|
||||
public static string magicthegathering_usage {
|
||||
get {
|
||||
return ResourceManager.GetString("magicthegathering_usage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to manga mang mq.
|
||||
/// </summary>
|
||||
|
@ -2700,4 +2700,13 @@
|
||||
<data name="yandere_usage" xml:space="preserve">
|
||||
<value>`{0}yandere tag1+tag2`</value>
|
||||
</data>
|
||||
<data name="magicthegathering_cmd" xml:space="preserve">
|
||||
<value>magicthegathering mtg</value>
|
||||
</data>
|
||||
<data name="magicthegathering_desc" xml:space="preserve">
|
||||
<value>Searches for a Magic The Gathering card.</value>
|
||||
</data>
|
||||
<data name="magicthegathering_usage" xml:space="preserve">
|
||||
<value>`{0}magicthegathering about face` or `{0}mtg about face`</value>
|
||||
</data>
|
||||
</root>
|
Loading…
Reference in New Issue
Block a user