Skip to content

Commit

Permalink
- Add PvP subscriptions to info command.
Browse files Browse the repository at this point in the history
- Remove old min_rank from `PokemonSubscription`
- Update en.xml
- Fix typo
  • Loading branch information
versx committed Dec 16, 2019
1 parent 5fe9f3e commit daa9feb
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down
74 changes: 54 additions & 20 deletions src/Commands/Notifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1512,6 +1512,7 @@ private async Task<List<string>> 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;
Expand All @@ -1524,12 +1525,11 @@ private async Task<List<string>> 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)
Expand Down Expand Up @@ -1560,7 +1560,7 @@ private async Task<List<string>> 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)
Expand All @@ -1576,10 +1576,20 @@ private async Task<List<string>> 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")));
Expand Down Expand Up @@ -1644,6 +1654,30 @@ private async Task<List<string>> BuildUserSubscriptionSettings(DiscordClient cli
// return list;
//}

private List<string> GetPvPSubscriptionNames(ulong guildId, ulong userId)
{
var list = new List<string>();
//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<string> GetRaidSubscriptionNames(ulong guildId, ulong userId)
{
var list = new List<string>();
Expand Down Expand Up @@ -1979,4 +2013,4 @@ private async Task<bool> CanExecute(CommandContext ctx)

#endregion
}
}
}
6 changes: 0 additions & 6 deletions src/Data/Subscriptions/Models/PokemonSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Data/Subscriptions/Models/PvPSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class PvPSubscription : SubscriptionItem

[
JsonProperty("league"),
Alias("league")
Alias("league"),
Required
]
public PvPLeague League { get; set; }

Expand Down
17 changes: 17 additions & 0 deletions src/Extensions/DiscordExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,23 @@ internal static async Task<bool> IsDirectMessageSupported(this DiscordMessage me
return true;
}

public static ulong ContextToGuild(this CommandContext ctx, Dictionary<ulong, DiscordClient> 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)
Expand Down
1 change: 1 addition & 0 deletions src/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion static/locale/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<string name="NOTIFY_INVALID_POKEMON_SPECIFIED">{0} Unable to recognize any of the Pokemon you specified.</string>
<string name="NOTIFY_NO_POKEMON_SUBSCRIPTIONS">{0} is not subscribed to any Pokemon notifications.</string>
<string name="NOTIFY_INVALID_PVP_RANK_RANGE">{0} {1} must be within the range of `0-4096`.</string>
<string name="NOTIFY_INVALID_PVP_PERCENT_RANGE">{0} {1} must be within the range of `0-100`.</string>

<string name="NOTIFY_CONFIRM_REMOVE_ALL_POKEMON_SUBSCRIPTIONS">{0} are you sure you want to remove **all** {1} of your Pokemon subscriptions? Please reply back with `y` or `yes` to confirm.</string>
<string name="NOTIFY_SUCCESS_REMOVE_ALL_POKEMON_SUBSCRIPTIONS">{0} has unsubscribed from **all** Pokemon notifications.</string>
Expand Down Expand Up @@ -78,8 +79,9 @@
<string name="NOTIFY_SETTINGS_EMBED_DISTANCE_NOT_SET">Not Set (Any Distance)</string>
<string name="NOTIFY_SETTINGS_EMBED_DISTANCE_KM">{0} kilometers</string>

<string name="NOTIFY_SETTINGS_EMBED_POKEMON">Pokemon Subscriptions: ({0}/{1} used)</string>
<string name="NOTIFY_SETTINGS_EMBED_POKEMON_DEFAULT_UNLISTED">Default: {0}% ({1} unlisted)</string>
<string name="NOTIFY_SETTINGS_EMBED_POKEMON">Pokemon Subscriptions: ({0}/{1} used)</string>
<string name="NOTIFY_SETTINGS_EMBED_PVP">PvP Subscriptions: ({0}/{1} used)</string>
<string name="NOTIFY_SETTINGS_EMBED_RAIDS">Raid Subscriptions: ({0}/{1} used)</string>
<string name="NOTIFY_SETTINGS_EMBED_QUESTS">Quest Subscriptions: ({0}/{1} used)</string>
<string name="NOTIFY_SETTINGS_EMBED_INVASIONS">Invasion Subscriptions: ({0}/{1} used)</string>
Expand Down

0 comments on commit daa9feb

Please sign in to comment.