NadekoBot/src/NadekoBot/Modules/Searches/Commands/PokemonSearchCommands.cs

96 lines
4.2 KiB
C#
Raw Normal View History

using Discord;
using Discord.Commands;
using NadekoBot.Attributes;
2016-12-09 03:22:23 +00:00
using NadekoBot.Extensions;
using NadekoBot.Modules.Searches.Models;
2016-06-26 19:33:25 +00:00
using Newtonsoft.Json;
using NLog;
2016-06-26 19:33:25 +00:00
using System.Collections.Generic;
using System.IO;
2016-12-09 03:22:23 +00:00
using System.Linq;
using System.Threading.Tasks;
2016-06-26 19:33:25 +00:00
namespace NadekoBot.Modules.Searches
2016-06-26 19:33:25 +00:00
{
public partial class Searches
2016-06-26 19:33:25 +00:00
{
[Group]
public class PokemonSearchCommands
2016-06-26 19:33:25 +00:00
{
2016-12-09 03:22:23 +00:00
private static Dictionary<string, SearchPokemon> pokemons { get; } = new Dictionary<string, SearchPokemon>();
private static Dictionary<string, SearchPokemonAbility> pokemonAbilities { get; } = new Dictionary<string, SearchPokemonAbility>();
2016-08-20 17:38:55 +00:00
2016-12-15 05:23:07 +00:00
public const string PokemonAbilitiesFile = "data/pokemon/pokemon_abilities7.json";
2016-08-20 17:38:55 +00:00
2016-12-15 05:23:07 +00:00
public const string PokemonListFile = "data/pokemon/pokemon_list7.json";
2016-12-09 03:22:23 +00:00
private static Logger _log { get; }
2016-06-26 19:33:25 +00:00
2016-12-08 17:35:34 +00:00
static PokemonSearchCommands()
{
_log = LogManager.GetCurrentClassLogger();
if (File.Exists(PokemonListFile))
{
pokemons = JsonConvert.DeserializeObject<Dictionary<string, SearchPokemon>>(File.ReadAllText(PokemonListFile));
}
else
_log.Warn(PokemonListFile + " is missing. Pokemon abilities not loaded.");
if (File.Exists(PokemonAbilitiesFile))
pokemonAbilities = JsonConvert.DeserializeObject<Dictionary<string, SearchPokemonAbility>>(File.ReadAllText(PokemonAbilitiesFile));
else
_log.Warn(PokemonAbilitiesFile + " is missing. Pokemon abilities not loaded.");
}
2016-06-26 19:33:25 +00:00
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Pokemon(IUserMessage umsg, [Remainder] string pokemon = null)
{
var channel = (ITextChannel)umsg.Channel;
2016-06-26 19:33:25 +00:00
pokemon = pokemon?.Trim().ToUpperInvariant();
if (string.IsNullOrWhiteSpace(pokemon))
return;
2016-06-26 19:33:25 +00:00
foreach (var kvp in pokemons)
2016-06-26 19:33:25 +00:00
{
if (kvp.Key.ToUpperInvariant() == pokemon.ToUpperInvariant())
2016-06-26 19:33:25 +00:00
{
2016-12-09 03:22:23 +00:00
var p = kvp.Value;
await channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
.WithTitle(kvp.Key.ToTitleCase())
.WithDescription(p.BaseStats.ToString())
.AddField(efb => efb.WithName("Types").WithValue(string.Join(",\n", p.Types)).WithIsInline(true))
.AddField(efb => efb.WithName("Height/Weight").WithValue($"{p.HeightM}m/{p.WeightKg}kg").WithIsInline(true))
.AddField(efb => efb.WithName("Abilitities").WithValue(string.Join(",\n", p.Abilities.Select(a => a.Value))).WithIsInline(true))
.Build());
return;
2016-06-26 19:33:25 +00:00
}
}
2016-12-09 03:22:23 +00:00
await channel.SendErrorAsync("No pokemon found.");
}
2016-06-26 19:33:25 +00:00
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task PokemonAbility(IUserMessage umsg, [Remainder] string ability = null)
{
var channel = (ITextChannel)umsg.Channel;
2016-06-26 19:33:25 +00:00
ability = ability?.Trim().ToUpperInvariant().Replace(" ", "");
if (string.IsNullOrWhiteSpace(ability))
return;
foreach (var kvp in pokemonAbilities)
{
if (kvp.Key.ToUpperInvariant() == ability)
{
2016-12-09 03:22:23 +00:00
await channel.EmbedAsync(new EmbedBuilder().WithColor(NadekoBot.OkColor)
.WithTitle(kvp.Value.Name)
.WithDescription(kvp.Value.Desc)
.AddField(efb => efb.WithName("Rating").WithValue(kvp.Value.Rating.ToString()).WithIsInline(true))
.Build()).ConfigureAwait(false);
return;
}
}
2016-12-09 03:22:23 +00:00
await channel.SendErrorAsync("No ability found.");
}
2016-06-26 19:33:25 +00:00
}
}
}