Skip to content

Commit

Permalink
Multiple Pokemon Per Subscription (#158)
Browse files Browse the repository at this point in the history
* Add initial support for multiple Pokemon subscriptions

* Add migration and account for `All` keyword

* Uncommand subscription commands

* Fix issue with multi subs

* Fix issue with PvP Great+Ultra league subscriptions

* Rename typos

* Remove excess checks and rename variables again

* Update migration

* version bump
  • Loading branch information
versx committed Jun 16, 2021
1 parent ab1f63c commit c689bdc
Show file tree
Hide file tree
Showing 30 changed files with 385 additions and 432 deletions.
2 changes: 2 additions & 0 deletions migrations/10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `pokemon`
MODIFY COLUMN `pokemon_id` text NOT NULL;
4 changes: 2 additions & 2 deletions src/Alarms/Filters/Models/FilterPokemonObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class FilterPokemonObject
/// </summary>
//TODO: Allow pokemon names and ids for pokemon filter.
[JsonProperty("pokemon")]
public List<int> Pokemon { get; set; }
public List<uint> Pokemon { get; set; }

/// <summary>
/// Gets or sets the list of pokemon Form strings to filter against
Expand Down Expand Up @@ -134,7 +134,7 @@ public class FilterPokemonObject
/// </summary>
public FilterPokemonObject()
{
Pokemon = new List<int>();
Pokemon = new List<uint>();
Forms = new List<string>();
Costumes = new List<string>();
MinimumIV = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Alarms/Filters/Models/FilterRaidObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class FilterRaidObject
/// </summary>
//TODO: Allow pokemon names and ids for raid filter.
[JsonProperty("pokemon")]
public List<int> Pokemon { get; set; }
public List<uint> Pokemon { get; set; }

/// <summary>
/// Gets or sets the list of Raid Boss Pokemon Form strings to filter against
Expand Down Expand Up @@ -78,7 +78,7 @@ public class FilterRaidObject
/// </summary>
public FilterRaidObject()
{
Pokemon = new List<int>();
Pokemon = new List<uint>();
Forms = new List<string>();
Costumes = new List<string>();
MinimumLevel = 1;
Expand Down
5 changes: 2 additions & 3 deletions src/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

// TODO: List all subscriptions with info command
// TODO: IV wildcards
// TODO: Egg subscriptions (maybe)

public class Bot
{
Expand Down Expand Up @@ -1039,10 +1038,10 @@ private async Task PostShinyStats(DiscordClient client, ulong guildId, DiscordSe
if (pokemon == 0)
continue;

if (!MasterFile.Instance.Pokedex.ContainsKey((int)pokemon))
if (!MasterFile.Instance.Pokedex.ContainsKey(pokemon))
continue;

var pkmn = MasterFile.Instance.Pokedex[(int)pokemon];
var pkmn = MasterFile.Instance.Pokedex[pokemon];
var pkmnStats = stats[pokemon];
var chance = pkmnStats.Shiny == 0 || pkmnStats.Total == 0 ? 0 : Convert.ToInt32(pkmnStats.Total / pkmnStats.Shiny);
if (chance == 0)
Expand Down
12 changes: 6 additions & 6 deletions src/Commands/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ public async Task SetAsync(CommandContext ctx,
[Description("Comma separated list of event Pokemon")] string eventPokemonIds = "0")
{
var eventPokemonSplit = eventPokemonIds.Split(',');
var pkmnToAdd = new List<int>();
var pkmnToAdd = new List<uint>();
var pkmnFailed = new List<string>();
for (var i = 0; i < eventPokemonSplit.Length; i++)
{
var eventPokemonId = eventPokemonSplit[i];
if (int.TryParse(eventPokemonId, out var pokemonId) && (pokemonId == 0 || MasterFile.Instance.Pokedex.ContainsKey(pokemonId)))
if (uint.TryParse(eventPokemonId, out var pokemonId) && (pokemonId == 0 || MasterFile.Instance.Pokedex.ContainsKey(pokemonId)))
{
pkmnToAdd.Add(pokemonId);
continue;
Expand Down Expand Up @@ -119,12 +119,12 @@ public async Task AddAsync(CommandContext ctx,
[Description("Comma separated list of event Pokemon")] string eventPokemonIds)
{
var eventPokemonSplit = eventPokemonIds.Split(',');
var pkmnToAdd = new List<int>();
var pkmnToAdd = new List<uint>();
var pkmnFailed = new List<string>();
for (var i = 0; i < eventPokemonSplit.Length; i++)
{
var eventPokemonId = eventPokemonSplit[i];
if (int.TryParse(eventPokemonId, out var pokemonId) && (pokemonId == 0 || MasterFile.Instance.Pokedex.ContainsKey(pokemonId)))
if (uint.TryParse(eventPokemonId, out var pokemonId) && (pokemonId == 0 || MasterFile.Instance.Pokedex.ContainsKey(pokemonId)))
{
pkmnToAdd.Add(pokemonId);
continue;
Expand Down Expand Up @@ -163,12 +163,12 @@ public async Task RemoveAsync(CommandContext ctx,
[Description("Command separated list of event Pokemon")] string eventPokemonIds)
{
var eventPokemonSplit = eventPokemonIds.Split(',');
var pkmnToRemove = new List<int>();
var pkmnToRemove = new List<uint>();
var pkmnFailed = new List<string>();
for (var i = 0; i < eventPokemonSplit.Length; i++)
{
var eventPokemonId = eventPokemonSplit[i];
if (int.TryParse(eventPokemonId, out var pokemonId) && (pokemonId == 0 || MasterFile.Instance.Pokedex.ContainsKey(pokemonId)))
if (uint.TryParse(eventPokemonId, out var pokemonId) && (pokemonId == 0 || MasterFile.Instance.Pokedex.ContainsKey(pokemonId)))
{
pkmnToRemove.Add(pokemonId);
continue;
Expand Down
7 changes: 3 additions & 4 deletions src/Commands/Input/SubscriptionInput.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using WhMgr.Configuration;

namespace WhMgr.Commands.Input
namespace WhMgr.Commands.Input
{
using System;
using System.Collections.Generic;
Expand All @@ -10,6 +8,7 @@ namespace WhMgr.Commands.Input
using DSharpPlus.CommandsNext;
using DSharpPlus.Entities;

using WhMgr.Configuration;
using WhMgr.Extensions;
using WhMgr.Localization;

Expand Down Expand Up @@ -38,7 +37,7 @@ public async Task<PokemonValidation> GetPokemonResult(uint maxPokemonId)
var pokemonMessage = (await _context.RespondEmbed("Enter either the Pokemon name(s) or Pokedex ID(s) separated by a comma to subscribe to (i.e. Mewtwo,Dragonite):", DiscordColor.Blurple)).FirstOrDefault();
var pokemonSubs = await _context.WaitForUserChoice();
// Validate the provided pokemon list
var validation = PokemonValidation.Validate(pokemonSubs, (int)maxPokemonId);
var validation = PokemonValidation.Validate(pokemonSubs, maxPokemonId);
if (validation == null || validation.Valid.Count == 0)
{
await _context.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_IDS_OR_NAMES").FormatText(_context.User.Username, string.Join(", ", validation.Invalid)), DiscordColor.Red);
Expand Down
Loading

0 comments on commit c689bdc

Please sign in to comment.