Skip to content

Commit

Permalink
More management commands for event pokemon
Browse files Browse the repository at this point in the history
  • Loading branch information
versx committed Dec 15, 2019
1 parent 134f795 commit ebc20ba
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
//TODO: Reload config on change
//TODO: PvP ranks dts
//TODO: Separate subscriptions dts
//TODO: Translator singleton

public class Bot
{
Expand Down
94 changes: 90 additions & 4 deletions src/Commands/CommunityDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
using WhMgr.Diagnostics;
using WhMgr.Extensions;

//TODO: Expand with add/remove commands

[
Group("event"),
Aliases("ev"),
Expand All @@ -38,7 +36,7 @@ public CommunityDay(Dependencies dep)
Aliases("l"),
Description("List all Pokemon considered as `event`.")
]
public async Task ListCommandDayAsync(CommandContext ctx)
public async Task ListAsync(CommandContext ctx)
{
var eb = new DiscordEmbedBuilder
{
Expand Down Expand Up @@ -70,7 +68,7 @@ public async Task ListCommandDayAsync(CommandContext ctx)
Aliases("s"),
Description("Sets a list of Pokemon as `event`.")
]
public async Task SetCommunityDayAsync(CommandContext ctx,
public async Task SetAsync(CommandContext ctx,
[Description("Comma separated list of event Pokemon")] string eventPokemonIds = "0")
{
var eventPokemonSplit = eventPokemonIds.Split(',');
Expand Down Expand Up @@ -108,5 +106,93 @@ public async Task SetCommunityDayAsync(CommandContext ctx,
}
await ctx.RespondEmbed(message);
}

[
Command("add"),
Aliases("a"),
Description("Adds one or more Pokemon to current `event` list.")
]
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 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)))
{
pkmnToAdd.Add(pokemonId);
continue;
}

pkmnFailed.Add(eventPokemonId);
}

_dep.WhConfig.EventPokemonIds.AddRange(pkmnToAdd);
_dep.WhConfig.Save(_dep.WhConfig.FileName);

var pkmnNames = new List<string>();
for (var i = 0; i < pkmnToAdd.Count; i++)
{
var pkmnId = pkmnToAdd[i];
if (MasterFile.Instance.Pokedex.ContainsKey(pkmnId))
{
pkmnNames.Add(pkmnId + ":" + MasterFile.Instance.Pokedex[pkmnId].Name);
}
}

var message = _dep.Language.Translate("EVENT_POKEMON_SET").FormatText(ctx.User.Username, string.Join(", ", pkmnNames));
if (pkmnFailed.Count > 0)
{
message += "\r\n" + _dep.Language.Translate("NOTIFY_INVALID_POKEMON_IDS_OR_NAMES").FormatText(ctx.User.Username, string.Join(", ", pkmnFailed));
}
await ctx.RespondEmbed(message);
}

[
Command("remove"),
Aliases("r", "rm"),
Description("Removes one or more Pokemon from `event` list.")
]
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 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)))
{
pkmnToRemove.Add(pokemonId);
continue;
}

pkmnFailed.Add(eventPokemonId);
}

pkmnToRemove.ForEach(x => _dep.WhConfig.EventPokemonIds.Remove(x));
_dep.WhConfig.Save(_dep.WhConfig.FileName);

var pkmnNames = new List<string>();
for (var i = 0; i < pkmnToRemove.Count; i++)
{
var pkmnId = pkmnToRemove[i];
if (MasterFile.Instance.Pokedex.ContainsKey(pkmnId))
{
pkmnNames.Add(pkmnId + ":" + MasterFile.Instance.Pokedex[pkmnId].Name);
}
}

var message = _dep.Language.Translate("EVENT_POKEMON_REMOVE").FormatText(ctx.User.Username, string.Join(", ", pkmnNames));
if (pkmnFailed.Count > 0)
{
message += "\r\n" + _dep.Language.Translate("NOTIFY_INVALID_POKEMON_IDS_OR_NAMES").FormatText(ctx.User.Username, string.Join(", ", pkmnFailed));
}
await ctx.RespondEmbed(message);
}
}
}
2 changes: 2 additions & 0 deletions static/locale/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,6 @@
<string name="NOTIFY_SUCCESS_REMOVE_ALL_PVP_SUBSCRIPTIONS">{0} has unsubscribed from **all** {1} League PvP Pokemon notifications.</string>

<string name="EVENT_POKEMON_SET">{0} event Pokemon set to `{1}`, feeds will adjust to only show in channels that are 90% or higher.</string>
<string name="EVENT_POKEMON_ADD">{0} event Pokemon added to `{1}`, feeds will adjust to only show in channels that are 90% or higher.</string>
<string name="EVENT_POKEMON_REMOVE">{0} event Pokemon `{1}` removed.</string>
</resources>

0 comments on commit ebc20ba

Please sign in to comment.