public dynamic Post([FromForm][Required] IFormFile pokemon, [FromForm] string generation, [FromForm] bool bot)
        {
            using var memoryStream = new MemoryStream();
            pokemon.CopyTo(memoryStream);
            byte[] data = memoryStream.ToArray();
            PKM    pkm;

            try
            {
                if (string.IsNullOrEmpty(generation))
                {
                    pkm = PKMConverter.GetPKMfromBytes(data);
                    if (pkm == null)
                    {
                        throw new ArgumentException("Bad data!");
                    }
                    generation = Utils.GetGeneration(pkm);
                }
                else
                {
                    //Console.WriteLine(generation
                    pkm = Utils.GetPKMwithGen(generation, data);
                    if (pkm == null)
                    {
                        throw new System.ArgumentException("Bad generation!");
                    }
                }

/*                Console.WriteLine(generation);
 *              Console.WriteLine(pkm.Species);
 *              Console.WriteLine(pkm.GetType());*/
                if (!Utils.PokemonExistsInGeneration(generation, pkm.Species))
                {
                    throw new ArgumentException("Pokemon is not in generation");
                }
                if (bot)
                {
                    return(new PokemonSummary(pkm, GameInfo.Strings));
                }
                else
                {
                    DefaultContractResolver contractResolver = new DefaultContractResolver
                    {
                        NamingStrategy = new SnakeCaseNamingStrategy()
                    };

                    PokemonSummary PS = new PokemonSummary(pkm, GameInfo.Strings);
                    return(JsonConvert.SerializeObject(PS, new JsonSerializerSettings
                    {
                        ContractResolver = contractResolver,
                        Formatting = Formatting.Indented
                    }));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(e.ToString());
            }
        }
Example #2
0
        public dynamic Showdown([FromForm][Required] string set, [FromForm] string generation)
        {
            ShowdownSet showdown;

            try
            {
                showdown = new ShowdownSet(set);
                var            sav    = SaveUtil.GetBlankSAV(Utils.GetGameVersion(generation), "Scatman");
                PKM            newPKM = sav.GetLegalFromSet(showdown, out var result);
                PokemonSummary pks    = new PokemonSummary(newPKM, GameInfo.Strings);
                if (pks.Species == "")
                {
                    throw new System.ArgumentException("Your Pokemon does not exist!");
                }

                DefaultContractResolver contractResolver = new DefaultContractResolver
                {
                    NamingStrategy = new SnakeCaseNamingStrategy()
                };


                Response.ContentType = "application/json";
                return(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(pks, new JsonSerializerSettings
                {
                    ContractResolver = contractResolver,
                    Formatting = Formatting.Indented
                })));
            } catch (Exception e) {
                dynamic error = new JObject();
                error.message = e.Message;
                return(StatusCode(400, error));
            }
        }
Example #3
0
        public async Task AddPokemonAsync(long discordUserId, long guildId, PokemonSummary pokemon)
        {
            AsyncDataReader dr = new AsyncDataReader("POKEMON_AddPokemonToInventory", _connectionString);

            dr.AddParameter("@DiscordGuildId", guildId);
            dr.AddParameter("@DiscordUserId", discordUserId);
            dr.AddParameter("@PokemonNumber", pokemon.Id);
            dr.AddParameter("@PokemonName", pokemon.Name);

            await dr.ExecuteNonQueryAsync();
        }
Example #4
0
 public Pokemon(PKM pk)
 {
     Summary = new PokemonSummary(pk, GameInfo.Strings);
 }
Example #5
0
        public Legalize(PKM pk, string version)
        {
            CancellationTokenSource cts = new CancellationTokenSource(10000);

            try
            {
                var al = new AutoLegality(pk, version, cts);
                if (al.OkayToRun)
                {
                    PKM    pkmn;
                    Thread thread = new Thread(() => {
                        al.LegalizePokemon(cts);
                    });
                    thread.Start();
                    while (true)
                    {
                        if (cts.IsCancellationRequested)
                        {
                            thread.Interrupt();
                            pkmn = al.GetLegalPK();
                            break;
                        }
                        Thread.Sleep(100);
                    }
                    Success = al.Successful;
                    Report  = al.Report.Split('\n');
                    Ran     = al.Ran;
                    if (Success)
                    {
                        try
                        {
                            Pokemon = Convert.ToBase64String(pkmn.DecryptedBoxData);
                            Species = new PokemonSummary(pkmn, GameInfo.Strings).Species;
                            try
                            {
                                QR = Utils.GenerateQR(QRMessageUtil.GetMessage(pkmn));
                            }
                            catch
                            {
                                QR = "";
                            }
                        }
                        catch
                        {
                            Pokemon = "";
                            Species = "";
                            Success = false;
                            Ran     = true;
                            Report  = new[] { "Stuck in legalization!" };
                        }
                    }
                    else
                    {
                        Pokemon = "";
                    }
                }
                else
                {
                    Ran     = false;
                    Success = false;
                    Report  = new[] { "Could not run legalization!" };
                }
            }
            catch (Exception e)
            {
                cts.Cancel();
                if (SentrySdk.IsEnabled)
                {
                    SentrySdk.ConfigureScope(scope =>
                    {
                        scope.Contexts["pokemon"] = new
                        {
                            Version = version,
                            Base64  = Convert.ToBase64String(pk.DecryptedBoxData)
                        };
                    });
                    SentrySdk.CaptureException(e);
                }
            }
        }