Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.75 KB | None | 0 0
  1. using Discord;
  2. using Discord.Commands;
  3. using NadekoBot.Extensions;
  4. using NadekoBot.Modules.Searches.Services;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using NadekoBot.Common.Attributes;
  9. using NadekoBot.Core.Common.Pokemon;
  10. using NadekoBot.Core.Services;
  11.  
  12. namespace NadekoBot.Modules.Searches
  13. {
  14.     public partial class Searches
  15.     {
  16.         [Group]
  17.         public class PokemonSearchCommands : NadekoSubmodule<SearchesService>
  18.         {
  19.             private readonly IDataCache _cache;
  20.  
  21.             public IReadOnlyDictionary<string, SearchPokemon> Pokemons => _cache.LocalData.Pokemons;
  22.             public IReadOnlyDictionary<string, SearchPokemonAbility> PokemonAbilities => _cache.LocalData.PokemonAbilities;
  23.  
  24.             public PokemonSearchCommands(IDataCache cache)
  25.             {
  26.                 _cache = cache;
  27.             }
  28.  
  29.             [NadekoCommand, Usage, Description, Aliases]
  30.             public async Task Pokemon([Remainder] string pokemon = null)
  31.             {
  32.                 pokemon = pokemon?.Trim().ToUpperInvariant();
  33.                 if (string.IsNullOrWhiteSpace(pokemon))
  34.                     return;
  35.  
  36.                 foreach (var kvp in Pokemons)
  37.                 {
  38.                     if (kvp.Key.ToUpperInvariant() == pokemon.ToUpperInvariant())
  39.                     {
  40.                         var p = kvp.Value;
  41.                         await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
  42.                             .WithTitle(kvp.Key.ToTitleCase())
  43.                             .WithDescription(p.BaseStats.ToString())
  44.                             .AddField(efb => efb.WithName(GetText("types")).WithValue(string.Join(",\n", p.Types)).WithIsInline(true))
  45.                             .AddField(efb => efb.WithName(GetText("height_weight")).WithValue(GetText("height_weight_val", p.HeightM, p.WeightKg)).WithIsInline(true))
  46.                             .AddField(efb => efb.WithName(GetText("abilities")).WithValue(string.Join(",\n", p.Abilities.Select(a => a.Value))).WithIsInline(true))
  47.                             .AddField(efb => efb.WithName(GetText("evos")).WithValue(string.Join(", ", p.Evos)).WithIsInline(false))
  48.                             .AddField(efb => efb.WithName(GetText("eggGroups")).WithValue(string.Join(", ", p.EggGroups)).WithIsInline(false)));
  49.                         return;
  50.                     }
  51.                 }
  52.                 await ReplyErrorLocalized("pokemon_none").ConfigureAwait(false);
  53.             }
  54.  
  55.             [NadekoCommand, Usage, Description, Aliases]
  56.             public async Task PokemonAbility([Remainder] string ability = null)
  57.             {
  58.                 ability = ability?.Trim().ToUpperInvariant().Replace(" ", "");
  59.                 if (string.IsNullOrWhiteSpace(ability))
  60.                     return;
  61.                 foreach (var kvp in PokemonAbilities)
  62.                 {
  63.                     if (kvp.Key.ToUpperInvariant() == ability)
  64.                     {
  65.                         await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
  66.                             .WithTitle(kvp.Value.Name)
  67.                             .WithDescription(string.IsNullOrWhiteSpace(kvp.Value.Desc)
  68.                                 ? kvp.Value.ShortDesc
  69.                                 : kvp.Value.Desc)
  70.                             .AddField(efb => efb.WithName(GetText("rating"))
  71.                                                 .WithValue(kvp.Value.Rating.ToString(_cultureInfo)).WithIsInline(true))
  72.                             ).ConfigureAwait(false);
  73.                         return;
  74.                     }
  75.                 }
  76.                 await ReplyErrorLocalized("pokemon_ability_none").ConfigureAwait(false);
  77.             }
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement