From daa9feb60ed0886e2ce12afb5bbf943fee0c1921 Mon Sep 17 00:00:00 2001 From: versx Date: Mon, 16 Dec 2019 02:47:22 -0800 Subject: [PATCH] - Add PvP subscriptions to `info` command. - Remove old min_rank from `PokemonSubscription` - Update en.xml - Fix typo --- src/Bot.cs | 4 +- src/Commands/Notifications.cs | 74 ++++++++++++++----- .../Models/PokemonSubscription.cs | 6 -- .../Subscriptions/Models/PvPSubscription.cs | 3 +- src/Extensions/DiscordExtensions.cs | 17 +++++ src/Strings.cs | 1 + static/locale/en.xml | 4 +- 7 files changed, 79 insertions(+), 30 deletions(-) diff --git a/src/Bot.cs b/src/Bot.cs index 84f43a23..10227bd8 100644 --- a/src/Bot.cs +++ b/src/Bot.cs @@ -252,11 +252,11 @@ private async Task Client_Ready(ReadyEventArgs e) { _logger.Info($"------------------------------------------"); _logger.Info($"[DISCORD] Connected."); - _logger.Info($"[DISCORD] Current Application:"); + _logger.Info($"[DISCORD] ----- Current Application"); _logger.Info($"[DISCORD] Name: {e.Client.CurrentApplication.Name}"); _logger.Info($"[DISCORD] Description: {e.Client.CurrentApplication.Description}"); _logger.Info($"[DISCORD] Owner: {e.Client.CurrentApplication.Owner.Username}#{e.Client.CurrentApplication.Owner.Discriminator}"); - _logger.Info($"[DISCORD] Current User:"); + _logger.Info($"[DISCORD] ----- Current User"); _logger.Info($"[DISCORD] Id: {e.Client.CurrentUser.Id}"); _logger.Info($"[DISCORD] Name: {e.Client.CurrentUser.Username}#{e.Client.CurrentUser.Discriminator}"); _logger.Info($"[DISCORD] Email: {e.Client.CurrentUser.Email}"); diff --git a/src/Commands/Notifications.cs b/src/Commands/Notifications.cs index 1c982ff5..0e02949b 100644 --- a/src/Commands/Notifications.cs +++ b/src/Commands/Notifications.cs @@ -558,10 +558,10 @@ public async Task RaidMeAsync(CommandContext ctx, var pokemonNames = validation.Valid.Select(x => MasterFile.Instance.Pokedex[x.Key].Name + (string.IsNullOrEmpty(x.Value) ? string.Empty : "-" + x.Value)); await ctx.RespondEmbed(_dep.Language.Translate("SUCCESS_RAID_SUBSCRIPTIONS_SUBSCRIBE").FormatText( - ctx.User.Username, + ctx.User.Username, string.Join("**, **", pokemonNames), - string.IsNullOrEmpty(city) ? - _dep.Language.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") : + string.IsNullOrEmpty(city) ? + _dep.Language.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") : _dep.Language.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(city)) ); _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); @@ -1041,7 +1041,7 @@ private InvasionGruntType GetLeaderGruntType(string leaderGruntType, PokemonGend return InvasionGruntType.ExecutiveSierra; else if (type.Contains("decoy")) return gender == PokemonGender.Male ? - InvasionGruntType.DecoyMale : + InvasionGruntType.DecoyMale : InvasionGruntType.DecoyFemale; return InvasionGruntType.Unset; @@ -1108,12 +1108,12 @@ public async Task PvpMeAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var pvpLeague = string.Compare(league, "great", true) == 0 ? - PvPLeague.Great : - string.Compare(league, "ultra", true) == 0 ? - PvPLeague.Ultra : - string.Compare(league, "master", true) == 0 ? - PvPLeague.Master : + var pvpLeague = string.Compare(league, "great", true) == 0 ? + PvPLeague.Great : + string.Compare(league, "ultra", true) == 0 ? + PvPLeague.Ultra : + string.Compare(league, "master", true) == 0 ? + PvPLeague.Master : PvPLeague.Other; //You may only subscribe to the top 100 or higher rank. @@ -1127,7 +1127,7 @@ public async Task PvpMeAsync(CommandContext ctx, if (minimumPercent < 0 || minimumPercent > 100) { await ctx.TriggerTypingAsync(); - await ctx.RespondEmbed(""); + await ctx.RespondEmbed(_dep.Language.Translate("NOTIFY_INVALID_PVP_RANK_RANGE").FormatText(ctx.User.Username, minimumPercent), DiscordColor.Red); return; } @@ -1156,7 +1156,7 @@ public async Task PvpMeAsync(CommandContext ctx, var pokemon = MasterFile.Instance.Pokedex[pokemonId]; var name = string.IsNullOrEmpty(form) ? pokemon.Name : pokemon.Name + "-" + form; - var subPkmn = subscription.PvP.FirstOrDefault(x => x.PokemonId == pokemonId && + var subPkmn = subscription.PvP.FirstOrDefault(x => x.PokemonId == pokemonId && string.Compare(x.Form, form, true) == 0 && x.League == pvpLeague); if (subPkmn == null) @@ -1201,10 +1201,10 @@ public async Task PvpMeAsync(CommandContext ctx, await ctx.RespondEmbed ( (subscribed.Count > 0 - ? $"{ctx.User.Username} has subscribed to **{string.Join("**, **", subscribed)}** notifications with a minimum {pvpLeague} League PvP ranking of {minimumRank} or lower and a minimum ranking percentage of {minimumPercent}%." + ? $"{ctx.User.Username} has subscribed to **{string.Join("**, **", subscribed)}** notifications with a minimum {pvpLeague} League PvP ranking of {minimumRank} or higher and a minimum ranking percentage of {minimumPercent}%." : string.Empty) + (alreadySubscribed.Count > 0 - ? $"\r\n{ctx.User.Username} is already subscribed to **{string.Join("**, **", alreadySubscribed)}** notifications with a minimum {pvpLeague} League PvP ranking of '{minimumRank}' or lower and a minimum ranking percentage of {minimumPercent}%." + ? $"\r\n{ctx.User.Username} is already subscribed to **{string.Join("**, **", alreadySubscribed)}** notifications with a minimum {pvpLeague} League PvP ranking of '{minimumRank}' or higher and a minimum ranking percentage of {minimumPercent}%." : string.Empty) ); _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); @@ -1512,6 +1512,7 @@ private async Task> BuildUserSubscriptionSettings(DiscordClient cli //var isSubbed = _dep.SubscriptionProcessor.Manager.UserExists(guildId, user.Id); var isSubbed = subscription?.Pokemon.Count > 0 || subscription?.Raids.Count > 0 || subscription?.Quests.Count > 0 || subscription?.Invasions.Count > 0 || subscription?.Gyms.Count > 0; var hasPokemon = isSubbed && subscription?.Pokemon.Count > 0; + var hasPvP = isSubbed && subscription?.PvP.Count > 0; var hasRaids = isSubbed && subscription?.Raids.Count > 0; var hasQuests = isSubbed && subscription?.Quests.Count > 0; var hasInvasions = isSubbed && subscription?.Invasions.Count > 0; @@ -1524,12 +1525,11 @@ private async Task> BuildUserSubscriptionSettings(DiscordClient cli feeds.Sort(); var sb = new StringBuilder(); - sb.AppendLine(_dep.Language.Translate("NOTIFY_SETTINGS_EMBED_ENABLED").FormatText(subscription.Enabled ? "Yes" : "No")); sb.AppendLine(_dep.Language.Translate("NOTIFY_SETTINGS_EMBED_CITIES").FormatText(string.Join(", ", feeds))); sb.AppendLine(_dep.Language.Translate("NOTIFY_SETTINGS_EMBED_ICON_STYLE").FormatText(subscription.IconStyle)); - sb.AppendLine(_dep.Language.Translate("NOTIFY_SETTINGS_EMBED_DISTANCE").FormatText(subscription.DistanceM == 0 ? - _dep.Language.Translate("NOTIFY_SETTINGS_EMBED_DISTANCE_NOT_SET") : + sb.AppendLine(_dep.Language.Translate("NOTIFY_SETTINGS_EMBED_DISTANCE").FormatText(subscription.DistanceM == 0 ? + _dep.Language.Translate("NOTIFY_SETTINGS_EMBED_DISTANCE_NOT_SET") : _dep.Language.Translate("NOTIFY_SETTINGS_EMBED_DISTANCE_KM").FormatText(subscription.DistanceM))); if (hasPokemon) @@ -1560,7 +1560,7 @@ private async Task> BuildUserSubscriptionSettings(DiscordClient cli foreach (var sub in results) { - if (sub.IV == defaultIV && exceedsLimits) + if (sub.IV == defaultIV && exceedsLimits) continue; foreach (var poke in sub.Pokes) @@ -1576,10 +1576,20 @@ private async Task> BuildUserSubscriptionSettings(DiscordClient cli sb.Append("```"); sb.AppendLine(); sb.AppendLine(); - messages.Add(sb.ToString()); ; + messages.Add(sb.ToString()); } var sb2 = new StringBuilder(); + if (hasPvP) + { + sb2.AppendLine(_dep.Language.Translate("NOTIFY_SETTINGS_EMBED_PVP").FormatText(subscription.PvP.Count.ToString("N0"), isSupporter ? "∞" : Strings.MaxPvPSubscriptions.ToString("N0"))); + sb2.Append("```"); + sb2.Append(string.Join(Environment.NewLine, GetPvPSubscriptionNames(guildId, user.Id))); + sb2.Append("```"); + sb2.AppendLine(); + sb2.AppendLine(); + } + if (hasRaids) { sb2.AppendLine(_dep.Language.Translate("NOTIFY_SETTINGS_EMBED_RAIDS").FormatText(subscription.Raids.Count.ToString("N0"), isSupporter ? "∞" : Strings.MaxRaidSubscriptions.ToString("N0"))); @@ -1644,6 +1654,30 @@ private async Task> BuildUserSubscriptionSettings(DiscordClient cli // return list; //} + private List GetPvPSubscriptionNames(ulong guildId, ulong userId) + { + var list = new List(); + //if (!_dep.SubscriptionProcessor.Manager.UserExists(guildId, userId)) + // return list; + + var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, userId); + var subscribedPvP = subscription.PvP; + subscribedPvP.Sort((x, y) => x.PokemonId.CompareTo(y.PokemonId)); + foreach (var pvp in subscribedPvP) + { + if (!MasterFile.Instance.Pokedex.ContainsKey(pvp.PokemonId)) + continue; + + var pokemon = MasterFile.Instance.Pokedex[pvp.PokemonId]; + if (pokemon == null) + continue; + + list.Add($"{pvp.PokemonId}: {pokemon.Name} {(string.IsNullOrEmpty(pvp.Form) ? string.Empty : $"Form: {pvp.Form} ")}({pvp.League} League Rank: 1-{pvp.MinimumRank} Percent: {pvp.MinimumPercent}%+)"); + } + + return list; + } + private List GetRaidSubscriptionNames(ulong guildId, ulong userId) { var list = new List(); @@ -1979,4 +2013,4 @@ private async Task CanExecute(CommandContext ctx) #endregion } -} +} \ No newline at end of file diff --git a/src/Data/Subscriptions/Models/PokemonSubscription.cs b/src/Data/Subscriptions/Models/PokemonSubscription.cs index 28d1d905..734461a2 100644 --- a/src/Data/Subscriptions/Models/PokemonSubscription.cs +++ b/src/Data/Subscriptions/Models/PokemonSubscription.cs @@ -73,12 +73,6 @@ public class PokemonSubscription : SubscriptionItem ] public int Stamina { get; set; } - [ - JsonProperty("min_rank"), - Alias("min_rank") - ] - public int MinimumRank { get; set; } - [ JsonIgnore, Ignore diff --git a/src/Data/Subscriptions/Models/PvPSubscription.cs b/src/Data/Subscriptions/Models/PvPSubscription.cs index 2b990e02..71b6bf06 100644 --- a/src/Data/Subscriptions/Models/PvPSubscription.cs +++ b/src/Data/Subscriptions/Models/PvPSubscription.cs @@ -33,7 +33,8 @@ public class PvPSubscription : SubscriptionItem [ JsonProperty("league"), - Alias("league") + Alias("league"), + Required ] public PvPLeague League { get; set; } diff --git a/src/Extensions/DiscordExtensions.cs b/src/Extensions/DiscordExtensions.cs index 10c63b05..c5ac1ad8 100644 --- a/src/Extensions/DiscordExtensions.cs +++ b/src/Extensions/DiscordExtensions.cs @@ -164,6 +164,23 @@ internal static async Task IsDirectMessageSupported(this DiscordMessage me return true; } + public static ulong ContextToGuild(this CommandContext ctx, Dictionary servers) + { + var keys = servers.Keys.ToList(); + for (var i = 0; i < keys.Count; i++) + { + var guildId = keys[i]; + if (!servers.ContainsKey(guildId)) + continue; + + if (ctx.Client.CurrentUser.Id != servers[guildId].CurrentUser.Id) + continue; + + return guildId; + } + return 0; + } + #region Roles public static bool IsSupporterOrHigher(this DiscordClient client, ulong userId, ulong guildId, WhConfig config) diff --git a/src/Strings.cs b/src/Strings.cs index 94d3683e..edb34851 100644 --- a/src/Strings.cs +++ b/src/Strings.cs @@ -46,6 +46,7 @@ internal static class Strings public const int MaxPokemonDisplayed = 70; public const int MaxPokemonSubscriptions = 25; + public const int MaxPvPSubscriptions = 15; public const int MaxRaidSubscriptions = 5; public const int MaxQuestSubscriptions = 2; public const int MaxInvasionSubscriptions = 1; diff --git a/static/locale/en.xml b/static/locale/en.xml index 6d6adf56..f5c91f4c 100644 --- a/static/locale/en.xml +++ b/static/locale/en.xml @@ -36,6 +36,7 @@ {0} Unable to recognize any of the Pokemon you specified. {0} is not subscribed to any Pokemon notifications. {0} {1} must be within the range of `0-4096`. + {0} {1} must be within the range of `0-100`. {0} are you sure you want to remove **all** {1} of your Pokemon subscriptions? Please reply back with `y` or `yes` to confirm. {0} has unsubscribed from **all** Pokemon notifications. @@ -78,8 +79,9 @@ Not Set (Any Distance) {0} kilometers - Pokemon Subscriptions: ({0}/{1} used) Default: {0}% ({1} unlisted) + Pokemon Subscriptions: ({0}/{1} used) + PvP Subscriptions: ({0}/{1} used) Raid Subscriptions: ({0}/{1} used) Quest Subscriptions: ({0}/{1} used) Invasion Subscriptions: ({0}/{1} used)