Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/versx/WhMgr
Browse files Browse the repository at this point in the history
  • Loading branch information
versx committed Dec 28, 2020
2 parents 60b38b5 + 693b2a9 commit 9c20016
Show file tree
Hide file tree
Showing 25 changed files with 161 additions and 175 deletions.
2 changes: 2 additions & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"emojiGuildId": 000000000000000001,
"ownerId": 000000000000000000,
"donorRoleIds": [],
"freeRoleName": "",
"moderatorRoleIds": [],
"token": "<DISCORD_BOT_TOKEN>",
"alarms": "alarms.json",
Expand Down Expand Up @@ -96,6 +97,7 @@
"emojiGuildId": 000000000000000001,
"ownerId": 000000000000000000,
"donorRoleIds": [],
"freeRoleName": "",
"moderatorRoleIds": [],
"token": "<DISCORD_BOT_TOKEN>",
"alarms": "alarms2.json",
Expand Down
2 changes: 1 addition & 1 deletion src/Alarms/Filters/Filters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
using System;

using POGOProtos.Enums;
using Gender = POGOProtos.Rpc.PokemonDisplayProto.Types.Gender;

using WhMgr.Diagnostics;
using WhMgr.Net.Models;
Expand Down
4 changes: 2 additions & 2 deletions src/Alarms/Filters/Models/FilterWeatherObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;

using Newtonsoft.Json;
using POGOProtos.Map.Weather;
using WeatherCondition = POGOProtos.Rpc.GameplayWeatherProto.Types.WeatherCondition;

/// <summary>
/// Weather filters
Expand All @@ -21,6 +21,6 @@ public class FilterWeatherObject
/// Filter by in-game weather type
/// </summary>
[JsonProperty("types")]
public List<GameplayWeather.Types.WeatherCondition> WeatherTypes { get; set; }
public List<WeatherCondition> WeatherTypes { get; set; }
}
}
45 changes: 10 additions & 35 deletions src/Commands/Feeds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ public async Task FeedMeAsync(CommandContext ctx,
return;

var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x));

var isSupporter = await ctx.Client.IsSupporterOrHigher(ctx.User.Id, guildId, _dep.WhConfig);
if (!_dep.WhConfig.Servers.ContainsKey(guildId))
return;

var server = _dep.WhConfig.Servers[guildId];
if (server.CitiesRequireSupporterRole && !isSupporter)
var isSupporter = await ctx.Client.IsSupporterOrHigher(ctx.User.Id, guildId, _dep.WhConfig);
var isFreeRole = string.IsNullOrEmpty(server.FreeRoleName) ? false : string.Compare(cityName, server.FreeRoleName, true) == 0;
if (server.CitiesRequireSupporterRole && !isSupporter && !isFreeRole)
{
await ctx.DonateUnlockFeaturesMessage();
return;
Expand All @@ -105,7 +105,7 @@ public async Task FeedMeAsync(CommandContext ctx,
var cityRoles = server.CityRoles.Select(x => x.ToLower());
foreach (var city in cityNames)
{
if (!cityRoles.Contains(city.ToLower()))
if (!isFreeRole && !cityRoles.Contains(city.ToLower()))
{
await ctx.RespondEmbed(Translator.Instance.Translate("FEEDS_INVALID_CITY_NAME_TYPE_COMMAND").FormatText(ctx.User.Username, city, server.CommandPrefix), DiscordColor.Red);
continue;
Expand All @@ -128,20 +128,6 @@ public async Task FeedMeAsync(CommandContext ctx,
alreadyAssigned.Add(cityRole.Name);
}

var cityRaidRole = ctx.Guild.GetRoleFromName($"{city}Raids");
if (cityRaidRole != null)
{
result = await AddFeedRole(ctx.Member, cityRaidRole);
if (result)
{
assigned.Add(cityRaidRole.Name);
}
else
{
alreadyAssigned.Add(cityRaidRole.Name);
}
}

Thread.Sleep(200);
}

Expand Down Expand Up @@ -178,9 +164,13 @@ public async Task FeedMeNotAsync(CommandContext ctx,
return;

var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x));
if (!_dep.WhConfig.Servers.ContainsKey(guildId))
return;

var server = _dep.WhConfig.Servers[guildId];
var isSupporter = await ctx.Client.IsSupporterOrHigher(ctx.User.Id, guildId, _dep.WhConfig);
if (_dep.WhConfig.Servers[guildId].CitiesRequireSupporterRole && !isSupporter)
var isFreeRole = string.IsNullOrEmpty(server.FreeRoleName) ? false : string.Compare(cityName, server.FreeRoleName, true) == 0;
if (server.CitiesRequireSupporterRole && !isSupporter && !isFreeRole)
{
await ctx.DonateUnlockFeaturesMessage();
return;
Expand All @@ -193,17 +183,15 @@ public async Task FeedMeNotAsync(CommandContext ctx,
return;
}

var server = _dep.WhConfig.Servers[guildId];
var unassigned = new List<string>();
var alreadyUnassigned = new List<string>();

try
{
var cityNames = cityName.RemoveSpaces();
var cityRoles = server.CityRoles;
foreach (var city in cityNames)
{
if (!cityRoles.Exists(x => string.Compare(city, x, true) == 0))
if (!isFreeRole && !server.CityRoles.Exists(x => string.Compare(city, x, true) == 0))
{
await ctx.RespondEmbed(Translator.Instance.Translate("FEEDS_INVALID_CITY_NAME_TYPE_COMMAND").FormatText(ctx.User.Username, city, server.CommandPrefix), DiscordColor.Red);
continue;
Expand All @@ -225,19 +213,6 @@ public async Task FeedMeNotAsync(CommandContext ctx,
alreadyUnassigned.Add(cityRole.Name);
}

var cityRaidRole = ctx.Guild.GetRoleFromName($"{city}Raids");
if (cityRaidRole == null)
continue;

if (await RemoveFeedRole(ctx.Member, cityRaidRole))
{
unassigned.Add(cityRaidRole.Name);
}
else
{
alreadyUnassigned.Add(cityRaidRole.Name);
}

Thread.Sleep(200);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Nests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using POGOProtos.Enums;
using POGOProtos.Rpc;
using ServiceStack;
using ServiceStack.OrmLite;

Expand Down Expand Up @@ -186,7 +186,7 @@ public IReadOnlyDictionary<string, string> GetProperties(DiscordGuild guild, Nes
var pkmnImage = pokemonImageUrl;
var nestName = nest.Name ?? "Unknown";
var type1 = pkmnInfo?.Types?[0];
var type2 = pkmnInfo?.Types?.Count > 1 ? pkmnInfo.Types?[1] : PokemonType.None;
var type2 = pkmnInfo?.Types?.Count > 1 ? pkmnInfo.Types?[1] : HoloPokemonType.PokemonTypeNone;
var type1Emoji = pkmnInfo?.Types?[0].GetTypeEmojiIcons();
var type2Emoji = pkmnInfo?.Types?.Count > 1 ? pkmnInfo?.Types?[1].GetTypeEmojiIcons() : string.Empty;
var typeEmojis = $"{type1Emoji} {type2Emoji}";
Expand Down
52 changes: 22 additions & 30 deletions src/Commands/Notifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace WhMgr.Commands
using DSharpPlus.CommandsNext.Attributes;
using DSharpPlus.Entities;
using Newtonsoft.Json;
using POGOProtos.Enums;
using POGOProtos.Rpc;

using WhMgr.Commands.Input;
using WhMgr.Data;
Expand Down Expand Up @@ -353,7 +353,6 @@ public async Task PokeMeAsync(CommandContext ctx,
// If so, make sure they specified at least 90% or higher
if (realIV < 90)
{
await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_MINIMUM_IV").FormatText(ctx.User.Username), DiscordColor.Red);
return;
}
Expand Down Expand Up @@ -388,7 +387,6 @@ public async Task PokeMeAsync(CommandContext ctx,
{
if (!MasterFile.Instance.Pokedex.ContainsKey(pokemonId))
{
await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_ID").FormatText(ctx.User.Username, pokemonId), DiscordColor.Red);
continue;
}
Expand All @@ -399,7 +397,6 @@ public async Task PokeMeAsync(CommandContext ctx,
// Check if common type pokemon e.g. Pidgey, Ratatta, Spinarak 'they are beneath him and he refuses to discuss them further'
if (pokemonId.IsCommonPokemon() && realIV < Strings.CommonTypeMinimumIV && !isModOrHigher)
{
await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_COMMON_TYPE_POKEMON").FormatText(ctx.User.Username, pokemon.Name, Strings.CommonTypeMinimumIV), DiscordColor.Red);
continue;
}
Expand Down Expand Up @@ -1163,49 +1160,49 @@ await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_INVASION_SUBSCRIPT
_dep.SubscriptionProcessor.Manager.ReloadSubscriptions();
}

public static PokemonType GetPokemonTypeFromString(string pokemonType)
public static HoloPokemonType GetPokemonTypeFromString(string pokemonType)
{
var type = pokemonType.ToLower();
if (type.Contains("bug"))
return PokemonType.Bug;
return HoloPokemonType.PokemonTypeBug;
else if (type.Contains("dark"))
return PokemonType.Dark;
return HoloPokemonType.PokemonTypeDark;
else if (type.Contains("dragon"))
return PokemonType.Dragon;
return HoloPokemonType.PokemonTypeDragon;
else if (type.Contains("electric"))
return PokemonType.Electric;
return HoloPokemonType.PokemonTypeElectric;
else if (type.Contains("fairy"))
return PokemonType.Fairy;
return HoloPokemonType.PokemonTypeFairy;
else if (type.Contains("fighting") || type.Contains("fight"))
return PokemonType.Fighting;
return HoloPokemonType.PokemonTypeFighting;
else if (type.Contains("fire"))
return PokemonType.Fire;
return HoloPokemonType.PokemonTypeFire;
else if (type.Contains("flying") || type.Contains("fly"))
return PokemonType.Flying;
return HoloPokemonType.PokemonTypeFlying;
else if (type.Contains("ghost"))
return PokemonType.Ghost;
return HoloPokemonType.PokemonTypeGhost;
else if (type.Contains("grass"))
return PokemonType.Grass;
return HoloPokemonType.PokemonTypeGrass;
else if (type.Contains("ground"))
return PokemonType.Ground;
return HoloPokemonType.PokemonTypeGround;
else if (type.Contains("ice"))
return PokemonType.Ice;
return HoloPokemonType.PokemonTypeIce;
//else if (type.Contains("tierii") || type.Contains("none") || type.Contains("tier2") || type.Contains("t2"))
// return PokemonType.None;
else if (type.Contains("normal"))
return PokemonType.Normal;
return HoloPokemonType.PokemonTypeNormal;
else if (type.Contains("poison"))
return PokemonType.Poison;
return HoloPokemonType.PokemonTypePoison;
else if (type.Contains("psychic"))
return PokemonType.Psychic;
return HoloPokemonType.PokemonTypePsychic;
else if (type.Contains("rock"))
return PokemonType.Rock;
return HoloPokemonType.PokemonTypeRock;
else if (type.Contains("steel"))
return PokemonType.Steel;
return HoloPokemonType.PokemonTypeSteel;
else if (type.Contains("water"))
return PokemonType.Water;
return HoloPokemonType.PokemonTypeWater;
else
return PokemonType.None;
return HoloPokemonType.PokemonTypeNone;
}

#endregion
Expand Down Expand Up @@ -1248,14 +1245,12 @@ public async Task PvpMeAsync(CommandContext ctx,
//You may only subscribe to the top 100 or higher rank.
if (minimumRank < Strings.MinimumRank || minimumRank > Strings.MaximumRank)
{
await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_PVP_RANK_RANGE").FormatText(ctx.User.Username, minimumRank), DiscordColor.Red);
return;
}

if (minimumPercent < Strings.MinimumPercent || minimumPercent > Strings.MaximumPercent)
{
await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_PVP_RANK_RANGE").FormatText(ctx.User.Username, minimumPercent), DiscordColor.Red);
return;
}
Expand Down Expand Up @@ -1283,7 +1278,6 @@ public async Task PvpMeAsync(CommandContext ctx,
{
if (!MasterFile.Instance.Pokedex.ContainsKey(pokemonId))
{
await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_ID").FormatText(ctx.User.Username, pokemonId), DiscordColor.Red);
continue;
}
Expand Down Expand Up @@ -1381,7 +1375,6 @@ public async Task PvpMeNotAsync(CommandContext ctx,
var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id);
if (subscription == null || subscription?.PvP?.Count == 0)
{
await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_NO_POKEMON_SUBSCRIPTIONS").FormatText(ctx.User.Username), DiscordColor.Red);
return;
}
Expand Down Expand Up @@ -1411,7 +1404,6 @@ public async Task PvpMeNotAsync(CommandContext ctx,
.ToList()?
.ForEach(x => x.Id.Remove<PvPSubscription>());

await ctx.TriggerTypingAsync();
await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_SUCCESS_REMOVE_ALL_PVP_SUBSCRIPTIONS").FormatText(ctx.User.Username, pvpLeague));
_dep.SubscriptionProcessor.Manager.ReloadSubscriptions();
return;
Expand Down Expand Up @@ -2603,7 +2595,7 @@ public async Task ImportAsync(CommandContext ctx)
var oldSubscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id);
if (oldSubscription != null)
{
var result = Data.Subscriptions.SubscriptionManager.RemoveAllUserSubscriptions(guildId, ctx.User.Id);
var result = SubscriptionManager.RemoveAllUserSubscriptions(guildId, ctx.User.Id);
if (!result)
{
_logger.Error($"Failed to clear old user subscriptions for {ctx.User.Username} ({ctx.User.Id}) in guild {ctx.Guild?.Name} ({ctx.Guild?.Id}) before importing.");
Expand Down
3 changes: 3 additions & 0 deletions src/Configuration/DiscordServerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class DiscordServerConfig
[JsonProperty("donorRoleIds")]
public List<ulong> DonorRoleIds { get; set; }

[JsonProperty("freeRoleName")]
public string FreeRoleName { get; set; }

/// <summary>
/// Gets or sets the moderators of the Discord server
/// </summary>
Expand Down
22 changes: 11 additions & 11 deletions src/Data/MasterFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using InvasionCharacter = POGOProtos.Enums.EnumWrapper.Types.InvasionCharacter;
using POGOProtos.Enums;
using POGOProtos.Rpc;
using InvasionCharacter = POGOProtos.Rpc.EnumWrapper.Types.InvasionCharacter;

using WhMgr.Data.Models;
using WhMgr.Diagnostics;
Expand Down Expand Up @@ -49,7 +49,7 @@ public class MasterFile
public IReadOnlyDictionary<InvasionCharacter, TeamRocketInvasion> GruntTypes { get; set; }

[JsonProperty("pokemon_types")]
public IReadOnlyDictionary<PokemonType, PokemonTypes> PokemonTypes { get; set; }
public IReadOnlyDictionary<HoloPokemonType, PokemonTypes> PokemonTypes { get; set; }

[JsonIgnore]
public IReadOnlyDictionary<double, double> CpMultipliers { get; }
Expand Down Expand Up @@ -124,23 +124,23 @@ public static T LoadInit<T>(string filePath)
public class PokemonTypes
{
[JsonProperty("immunes")]
public List<PokemonType> Immune { get; set; }
public List<HoloPokemonType> Immune { get; set; }

[JsonProperty("weaknesses")]
public List<PokemonType> Weaknesses { get; set; }
public List<HoloPokemonType> Weaknesses { get; set; }

[JsonProperty("resistances")]
public List<PokemonType> Resistances { get; set; }
public List<HoloPokemonType> Resistances { get; set; }

[JsonProperty("strengths")]
public List<PokemonType> Strengths { get; set; }
public List<HoloPokemonType> Strengths { get; set; }

public PokemonTypes()
{
Immune = new List<PokemonType>();
Weaknesses = new List<PokemonType>();
Resistances = new List<PokemonType>();
Strengths = new List<PokemonType>();
Immune = new List<HoloPokemonType>();
Weaknesses = new List<HoloPokemonType>();
Resistances = new List<HoloPokemonType>();
Strengths = new List<HoloPokemonType>();
}
}

Expand Down
Loading

0 comments on commit 9c20016

Please sign in to comment.