EmbedAsync extension, ~ani and ~mang are wayyyyy cooler
This commit is contained in:
parent
269463e5c9
commit
25e31faa6e
@ -37,9 +37,35 @@ namespace NadekoBot.Modules.Searches
|
|||||||
if (string.IsNullOrWhiteSpace(query))
|
if (string.IsNullOrWhiteSpace(query))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var result = await GetAnimeData(query).ConfigureAwait(false);
|
var animeData = await GetAnimeData(query).ConfigureAwait(false);
|
||||||
|
|
||||||
await channel.SendMessageAsync(result.ToString() ?? "`No anime found.`").ConfigureAwait(false);
|
var embed = new Discord.API.Embed()
|
||||||
|
{
|
||||||
|
Description = animeData.Synopsis,
|
||||||
|
Title = animeData.title_english,
|
||||||
|
Url = animeData.Link,
|
||||||
|
Image = new Discord.API.EmbedImage() {
|
||||||
|
Url = animeData.image_url_lge
|
||||||
|
},
|
||||||
|
Fields = new[] {
|
||||||
|
new Discord.API.EmbedField() {
|
||||||
|
Inline = true,
|
||||||
|
Name = "Episodes",
|
||||||
|
Value = animeData.total_episodes.ToString()
|
||||||
|
},
|
||||||
|
new Discord.API.EmbedField() {
|
||||||
|
Inline = true,
|
||||||
|
Name = "Status",
|
||||||
|
Value = animeData.AiringStatus.ToString()
|
||||||
|
},
|
||||||
|
new Discord.API.EmbedField() {
|
||||||
|
Inline = true,
|
||||||
|
Name = "Genres",
|
||||||
|
Value = String.Join(", ", animeData.Genres)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
await channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
@ -51,9 +77,37 @@ namespace NadekoBot.Modules.Searches
|
|||||||
if (string.IsNullOrWhiteSpace(query))
|
if (string.IsNullOrWhiteSpace(query))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var result = await GetMangaData(query).ConfigureAwait(false);
|
var animeData = await GetMangaData(query).ConfigureAwait(false);
|
||||||
|
|
||||||
await channel.SendMessageAsync(result.ToString() ?? "`No manga found.`").ConfigureAwait(false);
|
var embed = new Discord.API.Embed()
|
||||||
|
{
|
||||||
|
Description = animeData.Synopsis,
|
||||||
|
Title = animeData.title_english,
|
||||||
|
Url = animeData.Link,
|
||||||
|
Image = new Discord.API.EmbedImage()
|
||||||
|
{
|
||||||
|
Url = animeData.image_url_lge
|
||||||
|
},
|
||||||
|
Fields = new[] {
|
||||||
|
new Discord.API.EmbedField() {
|
||||||
|
Inline = true,
|
||||||
|
Name = "Chapters",
|
||||||
|
Value = animeData.total_chapters.ToString()
|
||||||
|
},
|
||||||
|
new Discord.API.EmbedField() {
|
||||||
|
Inline = true,
|
||||||
|
Name = "Status",
|
||||||
|
Value = animeData.publishing_status.ToString()
|
||||||
|
},
|
||||||
|
new Discord.API.EmbedField() {
|
||||||
|
Inline = true,
|
||||||
|
Name = "Genres",
|
||||||
|
Value = String.Join(", ", animeData.Genres)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<AnimeResult> GetAnimeData(string query)
|
private async Task<AnimeResult> GetAnimeData(string query)
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
namespace NadekoBot.Modules.Searches.Models
|
using NadekoBot.Extensions;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace NadekoBot.Modules.Searches.Models
|
||||||
{
|
{
|
||||||
public class AnimeResult
|
public class AnimeResult
|
||||||
{
|
{
|
||||||
public int id;
|
public int id;
|
||||||
|
public string AiringStatus => airing_status.ToTitleCase();
|
||||||
public string airing_status;
|
public string airing_status;
|
||||||
public string title_english;
|
public string title_english;
|
||||||
public int total_episodes;
|
public int total_episodes;
|
||||||
public string description;
|
public string description;
|
||||||
public string image_url_lge;
|
public string image_url_lge;
|
||||||
|
public string[] Genres;
|
||||||
public override string ToString() =>
|
public string Link => "http://anilist.co/anime/" + id;
|
||||||
"`Title:` **" + title_english +
|
public string Synopsis => description?.Substring(0, description.Length > 500 ? 500 : description.Length) + "...";
|
||||||
"**\n`Status:` " + airing_status +
|
|
||||||
"\n`Episodes:` " + total_episodes +
|
|
||||||
"\n`Link:` http://anilist.co/anime/" + id +
|
|
||||||
"\n`Synopsis:` " + description.Substring(0, description.Length > 500 ? 500 : description.Length) + "..." +
|
|
||||||
"\n`img:` " + image_url_lge;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,14 +9,8 @@ namespace NadekoBot.Modules.Searches.Models
|
|||||||
public int total_chapters;
|
public int total_chapters;
|
||||||
public int total_volumes;
|
public int total_volumes;
|
||||||
public string description;
|
public string description;
|
||||||
|
public string[] Genres;
|
||||||
public override string ToString() =>
|
public string Link => "http://anilist.co/manga/" + id;
|
||||||
"`Title:` **" + title_english +
|
public string Synopsis => description?.Substring(0, description.Length > 500 ? 500 : description.Length) + "...";
|
||||||
"**\n`Status:` " + publishing_status +
|
|
||||||
"\n`Chapters:` " + total_chapters +
|
|
||||||
"\n`Volumes:` " + total_volumes +
|
|
||||||
"\n`Link:` http://anilist.co/manga/" + id +
|
|
||||||
"\n`Synopsis:` " + description.Substring(0, description.Length > 500 ? 500 : description.Length) + "..." +
|
|
||||||
"\n`img:` " + image_url_lge;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -155,6 +155,9 @@ namespace NadekoBot.Extensions
|
|||||||
return list.ToArray();
|
return list.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Task<IUserMessage> EmbedAsync(this IMessageChannel ch, Discord.API.Embed embed)
|
||||||
|
=> ch.SendMessageAsync("", embed: embed);
|
||||||
|
|
||||||
public static Task<IUserMessage> SendTableAsync<T>(this IMessageChannel ch, string seed, IEnumerable<T> items, Func<T, string> howToPrint, int columns = 3)
|
public static Task<IUserMessage> SendTableAsync<T>(this IMessageChannel ch, string seed, IEnumerable<T> items, Func<T, string> howToPrint, int columns = 3)
|
||||||
{
|
{
|
||||||
var i = 0;
|
var i = 0;
|
||||||
@ -214,6 +217,18 @@ namespace NadekoBot.Extensions
|
|||||||
return string.Concat(str.Take(maxLength - 3)) + (hideDots ? "" : "...");
|
return string.Concat(str.Take(maxLength - 3)) + (hideDots ? "" : "...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ToTitleCase(this string str)
|
||||||
|
{
|
||||||
|
var tokens = str.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
for (var i = 0; i < tokens.Length; i++)
|
||||||
|
{
|
||||||
|
var token = tokens[i];
|
||||||
|
tokens[i] = token.Substring(0, 1).ToUpper() + token.Substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Join(" ", tokens);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes trailing S or ES (if specified) on the given string if the num is 1
|
/// Removes trailing S or ES (if specified) on the given string if the num is 1
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user