diff --git a/src/Bot.cs b/src/Bot.cs index 729cb6a4..84f43a23 100644 --- a/src/Bot.cs +++ b/src/Bot.cs @@ -29,7 +29,6 @@ //TODO: Reload config on change //TODO: PvP ranks dts //TODO: Separate subscriptions dts - //TODO: Translator singleton public class Bot { diff --git a/src/Commands/CommunityDay.cs b/src/Commands/CommunityDay.cs index e8e62c38..d2f11c3a 100644 --- a/src/Commands/CommunityDay.cs +++ b/src/Commands/CommunityDay.cs @@ -13,8 +13,6 @@ using WhMgr.Diagnostics; using WhMgr.Extensions; - //TODO: Expand with add/remove commands - [ Group("event"), Aliases("ev"), @@ -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 { @@ -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(','); @@ -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(); + var pkmnFailed = new List(); + 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(); + 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(); + var pkmnFailed = new List(); + 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(); + 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); + } } } \ No newline at end of file diff --git a/static/locale/en.xml b/static/locale/en.xml index 05600544..6d6adf56 100644 --- a/static/locale/en.xml +++ b/static/locale/en.xml @@ -146,4 +146,6 @@ {0} has unsubscribed from **all** {1} League PvP Pokemon notifications. {0} event Pokemon set to `{1}`, feeds will adjust to only show in channels that are 90% or higher. + {0} event Pokemon added to `{1}`, feeds will adjust to only show in channels that are 90% or higher. + {0} event Pokemon `{1}` removed. \ No newline at end of file