From 91b696d4982a3e36705fe4940feea2e740c6214d Mon Sep 17 00:00:00 2001 From: versx Date: Sun, 5 Jul 2020 21:58:46 -0700 Subject: [PATCH 01/19] Add set-number command --- src/Commands/Notifications.cs | 28 ++++++++++++++++++++++++++++ static/locale/en.json | 1 + 2 files changed, 29 insertions(+) diff --git a/src/Commands/Notifications.cs b/src/Commands/Notifications.cs index 1907e961..ee0ed0ed 100644 --- a/src/Commands/Notifications.cs +++ b/src/Commands/Notifications.cs @@ -137,6 +137,34 @@ public async Task SetDistanceAsync(CommandContext ctx, _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); } + [ + Command("set-number"), + Description("Set the phone number to receive text message notifications for ultra rare pokemon.") + ] + public async Task SetPhoneNumberAsync(CommandContext ctx, + [Description("10 digit phone number to receive text message alerts for")] string phoneNumber) + { + if (!await CanExecute(ctx)) + return; + + // Check if user is in list of acceptable users to receive Pokemon text message notifications + if (!_dep.WhConfig.Twilio.UserIds.Contains(ctx.User.Id)) + return; + + var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(ctx.Guild.Id, ctx.User.Id); + if (subscription == null) + { + await ctx.RespondEmbed(Translator.Instance.Translate("MSG_USER_NOT_SUBSCRIBED").FormatText(ctx.User.Username), DiscordColor.Red); + return; + } + + subscription.PhoneNumber = phoneNumber; + subscription.Save(); + + await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_PHONE_NUMBER_SET").FormatText(ctx.User.Username, phoneNumber)); + _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + } + [ Command("expire"), Aliases("expires"), diff --git a/static/locale/en.json b/static/locale/en.json index ff9eaaad..e90efa5c 100644 --- a/static/locale/en.json +++ b/static/locale/en.json @@ -19,6 +19,7 @@ "NOTIFY_INVALID_COORDINATES": "{0} Unable not parse {1} as valid coordinates.", "NOTIFY_DISTANCE_SET": "{0} Notifications only within a {1} meter radius of location {2},{3} will be sent.", + "NOTIFY_PHONE_NUMBER_SET": "{0} Text message notifications for ultra rare Pokemon will be sent to {1}.", "NOTIFY_INVALID_IV_VALUES": "{0} {1} is not a valid value. (Example: `0-15-6`)", "NOTIFY_INVALID_ATTACK_VALUE": "{0} {1} is not a valid attack value. Must be between `0-15`.", From 0d4cbea49bf05d505399fb39063173de4d2ecf64 Mon Sep 17 00:00:00 2001 From: versx Date: Mon, 6 Jul 2020 06:16:27 -0700 Subject: [PATCH 02/19] Fix null reference error --- src/Data/Subscriptions/SubscriptionProcessor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/Subscriptions/SubscriptionProcessor.cs b/src/Data/Subscriptions/SubscriptionProcessor.cs index 588aed09..1110e19a 100644 --- a/src/Data/Subscriptions/SubscriptionProcessor.cs +++ b/src/Data/Subscriptions/SubscriptionProcessor.cs @@ -749,7 +749,7 @@ private void ProcessQueue() _whConfig.Servers[item.Subscription.GuildId].OwnerId == item.Member.Id) { // Send text message (max 160 characters) - if (IsUltraRare(_whConfig.Twilio, item.Pokemon)) + if (item.Pokemon != null && IsUltraRare(_whConfig.Twilio, item.Pokemon)) { var result = Utils.SendSmsMessage(StripEmbed(item), _whConfig.Twilio, item.Subscription.PhoneNumber); if (!result) From 9d2575077becdcce58cf90dd243171910b562ac3 Mon Sep 17 00:00:00 2001 From: versx Date: Mon, 6 Jul 2020 08:15:46 -0700 Subject: [PATCH 03/19] Show 'All' when subscribing to all invasions --- src/Commands/Notifications.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Commands/Notifications.cs b/src/Commands/Notifications.cs index ee0ed0ed..10a65d4f 100644 --- a/src/Commands/Notifications.cs +++ b/src/Commands/Notifications.cs @@ -996,9 +996,10 @@ public async Task InvMeAsync(CommandContext ctx, } subscription.Save(); + var valid = validation.Valid.Keys.Select(x => MasterFile.GetPokemon(x, 0).Name); await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_INVASION_SUBSCRIPTIONS_SUBSCRIBE").FormatText( ctx.User.Username, - string.Join(", ", validation.Valid.Keys.Select(x => MasterFile.GetPokemon(x, 0).Name)), + string.Compare(poke, Strings.All, true) == 0 ? Strings.All : string.Join(", ", valid), string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(city)) @@ -1085,9 +1086,10 @@ await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_NO_INVASION_SUBSCRIP } } + var valid = validation.Valid.Keys.Select(x => MasterFile.GetPokemon(x, 0).Name); await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_INVASION_SUBSCRIPTIONS_UNSUBSCRIBE").FormatText( ctx.User.Username, - string.Join(", ", validation.Valid.Keys.Select(x => MasterFile.GetPokemon(x, 0).Name)), + string.Compare(poke, Strings.All, true) == 0 ? Strings.All : string.Join(", ", valid), string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(city)) From 2e047702a62443fb64c6662c1e0bd86eff9da167 Mon Sep 17 00:00:00 2001 From: versx Date: Mon, 6 Jul 2020 08:18:24 -0700 Subject: [PATCH 04/19] Show 'All' when subscribing to all raids --- src/Commands/Notifications.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Commands/Notifications.cs b/src/Commands/Notifications.cs index 10a65d4f..8eefe779 100644 --- a/src/Commands/Notifications.cs +++ b/src/Commands/Notifications.cs @@ -635,7 +635,7 @@ 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(Translator.Instance.Translate("SUCCESS_RAID_SUBSCRIPTIONS_SUBSCRIBE").FormatText( ctx.User.Username, - string.Join("**, **", pokemonNames), + string.Compare(poke, Strings.All, true) == 0 ? Strings.All : string.Join("**, **", pokemonNames), string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(city)) @@ -729,7 +729,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_NO_RAID_SUBSCRIPTION var pokemonNames = validation.Valid.Select(x => MasterFile.Instance.Pokedex[x.Key].Name + (string.IsNullOrEmpty(x.Value) ? string.Empty : "-" + x.Value)); await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_RAID_SUBSCRIPTIONS_UNSUBSCRIBE").FormatText( ctx.User.Username, - string.Join("**, **", pokemonNames), + string.Compare(poke, Strings.All, true) == 0 ? Strings.All : string.Join("**, **", pokemonNames), string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(city)) From 799e9aa52bd8f649025e1e5805d48e4a5405e222 Mon Sep 17 00:00:00 2001 From: versx Date: Mon, 6 Jul 2020 08:18:54 -0700 Subject: [PATCH 05/19] Fix error with nest icon --- src/Commands/Nests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/Nests.cs b/src/Commands/Nests.cs index ea1cbd74..e4b8eb57 100644 --- a/src/Commands/Nests.cs +++ b/src/Commands/Nests.cs @@ -79,7 +79,7 @@ public async Task PostNestsAsync(CommandContext ctx) try { - var pkmnImage = nest.PokemonId.GetPokemonIcon(0, 0, _dep.WhConfig, _dep.WhConfig.IconStyles[server.IconStyle]); + var pkmnImage = nest.PokemonId.GetPokemonIcon(0, 0, _dep.WhConfig, server.IconStyle); var eb = GenerateNestMessage(ctx.Guild.Id, ctx.Client, nest, pkmnImage); var geofences = _dep.Whm.Geofences.Values.ToList(); var geofence = GeofenceService.GetGeofence(geofences, new Location(nest.Latitude, nest.Longitude)); From 07d0b0a8072c612883b415c83117b9ec192046e9 Mon Sep 17 00:00:00 2001 From: versx Date: Mon, 6 Jul 2020 08:59:22 -0700 Subject: [PATCH 06/19] Fix nests DTS typo --- examples/Alerts/default.json | 2 +- src/Alarms/Alerts/AlertMessage.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Alerts/default.json b/examples/Alerts/default.json index fbf67c53..139326d4 100644 --- a/examples/Alerts/default.json +++ b/examples/Alerts/default.json @@ -118,7 +118,7 @@ }, "nests": { "avatarUrl": "", - "content": "**Pokemon:**
**Average Spawns:** /h | **Types:**
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + "content": "**Pokemon:**
**Average Spawns:** /h | **Types:**
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", "iconUrl": "", "title": ": ", "url": "", diff --git a/src/Alarms/Alerts/AlertMessage.cs b/src/Alarms/Alerts/AlertMessage.cs index 8d566539..558dda93 100644 --- a/src/Alarms/Alerts/AlertMessage.cs +++ b/src/Alarms/Alerts/AlertMessage.cs @@ -164,7 +164,7 @@ public class AlertMessage : Dictionary AlertMessageType.Nests, new AlertMessageSettings { AvatarUrl = "", - Content = "**Pokemon:**
**Average Spawns:** /h | **Types:**
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + Content = "**Pokemon:**
**Average Spawns:** /h | **Types:**
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", IconUrl = "", Title = ": ", Url = "", From f4adc66e5685379a570e445e02c42759cc5e6ff2 Mon Sep 17 00:00:00 2001 From: versx Date: Mon, 6 Jul 2020 09:33:15 -0700 Subject: [PATCH 07/19] Update grass url for static map --- examples/Templates/pokemon.example.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Templates/pokemon.example.json b/examples/Templates/pokemon.example.json index 0ef1b633..bdb2c717 100644 --- a/examples/Templates/pokemon.example.json +++ b/examples/Templates/pokemon.example.json @@ -2,7 +2,7 @@ "staticmap_url": "{{tilemaps_url}}", "markers": [ { - "url": "https://raw.githubusercontent.com/versx/WhMgr-Assets/master/new/misc/grass.png", + "url": "https://raw.githubusercontent.com/versx/WhMgr-Assets/master/original/misc/grass.png", "height": "48", "width": "48", "x_offset": 0, From bcadfd13f29a3ac46a00550ecbe02057894705b7 Mon Sep 17 00:00:00 2001 From: versx Date: Mon, 6 Jul 2020 11:32:12 -0700 Subject: [PATCH 08/19] Add support for dynamic gym icons in static maps templates for gym, egg, and raid alarms --- examples/Templates/raids.example.json | 10 +++++++++- src/Commands/Nests.cs | 2 +- src/Net/Models/GymDetailsData.cs | 2 +- src/Net/Models/PokemonData.cs | 2 +- src/Net/Models/PokestopData.cs | 2 +- src/Net/Models/QuestData.cs | 2 +- src/Net/Models/RaidData.cs | 2 +- src/Net/Models/WeatherData.cs | 2 +- src/Utilities/Utils.cs | 8 ++++++-- 9 files changed, 22 insertions(+), 10 deletions(-) diff --git a/examples/Templates/raids.example.json b/examples/Templates/raids.example.json index 0d50b8ca..3048e02d 100644 --- a/examples/Templates/raids.example.json +++ b/examples/Templates/raids.example.json @@ -1,11 +1,19 @@ { "staticmap_url": "{{tilemaps_url}}", "markers": [{ + "url": "https://raw.githubusercontent.com/versx/WhMgr-Assets/master/original/gyms/gym_{{team_id}}.png", + "height": "32", + "width": "32", + "x_offset": 0, + "y_offset": 0, + "latitude": "{{lat}}", + "longitude": "{{lon}}" + },{ "url": "{{pkmn_img_url}}", "height": "32", "width": "32", "x_offset": 0, - "y_offset": 0, + "y_offset": -25, "latitude": "{{lat}}", "longitude": "{{lon}}" }] diff --git a/src/Commands/Nests.cs b/src/Commands/Nests.cs index e4b8eb57..b409df49 100644 --- a/src/Commands/Nests.cs +++ b/src/Commands/Nests.cs @@ -137,7 +137,7 @@ public IReadOnlyDictionary GetProperties(Nest nest, string pokem var appleMapsLink = string.Format(Strings.AppleMaps, nest.Latitude, nest.Longitude); var wazeMapsLink = string.Format(Strings.WazeMaps, nest.Latitude, nest.Longitude); var templatePath = Path.Combine(_dep.WhConfig.StaticMaps.TemplatesFolder, _dep.WhConfig.StaticMaps.NestsTemplateFile); - var staticMapLink = Utils.GetStaticMapsUrl(templatePath, _dep.WhConfig.Urls.StaticMap, nest.Latitude, nest.Longitude, pkmnImage, _dep.OsmManager.GetNest(nest.Name)?.FirstOrDefault()); + var staticMapLink = Utils.GetStaticMapsUrl(templatePath, _dep.WhConfig.Urls.StaticMap, nest.Latitude, nest.Longitude, pkmnImage, null, _dep.OsmManager.GetNest(nest.Name)?.FirstOrDefault()); var geofences = _dep.Whm.Geofences.Values.ToList(); var geofence = GeofenceService.GetGeofence(geofences, new Location(nest.Latitude, nest.Longitude)); var city = geofence?.Name ?? "Unknown"; diff --git a/src/Net/Models/GymDetailsData.cs b/src/Net/Models/GymDetailsData.cs index ef87ae4b..63ee4d46 100644 --- a/src/Net/Models/GymDetailsData.cs +++ b/src/Net/Models/GymDetailsData.cs @@ -99,7 +99,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh // TODO: Use team icon for gym var gymImage = "https://static.thenounproject.com/png/727778-200.png"; var templatePath = Path.Combine(whConfig.StaticMaps.TemplatesFolder, whConfig.StaticMaps.GymsTemplateFile); - var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap.Replace("/15/", "/11/"), Latitude, Longitude, gymImage); + var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap.Replace("/15/", "/11/"), Latitude, Longitude, gymImage, Team); //var staticMapLink = string.Format(whConfig.Urls.StaticMap, Latitude, Longitude);//whConfig.Urls.StaticMap.Gyms.Enabled ? string.Format(whConfig.Urls.StaticMap.Gyms.Url, Latitude, Longitude) : string.Empty var gmapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? gmapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, gmapsLink); var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); diff --git a/src/Net/Models/PokemonData.cs b/src/Net/Models/PokemonData.cs index caba0712..b5cad74f 100644 --- a/src/Net/Models/PokemonData.cs +++ b/src/Net/Models/PokemonData.cs @@ -460,7 +460,7 @@ private async Task> GetProperties(DiscordGui var appleMapsLink = string.Format(Strings.AppleMaps, Latitude, Longitude); var wazeMapsLink = string.Format(Strings.WazeMaps, Latitude, Longitude); var templatePath = Path.Combine(whConfig.StaticMaps.TemplatesFolder, whConfig.StaticMaps.PokemonTemplateFile); - var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap, Latitude, Longitude, pokemonImageUrl); + var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap, Latitude, Longitude, pokemonImageUrl, null); var gmapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? gmapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, gmapsLink); var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); diff --git a/src/Net/Models/PokestopData.cs b/src/Net/Models/PokestopData.cs index e9e87cb3..30c35bde 100644 --- a/src/Net/Models/PokestopData.cs +++ b/src/Net/Models/PokestopData.cs @@ -148,7 +148,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var appleMapsLink = string.Format(Strings.AppleMaps, Latitude, Longitude); var wazeMapsLink = string.Format(Strings.WazeMaps, Latitude, Longitude); var templatePath = Path.Combine(whConfig.StaticMaps.TemplatesFolder, HasInvasion ? whConfig.StaticMaps.InvasionsTemplateFile : HasLure ? whConfig.StaticMaps.LuresTemplateFile : whConfig.StaticMaps.LuresTemplateFile); - var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap, Latitude, Longitude, imageUrl); + var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap, Latitude, Longitude, imageUrl, null); var gmapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? gmapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, gmapsLink); var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); diff --git a/src/Net/Models/QuestData.cs b/src/Net/Models/QuestData.cs index 8d862aae..4dd77c2e 100644 --- a/src/Net/Models/QuestData.cs +++ b/src/Net/Models/QuestData.cs @@ -114,7 +114,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var appleMapsLink = string.Format(Strings.AppleMaps, Latitude, Longitude); var wazeMapsLink = string.Format(Strings.WazeMaps, Latitude, Longitude); var templatePath = Path.Combine(whConfig.StaticMaps.TemplatesFolder, whConfig.StaticMaps.QuestsTemplateFile); - var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap, Latitude, Longitude, questRewardImageUrl); + var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap, Latitude, Longitude, questRewardImageUrl, null); var gmapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? gmapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, gmapsLink); var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); diff --git a/src/Net/Models/RaidData.cs b/src/Net/Models/RaidData.cs index 03e3d074..f742aee9 100644 --- a/src/Net/Models/RaidData.cs +++ b/src/Net/Models/RaidData.cs @@ -199,7 +199,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var appleMapsLink = string.Format(Strings.AppleMaps, Latitude, Longitude); var wazeMapsLink = string.Format(Strings.WazeMaps, Latitude, Longitude); var templatePath = Path.Combine(whConfig.StaticMaps.TemplatesFolder, whConfig.StaticMaps.RaidsTemplateFile); - var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap, Latitude, Longitude, raidImageUrl); + var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap, Latitude, Longitude, raidImageUrl, Team); var gmapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? gmapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, gmapsLink); var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); diff --git a/src/Net/Models/WeatherData.cs b/src/Net/Models/WeatherData.cs index d0bf77b4..97196745 100644 --- a/src/Net/Models/WeatherData.cs +++ b/src/Net/Models/WeatherData.cs @@ -148,7 +148,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var appleMapsLink = string.Format(Strings.AppleMaps, Latitude, Longitude); var wazeMapsLink = string.Format(Strings.WazeMaps, Latitude, Longitude); var templatePath = Path.Combine(whConfig.StaticMaps.TemplatesFolder, whConfig.StaticMaps.WeatherTemplateFile); - var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap.Replace("/15/", "/11/"), Latitude, Longitude, weatherImageUrl); + var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap.Replace("/15/", "/11/"), Latitude, Longitude, weatherImageUrl, null); var gmapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? gmapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, gmapsLink); var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); diff --git a/src/Utilities/Utils.cs b/src/Utilities/Utils.cs index a082823b..7a7bf8a8 100644 --- a/src/Utilities/Utils.cs +++ b/src/Utilities/Utils.cs @@ -9,23 +9,27 @@ using Twilio.Rest.Api.V2010.Account; using WhMgr.Configuration; + using WhMgr.Net.Models; using WhMgr.Osm; using WhMgr.Osm.Models; public static class Utils { - public static string GetStaticMapsUrl(string templateFileName, string staticMapUrl, double latitude, double longitude, string markerImageUrl, OsmFeature feature = null, MultiPolygon multiPolygon = null) + // TODO: Provide better way for replacement values + public static string GetStaticMapsUrl(string templateFileName, string staticMapUrl, double latitude, double longitude, string markerImageUrl, PokemonTeam? team, OsmFeature feature = null, MultiPolygon multiPolygon = null) { var staticMapData = Renderer.Parse(templateFileName, new { lat = latitude, lon = longitude, + team = team?.ToString(), + team_id = Convert.ToInt32(team ?? 0), marker = markerImageUrl, pkmn_img_url = markerImageUrl, quest_reward_img_url = markerImageUrl, weather_img_url = markerImageUrl, tilemaps_url = staticMapUrl - }); + }); ; StaticMapConfig staticMap = JsonConvert.DeserializeObject(staticMapData); var url = string.Format(staticMapUrl, latitude, longitude); From 3f88899d0fa1ea2fccd839100d6674b270f29e78 Mon Sep 17 00:00:00 2001 From: versx Date: Mon, 6 Jul 2020 12:58:15 -0700 Subject: [PATCH 09/19] Update docs and examples --- README.md | 20 ++++++++++++++++---- alarms.example.json | 5 +++-- docs/commands/subscriptions.md | 23 ++++++++++++----------- docs/index.md | 14 +++++++++----- docs/user-guide/alarms.md | 4 ++++ docs/user-guide/filters.md | 15 ++++++++++++--- examples/Filters/default.json | 14 ++++++++++++-- src/Bot.cs | 1 + 8 files changed, 69 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 967124d6..d1c90f70 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ bitsadmin /transfer dotnet-install-job /download /priority FOREGROUND https://ra b.) Input your bot token and config options. ```js { + // Http listening interface for raw webhook data. + "host": "10.0.0.10", // Http listener port for raw webhook data. "port": 8008, // Locale language translation @@ -65,7 +67,7 @@ bitsadmin /transfer dotnet-install-job /download /priority FOREGROUND https://ra "commandPrefix": ".", // Discord server server ID. "guildId": 000000000000000001, - // Discord Emoji server ID. (Can be same as `guildId`, currently not implemented, set as `guildId`) + // Discord Emoji server ID. (Can be same as `guildId`) "emojiGuildId": 000000000000000001, // Discord server owner ID. "ownerId": 000000000000000000, @@ -170,7 +172,7 @@ bitsadmin /transfer dotnet-install-job /download /priority FOREGROUND https://ra // Brock database name. "database": "brock3" }, - // Scanner databse config + // Scanner database config "scanner": { // Database hostname or IP address. "host": "127.0.0.1", @@ -213,14 +215,23 @@ bitsadmin /transfer dotnet-install-job /download /priority FOREGROUND https://ra "Default": "https://raw.githubusercontent.com/versx/WhMgr-Assets/master/original/", "Shuffle": "https://raw.githubusercontent.com/versx/WhMgr-Assets/master/shuffle/" }, + // Custom static map template files for each alarm type "staticMaps": { + // Static map template for Pokemon "pokemon": "pokemon.example.json", + // Static map template for Raids and Eggs "raids": "raids.example.json", + // Static map template for field research quests "quests": "quests.example.json", + // Static map template for Team Rocket invasions "invasions": "invasions.example.json", + // Static map template for Pokestop lures "lures": "lures.example.json", + // Static map template for Gym team control changes "gyms": "gyms.example.json", + // Static map template for nest postings "nests": "nests.example.json", + // Static map template for weather changes "weather": "weather.example.json" }, // Get text message alerts with Twilio.com @@ -283,7 +294,7 @@ bitsadmin /transfer dotnet-install-job /download /priority FOREGROUND https://ra "geofence":"geofence1.txt", //DTS compatible mention description. - "mentions":" L " + "mentions":" L ", //Discord webhook url address. "webhook":"" @@ -362,6 +373,7 @@ bitsadmin /transfer dotnet-install-job /download /priority FOREGROUND https://ra * `info` List all Pokemon, Raid, Quest, Invasion, and Gym subscriptions and settings * `set-distance` Set minimum distance to Pokemon, raids, quests, invasions and gyms need to be within. (Measured in meters) * `expire` / `expires` Check stripe API when Donor/Supporter subscription expires +* `set-number` Sets the phone number to use for text message alerts for ultra rare Pokemon **Pokemon Subscriptions** * `pokeme` Subscribe to specific Pokemon notifications @@ -734,7 +746,7 @@ Discord Team Rocket Invasion Notifications: ![Team Rocket Invasion Notifications](images/invasions.png "Team Rocket Invasion Notifications") ## Current Issues: -- Gender icon comes in as `?` so -m and -f are used for now. +- Pokemon subscriptions are based on Discord city roles assigned currently, soon it will be based on specified cities. ## Credits: [versx](https://github.com/versx) - Developer diff --git a/alarms.example.json b/alarms.example.json index 4f169f7c..c54473e9 100644 --- a/alarms.example.json +++ b/alarms.example.json @@ -12,6 +12,7 @@ "alerts": "default.json", "filters":"all.json", "geofence":"City1.txt", + "mentions":" L ", "webhook":"" }, { @@ -71,10 +72,10 @@ "webhook":"" }, { - "name":"City2-Weather", + "name":"City1-Weather", "alerts": "default.json", "filters":"weather.json", - "geofence":"City2.txt", + "geofence":"City1.txt", "webhook":"" }, { diff --git a/docs/commands/subscriptions.md b/docs/commands/subscriptions.md index 10ac3f57..44bcc9a9 100644 --- a/docs/commands/subscriptions.md +++ b/docs/commands/subscriptions.md @@ -6,6 +6,8 @@ **disable** - Disable direct message subscription notifications. **info** - List all Pokemon, Raid, Quest, Invasion, and Gym subscriptions and settings. **expire** / **expires** - Check stripe API when Donor/Supporter subscription expires. +**set-number** - Set a phone number to receive text message alerts for ultra rare Pokemon. + **set-distance** - Set minimum distance to Pokemon, raids, quests, invasions and gyms need to be within. (Measured in kilometers) Usage: `set-distance ,` @@ -23,7 +25,7 @@ Examples: Usage: `pokeme [iv] [level] [gender]` * `` - Parameter can take a list of Ids or names or the `all` keyword for everything. -* `` - (Optional) Minimum IV value. +* `` - (Optional) Minimum IV value, or individual attack, defense, and stamina values i.e. `0-14-15` * `` - (Optional) Minimum level value. * `` - (Optional) Specific gender `m` or `f` or `*` for all. @@ -31,6 +33,7 @@ Examples: * `.pokeme tyranitar` * `.pokeme pikachu 100 35 f` +* `.pokeme Skarmory 0-15-15 12` * `.pokeme pikachu 100` * `.pokeme all 100 35`
@@ -135,29 +138,27 @@ Examples: ### Team Rocket Invasions **invme** - Subscribe to specific Team Rocket invasion notifications. -Usage: `invme - [city]` +Usage: `invme [city]` -* `` - Grunt Pokemon type i.e. `fire`, `water` -* `` - Grunt gender i.e. `male` | `m` | `female` | `f` +* `` - Reward Pokemon i.e. `Dratini`, `147` * `[city]` - (Optional) City name to get the notifications for or leave blank for all available cities. Examples: -* `.invme tier2-f` -* `.invme ground-male city1` +* `.invme Beldum` +* `.invme beldum city1`
**invmenot** - Unsubscribe from specific Team Rocket invasion notifications. -Usage: `invmenot - [city]` +Usage: `invmenot [city]` -* `` - Grunt Pokemon type i.e. `fire`, `water` -* `` - Grunt gender i.e. `male` | `m` | `female` | `f` +* `` - Pokemon reward i.e. `Pikachu`, `25` * `[city]` - (Optional) City name to get the notifications for or leave blank for all available cities. Examples: -* `.invmenot tier2-f` -* `.invmenot ground-male city1` +* `.invmenot Bulbasaur` +* `.invmenot Dratini city1` * `.invmenot all`
diff --git a/docs/index.md b/docs/index.md index f546b198..5543df75 100644 --- a/docs/index.md +++ b/docs/index.md @@ -2,6 +2,7 @@ Works with [RealDeviceMap](https://github.com/123FLO321/RealDeviceMap) +Made in C#, runs on .NET Core CLR. Cross platform compatibility, can run on Windows, macOS, and Linux operating systems. Parses and sends Discord notifications based on pre-defined filters for Pokemon, raids, raid eggs, field research quests, gym team control changes, and weather changes. Also supports Discord user's subscribing to Pokemon, raid, quest, or Team Rocket invasion notifications via direct messages. ## Features: @@ -28,12 +29,15 @@ Parses and sends Discord notifications based on pre-defined filters for Pokemon, - Lots more... ### Frameworks and Libraries -- .NET Framework v4.6.2 -- DSharpPlus v3.2.3 -- ServiceStack.OrmLite.MySql v5.7.0 -- Stripe.net v34.1.0 +- .NET Core v2.1.803 +- DSharpPlus v3.2.3 +- DSharpPlus.CommandsNext v3.2.3 +- DSharpPlus.Interactivity v3.2.3 +- Microsoft.Win32.SystemEvents v4.7.0 - Newtonsoft.Json v12.0.3 -- MySql.Data v8.0.18 +- ServiceStack.OrmLite.MySql v5.8.0 +- Stripe.net v37.14.0 +- Twilio v5.44.0 [Click here](user-guide/config) to get started! diff --git a/docs/user-guide/alarms.md b/docs/user-guide/alarms.md index d013bd0e..918f2e6e 100644 --- a/docs/user-guide/alarms.md +++ b/docs/user-guide/alarms.md @@ -17,6 +17,8 @@ There is no limit to the amount of alarms you can add under the `alarms` propert "enablePokestops": true, //Enable or disable Gym alarms globally "enableGyms": true, + //Enable or disable Weather alarms globally + "enableWeather": true, //List of alarms "alarms": [ @@ -27,6 +29,8 @@ There is no limit to the amount of alarms you can add under the `alarms` propert "alerts": "default.json", //Alarm filters "filters":"all.json", + //Mentionable string that supports DTS + "mentions":" L ", //Geofence file name "geofence":"City1.txt", //Discord webhook url address diff --git a/docs/user-guide/filters.md b/docs/user-guide/filters.md index 5df91862..229ebbf0 100644 --- a/docs/user-guide/filters.md +++ b/docs/user-guide/filters.md @@ -16,6 +16,8 @@ Filters allow you to narrow down what is reported. All filters are options and c "size": "Big", //Tiny, Small, Normal, Large, Big "great_league": true, //Great League "ultra_league": true, //Ultra League + "min_rank": 1, //Minimum rank of #1 PVP stats + "max_rank": 5, //Maximum rank of #5 PVP stats "type": "Include", //Include or Exclude the `pokemon` list "ignoreMissing": true //Ignore Pokemon missing stats }, @@ -40,8 +42,8 @@ Filters allow you to narrow down what is reported. All filters are options and c { "enabled": true, //Filter is enabled "rewards": ["spinda", "nincada"], //Quest reward string (Chansey, stardust, candy, etc.) - "type": "Include", //Include or Exclude the `rewards` list - "isShiny": false //Only shiny encounter quests. + "isShiny": false, //Only shiny encounter quests. + "type": "Include" //Include or Exclude the `rewards` list }, "pokestops": { @@ -51,7 +53,14 @@ Filters allow you to narrow down what is reported. All filters are options and c }, "gyms": { - "enabled": true //Filter is enabled + "enabled": true, //Filter is enabled + "underAttack": true, //Only gyms that are under attack + "team": "All" //Team change to notify about (i.e. Neutral/Mystic/Valor/Instinct/All) + }, + "weather": + { + "enabled": true, //Filter is enabled + "types": ["Clear", "Rain", "PartlyCloudy", "Cloudy", "Windy", "Snow", "Fog"] //Only send weather types that are in the list } } ``` \ No newline at end of file diff --git a/examples/Filters/default.json b/examples/Filters/default.json index 676d1586..b27e8eb0 100644 --- a/examples/Filters/default.json +++ b/examples/Filters/default.json @@ -11,6 +11,8 @@ "size": "Big", //Tiny, Small, Normal, Large, Big "great_league": true, //Great League "ultra_league": true, //Ultra League + "min_rank": 1, //Minimum rank of #1 PVP stats + "max_rank": 5, //Maximum rank of #5 PVP stats "type": "Include", //Include or Exclude the `pokemon` list "ignoreMissing": true //Ignore Pokemon missing stats }, @@ -35,7 +37,8 @@ { "enabled": true, //Filter is enabled "rewards": ["spinda", "nincada"], //Quest reward string (Chansey, stardust, candy, etc.) - "isShiny": false //Only shiny encounter quests. + "isShiny": false, //Only shiny encounter quests. + "type": "Include" //Include or Exclude the `rewards` list }, "pokestops": { @@ -45,6 +48,13 @@ }, "gyms": { - "enabled": true //Filter is enabled + "enabled": true, //Filter is enabled + "underAttack": true, //Only gyms that are under attack + "team": "All" //Team change to notify about (i.e. Neutral/Mystic/Valor/Instinct/All) + }, + "weather": + { + "enabled": true, //Filter is enabled + "types": ["Clear", "Rain", "PartlyCloudy", "Cloudy", "Windy", "Snow", "Fog"] //Only send weather types that are in the list } } \ No newline at end of file diff --git a/src/Bot.cs b/src/Bot.cs index af782067..f7038ce2 100644 --- a/src/Bot.cs +++ b/src/Bot.cs @@ -32,6 +32,7 @@ // TODO: List all subscriptions with info command // TODO: Manage subscriptions via DM again // TODO: Multiple discord bot tokens per server + // TODO: Add map url to config and DTS options public class Bot { From 3fe59334bdc59d4b20b438604f71e2f85fef481e Mon Sep 17 00:00:00 2001 From: versx Date: Mon, 6 Jul 2020 13:46:08 -0700 Subject: [PATCH 10/19] Updated staticmap templates --- examples/Templates/gyms.example.json | 8 ++++++++ examples/Templates/invasions.example.json | 10 +++++++++- examples/Templates/lures.example.json | 10 +++++++++- examples/Templates/weather.example.json | 4 ++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/examples/Templates/gyms.example.json b/examples/Templates/gyms.example.json index 7a5b4d64..68ad87a2 100644 --- a/examples/Templates/gyms.example.json +++ b/examples/Templates/gyms.example.json @@ -1,6 +1,14 @@ { "staticmap_url": "{{tilemaps_url}}", "markers": [{ + "url": "https://raw.githubusercontent.com/versx/WhMgr-Assets/master/original/gyms/gym_{{team_id}}.png", + "height": "32", + "width": "32", + "x_offset": 0, + "y_offset": 0, + "latitude": "{{lat}}", + "longitude": "{{lon}}" + },{ "url": "{{marker}}", "height": "32", "width": "32", diff --git a/examples/Templates/invasions.example.json b/examples/Templates/invasions.example.json index 7a5b4d64..4f836643 100644 --- a/examples/Templates/invasions.example.json +++ b/examples/Templates/invasions.example.json @@ -1,11 +1,19 @@ { "staticmap_url": "{{tilemaps_url}}", "markers": [{ + "url": "https://raw.githubusercontent.com/versx/WhMgr-Assets/master/original/misc/pokestop_invasion.png", + "height": "32", + "width": "32", + "x_offset": 0, + "y_offset": 0, + "latitude": "{{lat}}", + "longitude": "{{lon}}" + },{ "url": "{{marker}}", "height": "32", "width": "32", "x_offset": 0, - "y_offset": 0, + "y_offset": -25, "latitude": "{{lat}}", "longitude": "{{lon}}" }] diff --git a/examples/Templates/lures.example.json b/examples/Templates/lures.example.json index 7a5b4d64..ab10f766 100644 --- a/examples/Templates/lures.example.json +++ b/examples/Templates/lures.example.json @@ -1,11 +1,19 @@ { "staticmap_url": "{{tilemaps_url}}", "markers": [{ + "url": "https://raw.githubusercontent.com/versx/WhMgr-Assets/master/original/misc/pokestop.png", + "height": "32", + "width": "32", + "x_offset": 0, + "y_offset": 0, + "latitude": "{{lat}}", + "longitude": "{{lon}}" + },{ "url": "{{marker}}", "height": "32", "width": "32", "x_offset": 0, - "y_offset": 0, + "y_offset": -25, "latitude": "{{lat}}", "longitude": "{{lon}}" }] diff --git a/examples/Templates/weather.example.json b/examples/Templates/weather.example.json index cd1613d6..ae39196e 100644 --- a/examples/Templates/weather.example.json +++ b/examples/Templates/weather.example.json @@ -2,8 +2,8 @@ "staticmap_url": "{{tilemaps_url}}", "markers": [{ "url": "{{weather_img_url}}", - "height": "32", - "width": "32", + "height": "48", + "width": "48", "x_offset": 0, "y_offset": 0, "latitude": "{{lat}}", From 5fa57eaede1d9ad60d2f0c6246df184ff07e2d08 Mon Sep 17 00:00:00 2001 From: versx Date: Tue, 7 Jul 2020 15:59:22 -0700 Subject: [PATCH 11/19] Rename folders --- examples/{Alerts => alerts}/default.json | 0 examples/{Filters => filters}/0iv.json | 0 examples/{Filters => filters}/100iv.json | 0 examples/{Filters => filters}/100iv_basura.json | 0 examples/{Filters => filters}/100iv_lvl30.json | 0 examples/{Filters => filters}/100iv_lvl35.json | 0 examples/{Filters => filters}/100iv_rare.json | 0 examples/{Filters => filters}/100iv_ultra.json | 0 examples/{Filters => filters}/3rd_evo.json | 0 examples/{Filters => filters}/90iv.json | 0 examples/{Filters => filters}/90iv_cd.json | 0 examples/{Filters => filters}/90iv_gible.json | 0 examples/{Filters => filters}/90iv_lvl34.json | 0 examples/{Filters => filters}/90iv_snorlax.json | 0 examples/{Filters => filters}/96iv.json | 0 examples/{Filters => filters}/98iv.json | 0 examples/{Filters => filters}/98iv_cd.json | 0 examples/{Filters => filters}/all.json | 0 examples/{Filters => filters}/axew.json | 0 examples/{Filters => filters}/bagon.json | 0 examples/{Filters => filters}/beldum.json | 0 examples/{Filters => filters}/bronzor.json | 0 examples/{Filters => filters}/chansey.json | 0 examples/{Filters => filters}/clamperl.json | 0 examples/{Filters => filters}/cranidos.json | 0 examples/{Filters => filters}/darumaka.json | 0 examples/{Filters => filters}/default.json | 0 examples/{Filters => filters}/deino.json | 0 examples/{Filters => filters}/ditto.json | 0 examples/{Filters => filters}/dratini.json | 0 examples/{Filters => filters}/drilbur.json | 0 examples/{Filters => filters}/durant.json | 0 examples/{Filters => filters}/dwebble.json | 0 examples/{Filters => filters}/ex_raids.json | 0 examples/{Filters => filters}/feebas.json | 0 examples/{Filters => filters}/ferroseed.json | 0 examples/{Filters => filters}/gible.json | 0 examples/{Filters => filters}/golett.json | 0 examples/{Filters => filters}/gyms.json | 0 examples/{Filters => filters}/heatmor.json | 0 examples/{Filters => filters}/invasions.json | 0 examples/{Filters => filters}/lake_trio.json | 0 examples/{Filters => filters}/lapras.json | 0 examples/{Filters => filters}/larvitar.json | 0 examples/{Filters => filters}/legendary_raids.json | 0 examples/{Filters => filters}/litwick.json | 0 examples/{Filters => filters}/lunatone.json | 0 examples/{Filters => filters}/lures.json | 0 examples/{Filters => filters}/magikarp.json | 0 examples/{Filters => filters}/mawile_raids.json | 0 examples/{Filters => filters}/pvp1500cp.json | 0 examples/{Filters => filters}/pvp1500cp_rank1.json | 0 examples/{Filters => filters}/pvp1500cp_rank5.json | 0 examples/{Filters => filters}/pvp2500cp.json | 0 examples/{Filters => filters}/pvp2500cp_rank1.json | 0 examples/{Filters => filters}/pvp2500cp_rank5.json | 0 examples/{Filters => filters}/quests.json | 0 examples/{Filters => filters}/quests_absol.json | 0 examples/{Filters => filters}/quests_aerodactyl.json | 0 examples/{Filters => filters}/quests_chansey.json | 0 examples/{Filters => filters}/quests_dratini.json | 0 examples/{Filters => filters}/quests_golden_pinap.json | 0 examples/{Filters => filters}/quests_lapras.json | 0 examples/{Filters => filters}/quests_larvitar.json | 0 examples/{Filters => filters}/quests_nincada.json | 0 examples/{Filters => filters}/quests_rare.json | 0 examples/{Filters => filters}/quests_seel.json | 0 examples/{Filters => filters}/quests_spinda.json | 0 examples/{Filters => filters}/raids.json | 0 examples/{Filters => filters}/ralts.json | 0 examples/{Filters => filters}/shieldon.json | 0 examples/{Filters => filters}/shinx_raids.json | 0 examples/{Filters => filters}/shiny_raids.json | 0 examples/{Filters => filters}/skorupi.json | 0 examples/{Filters => filters}/snorlax.json | 0 examples/{Filters => filters}/solrock.json | 0 examples/{Filters => filters}/unown.json | 0 examples/{Filters => filters}/wailmer.json | 0 examples/{Filters => filters}/weather.json | 0 examples/{Filters => filters}/xl_karp.json | 0 examples/{Filters => filters}/xs_rat.json | 0 examples/{Geofences => geofences}/Paris.txt | 0 examples/{Geofences => geofences}/ParisLondon.txt | 0 examples/{Templates => templates}/gyms.example.json | 0 examples/{Templates => templates}/invasions.example.json | 0 examples/{Templates => templates}/lures.example.json | 0 examples/{Templates => templates}/nests.example.json | 0 examples/{Templates => templates}/pokemon.example.json | 0 examples/{Templates => templates}/quests.example.json | 0 examples/{Templates => templates}/raids.example.json | 0 examples/{Templates => templates}/weather.example.json | 0 91 files changed, 0 insertions(+), 0 deletions(-) rename examples/{Alerts => alerts}/default.json (100%) rename examples/{Filters => filters}/0iv.json (100%) rename examples/{Filters => filters}/100iv.json (100%) rename examples/{Filters => filters}/100iv_basura.json (100%) rename examples/{Filters => filters}/100iv_lvl30.json (100%) rename examples/{Filters => filters}/100iv_lvl35.json (100%) rename examples/{Filters => filters}/100iv_rare.json (100%) rename examples/{Filters => filters}/100iv_ultra.json (100%) rename examples/{Filters => filters}/3rd_evo.json (100%) rename examples/{Filters => filters}/90iv.json (100%) rename examples/{Filters => filters}/90iv_cd.json (100%) rename examples/{Filters => filters}/90iv_gible.json (100%) rename examples/{Filters => filters}/90iv_lvl34.json (100%) rename examples/{Filters => filters}/90iv_snorlax.json (100%) rename examples/{Filters => filters}/96iv.json (100%) rename examples/{Filters => filters}/98iv.json (100%) rename examples/{Filters => filters}/98iv_cd.json (100%) rename examples/{Filters => filters}/all.json (100%) rename examples/{Filters => filters}/axew.json (100%) rename examples/{Filters => filters}/bagon.json (100%) rename examples/{Filters => filters}/beldum.json (100%) rename examples/{Filters => filters}/bronzor.json (100%) rename examples/{Filters => filters}/chansey.json (100%) rename examples/{Filters => filters}/clamperl.json (100%) rename examples/{Filters => filters}/cranidos.json (100%) rename examples/{Filters => filters}/darumaka.json (100%) rename examples/{Filters => filters}/default.json (100%) rename examples/{Filters => filters}/deino.json (100%) rename examples/{Filters => filters}/ditto.json (100%) rename examples/{Filters => filters}/dratini.json (100%) rename examples/{Filters => filters}/drilbur.json (100%) rename examples/{Filters => filters}/durant.json (100%) rename examples/{Filters => filters}/dwebble.json (100%) rename examples/{Filters => filters}/ex_raids.json (100%) rename examples/{Filters => filters}/feebas.json (100%) rename examples/{Filters => filters}/ferroseed.json (100%) rename examples/{Filters => filters}/gible.json (100%) rename examples/{Filters => filters}/golett.json (100%) rename examples/{Filters => filters}/gyms.json (100%) rename examples/{Filters => filters}/heatmor.json (100%) rename examples/{Filters => filters}/invasions.json (100%) rename examples/{Filters => filters}/lake_trio.json (100%) rename examples/{Filters => filters}/lapras.json (100%) rename examples/{Filters => filters}/larvitar.json (100%) rename examples/{Filters => filters}/legendary_raids.json (100%) rename examples/{Filters => filters}/litwick.json (100%) rename examples/{Filters => filters}/lunatone.json (100%) rename examples/{Filters => filters}/lures.json (100%) rename examples/{Filters => filters}/magikarp.json (100%) rename examples/{Filters => filters}/mawile_raids.json (100%) rename examples/{Filters => filters}/pvp1500cp.json (100%) rename examples/{Filters => filters}/pvp1500cp_rank1.json (100%) rename examples/{Filters => filters}/pvp1500cp_rank5.json (100%) rename examples/{Filters => filters}/pvp2500cp.json (100%) rename examples/{Filters => filters}/pvp2500cp_rank1.json (100%) rename examples/{Filters => filters}/pvp2500cp_rank5.json (100%) rename examples/{Filters => filters}/quests.json (100%) rename examples/{Filters => filters}/quests_absol.json (100%) rename examples/{Filters => filters}/quests_aerodactyl.json (100%) rename examples/{Filters => filters}/quests_chansey.json (100%) rename examples/{Filters => filters}/quests_dratini.json (100%) rename examples/{Filters => filters}/quests_golden_pinap.json (100%) rename examples/{Filters => filters}/quests_lapras.json (100%) rename examples/{Filters => filters}/quests_larvitar.json (100%) rename examples/{Filters => filters}/quests_nincada.json (100%) rename examples/{Filters => filters}/quests_rare.json (100%) rename examples/{Filters => filters}/quests_seel.json (100%) rename examples/{Filters => filters}/quests_spinda.json (100%) rename examples/{Filters => filters}/raids.json (100%) rename examples/{Filters => filters}/ralts.json (100%) rename examples/{Filters => filters}/shieldon.json (100%) rename examples/{Filters => filters}/shinx_raids.json (100%) rename examples/{Filters => filters}/shiny_raids.json (100%) rename examples/{Filters => filters}/skorupi.json (100%) rename examples/{Filters => filters}/snorlax.json (100%) rename examples/{Filters => filters}/solrock.json (100%) rename examples/{Filters => filters}/unown.json (100%) rename examples/{Filters => filters}/wailmer.json (100%) rename examples/{Filters => filters}/weather.json (100%) rename examples/{Filters => filters}/xl_karp.json (100%) rename examples/{Filters => filters}/xs_rat.json (100%) rename examples/{Geofences => geofences}/Paris.txt (100%) rename examples/{Geofences => geofences}/ParisLondon.txt (100%) rename examples/{Templates => templates}/gyms.example.json (100%) rename examples/{Templates => templates}/invasions.example.json (100%) rename examples/{Templates => templates}/lures.example.json (100%) rename examples/{Templates => templates}/nests.example.json (100%) rename examples/{Templates => templates}/pokemon.example.json (100%) rename examples/{Templates => templates}/quests.example.json (100%) rename examples/{Templates => templates}/raids.example.json (100%) rename examples/{Templates => templates}/weather.example.json (100%) diff --git a/examples/Alerts/default.json b/examples/alerts/default.json similarity index 100% rename from examples/Alerts/default.json rename to examples/alerts/default.json diff --git a/examples/Filters/0iv.json b/examples/filters/0iv.json similarity index 100% rename from examples/Filters/0iv.json rename to examples/filters/0iv.json diff --git a/examples/Filters/100iv.json b/examples/filters/100iv.json similarity index 100% rename from examples/Filters/100iv.json rename to examples/filters/100iv.json diff --git a/examples/Filters/100iv_basura.json b/examples/filters/100iv_basura.json similarity index 100% rename from examples/Filters/100iv_basura.json rename to examples/filters/100iv_basura.json diff --git a/examples/Filters/100iv_lvl30.json b/examples/filters/100iv_lvl30.json similarity index 100% rename from examples/Filters/100iv_lvl30.json rename to examples/filters/100iv_lvl30.json diff --git a/examples/Filters/100iv_lvl35.json b/examples/filters/100iv_lvl35.json similarity index 100% rename from examples/Filters/100iv_lvl35.json rename to examples/filters/100iv_lvl35.json diff --git a/examples/Filters/100iv_rare.json b/examples/filters/100iv_rare.json similarity index 100% rename from examples/Filters/100iv_rare.json rename to examples/filters/100iv_rare.json diff --git a/examples/Filters/100iv_ultra.json b/examples/filters/100iv_ultra.json similarity index 100% rename from examples/Filters/100iv_ultra.json rename to examples/filters/100iv_ultra.json diff --git a/examples/Filters/3rd_evo.json b/examples/filters/3rd_evo.json similarity index 100% rename from examples/Filters/3rd_evo.json rename to examples/filters/3rd_evo.json diff --git a/examples/Filters/90iv.json b/examples/filters/90iv.json similarity index 100% rename from examples/Filters/90iv.json rename to examples/filters/90iv.json diff --git a/examples/Filters/90iv_cd.json b/examples/filters/90iv_cd.json similarity index 100% rename from examples/Filters/90iv_cd.json rename to examples/filters/90iv_cd.json diff --git a/examples/Filters/90iv_gible.json b/examples/filters/90iv_gible.json similarity index 100% rename from examples/Filters/90iv_gible.json rename to examples/filters/90iv_gible.json diff --git a/examples/Filters/90iv_lvl34.json b/examples/filters/90iv_lvl34.json similarity index 100% rename from examples/Filters/90iv_lvl34.json rename to examples/filters/90iv_lvl34.json diff --git a/examples/Filters/90iv_snorlax.json b/examples/filters/90iv_snorlax.json similarity index 100% rename from examples/Filters/90iv_snorlax.json rename to examples/filters/90iv_snorlax.json diff --git a/examples/Filters/96iv.json b/examples/filters/96iv.json similarity index 100% rename from examples/Filters/96iv.json rename to examples/filters/96iv.json diff --git a/examples/Filters/98iv.json b/examples/filters/98iv.json similarity index 100% rename from examples/Filters/98iv.json rename to examples/filters/98iv.json diff --git a/examples/Filters/98iv_cd.json b/examples/filters/98iv_cd.json similarity index 100% rename from examples/Filters/98iv_cd.json rename to examples/filters/98iv_cd.json diff --git a/examples/Filters/all.json b/examples/filters/all.json similarity index 100% rename from examples/Filters/all.json rename to examples/filters/all.json diff --git a/examples/Filters/axew.json b/examples/filters/axew.json similarity index 100% rename from examples/Filters/axew.json rename to examples/filters/axew.json diff --git a/examples/Filters/bagon.json b/examples/filters/bagon.json similarity index 100% rename from examples/Filters/bagon.json rename to examples/filters/bagon.json diff --git a/examples/Filters/beldum.json b/examples/filters/beldum.json similarity index 100% rename from examples/Filters/beldum.json rename to examples/filters/beldum.json diff --git a/examples/Filters/bronzor.json b/examples/filters/bronzor.json similarity index 100% rename from examples/Filters/bronzor.json rename to examples/filters/bronzor.json diff --git a/examples/Filters/chansey.json b/examples/filters/chansey.json similarity index 100% rename from examples/Filters/chansey.json rename to examples/filters/chansey.json diff --git a/examples/Filters/clamperl.json b/examples/filters/clamperl.json similarity index 100% rename from examples/Filters/clamperl.json rename to examples/filters/clamperl.json diff --git a/examples/Filters/cranidos.json b/examples/filters/cranidos.json similarity index 100% rename from examples/Filters/cranidos.json rename to examples/filters/cranidos.json diff --git a/examples/Filters/darumaka.json b/examples/filters/darumaka.json similarity index 100% rename from examples/Filters/darumaka.json rename to examples/filters/darumaka.json diff --git a/examples/Filters/default.json b/examples/filters/default.json similarity index 100% rename from examples/Filters/default.json rename to examples/filters/default.json diff --git a/examples/Filters/deino.json b/examples/filters/deino.json similarity index 100% rename from examples/Filters/deino.json rename to examples/filters/deino.json diff --git a/examples/Filters/ditto.json b/examples/filters/ditto.json similarity index 100% rename from examples/Filters/ditto.json rename to examples/filters/ditto.json diff --git a/examples/Filters/dratini.json b/examples/filters/dratini.json similarity index 100% rename from examples/Filters/dratini.json rename to examples/filters/dratini.json diff --git a/examples/Filters/drilbur.json b/examples/filters/drilbur.json similarity index 100% rename from examples/Filters/drilbur.json rename to examples/filters/drilbur.json diff --git a/examples/Filters/durant.json b/examples/filters/durant.json similarity index 100% rename from examples/Filters/durant.json rename to examples/filters/durant.json diff --git a/examples/Filters/dwebble.json b/examples/filters/dwebble.json similarity index 100% rename from examples/Filters/dwebble.json rename to examples/filters/dwebble.json diff --git a/examples/Filters/ex_raids.json b/examples/filters/ex_raids.json similarity index 100% rename from examples/Filters/ex_raids.json rename to examples/filters/ex_raids.json diff --git a/examples/Filters/feebas.json b/examples/filters/feebas.json similarity index 100% rename from examples/Filters/feebas.json rename to examples/filters/feebas.json diff --git a/examples/Filters/ferroseed.json b/examples/filters/ferroseed.json similarity index 100% rename from examples/Filters/ferroseed.json rename to examples/filters/ferroseed.json diff --git a/examples/Filters/gible.json b/examples/filters/gible.json similarity index 100% rename from examples/Filters/gible.json rename to examples/filters/gible.json diff --git a/examples/Filters/golett.json b/examples/filters/golett.json similarity index 100% rename from examples/Filters/golett.json rename to examples/filters/golett.json diff --git a/examples/Filters/gyms.json b/examples/filters/gyms.json similarity index 100% rename from examples/Filters/gyms.json rename to examples/filters/gyms.json diff --git a/examples/Filters/heatmor.json b/examples/filters/heatmor.json similarity index 100% rename from examples/Filters/heatmor.json rename to examples/filters/heatmor.json diff --git a/examples/Filters/invasions.json b/examples/filters/invasions.json similarity index 100% rename from examples/Filters/invasions.json rename to examples/filters/invasions.json diff --git a/examples/Filters/lake_trio.json b/examples/filters/lake_trio.json similarity index 100% rename from examples/Filters/lake_trio.json rename to examples/filters/lake_trio.json diff --git a/examples/Filters/lapras.json b/examples/filters/lapras.json similarity index 100% rename from examples/Filters/lapras.json rename to examples/filters/lapras.json diff --git a/examples/Filters/larvitar.json b/examples/filters/larvitar.json similarity index 100% rename from examples/Filters/larvitar.json rename to examples/filters/larvitar.json diff --git a/examples/Filters/legendary_raids.json b/examples/filters/legendary_raids.json similarity index 100% rename from examples/Filters/legendary_raids.json rename to examples/filters/legendary_raids.json diff --git a/examples/Filters/litwick.json b/examples/filters/litwick.json similarity index 100% rename from examples/Filters/litwick.json rename to examples/filters/litwick.json diff --git a/examples/Filters/lunatone.json b/examples/filters/lunatone.json similarity index 100% rename from examples/Filters/lunatone.json rename to examples/filters/lunatone.json diff --git a/examples/Filters/lures.json b/examples/filters/lures.json similarity index 100% rename from examples/Filters/lures.json rename to examples/filters/lures.json diff --git a/examples/Filters/magikarp.json b/examples/filters/magikarp.json similarity index 100% rename from examples/Filters/magikarp.json rename to examples/filters/magikarp.json diff --git a/examples/Filters/mawile_raids.json b/examples/filters/mawile_raids.json similarity index 100% rename from examples/Filters/mawile_raids.json rename to examples/filters/mawile_raids.json diff --git a/examples/Filters/pvp1500cp.json b/examples/filters/pvp1500cp.json similarity index 100% rename from examples/Filters/pvp1500cp.json rename to examples/filters/pvp1500cp.json diff --git a/examples/Filters/pvp1500cp_rank1.json b/examples/filters/pvp1500cp_rank1.json similarity index 100% rename from examples/Filters/pvp1500cp_rank1.json rename to examples/filters/pvp1500cp_rank1.json diff --git a/examples/Filters/pvp1500cp_rank5.json b/examples/filters/pvp1500cp_rank5.json similarity index 100% rename from examples/Filters/pvp1500cp_rank5.json rename to examples/filters/pvp1500cp_rank5.json diff --git a/examples/Filters/pvp2500cp.json b/examples/filters/pvp2500cp.json similarity index 100% rename from examples/Filters/pvp2500cp.json rename to examples/filters/pvp2500cp.json diff --git a/examples/Filters/pvp2500cp_rank1.json b/examples/filters/pvp2500cp_rank1.json similarity index 100% rename from examples/Filters/pvp2500cp_rank1.json rename to examples/filters/pvp2500cp_rank1.json diff --git a/examples/Filters/pvp2500cp_rank5.json b/examples/filters/pvp2500cp_rank5.json similarity index 100% rename from examples/Filters/pvp2500cp_rank5.json rename to examples/filters/pvp2500cp_rank5.json diff --git a/examples/Filters/quests.json b/examples/filters/quests.json similarity index 100% rename from examples/Filters/quests.json rename to examples/filters/quests.json diff --git a/examples/Filters/quests_absol.json b/examples/filters/quests_absol.json similarity index 100% rename from examples/Filters/quests_absol.json rename to examples/filters/quests_absol.json diff --git a/examples/Filters/quests_aerodactyl.json b/examples/filters/quests_aerodactyl.json similarity index 100% rename from examples/Filters/quests_aerodactyl.json rename to examples/filters/quests_aerodactyl.json diff --git a/examples/Filters/quests_chansey.json b/examples/filters/quests_chansey.json similarity index 100% rename from examples/Filters/quests_chansey.json rename to examples/filters/quests_chansey.json diff --git a/examples/Filters/quests_dratini.json b/examples/filters/quests_dratini.json similarity index 100% rename from examples/Filters/quests_dratini.json rename to examples/filters/quests_dratini.json diff --git a/examples/Filters/quests_golden_pinap.json b/examples/filters/quests_golden_pinap.json similarity index 100% rename from examples/Filters/quests_golden_pinap.json rename to examples/filters/quests_golden_pinap.json diff --git a/examples/Filters/quests_lapras.json b/examples/filters/quests_lapras.json similarity index 100% rename from examples/Filters/quests_lapras.json rename to examples/filters/quests_lapras.json diff --git a/examples/Filters/quests_larvitar.json b/examples/filters/quests_larvitar.json similarity index 100% rename from examples/Filters/quests_larvitar.json rename to examples/filters/quests_larvitar.json diff --git a/examples/Filters/quests_nincada.json b/examples/filters/quests_nincada.json similarity index 100% rename from examples/Filters/quests_nincada.json rename to examples/filters/quests_nincada.json diff --git a/examples/Filters/quests_rare.json b/examples/filters/quests_rare.json similarity index 100% rename from examples/Filters/quests_rare.json rename to examples/filters/quests_rare.json diff --git a/examples/Filters/quests_seel.json b/examples/filters/quests_seel.json similarity index 100% rename from examples/Filters/quests_seel.json rename to examples/filters/quests_seel.json diff --git a/examples/Filters/quests_spinda.json b/examples/filters/quests_spinda.json similarity index 100% rename from examples/Filters/quests_spinda.json rename to examples/filters/quests_spinda.json diff --git a/examples/Filters/raids.json b/examples/filters/raids.json similarity index 100% rename from examples/Filters/raids.json rename to examples/filters/raids.json diff --git a/examples/Filters/ralts.json b/examples/filters/ralts.json similarity index 100% rename from examples/Filters/ralts.json rename to examples/filters/ralts.json diff --git a/examples/Filters/shieldon.json b/examples/filters/shieldon.json similarity index 100% rename from examples/Filters/shieldon.json rename to examples/filters/shieldon.json diff --git a/examples/Filters/shinx_raids.json b/examples/filters/shinx_raids.json similarity index 100% rename from examples/Filters/shinx_raids.json rename to examples/filters/shinx_raids.json diff --git a/examples/Filters/shiny_raids.json b/examples/filters/shiny_raids.json similarity index 100% rename from examples/Filters/shiny_raids.json rename to examples/filters/shiny_raids.json diff --git a/examples/Filters/skorupi.json b/examples/filters/skorupi.json similarity index 100% rename from examples/Filters/skorupi.json rename to examples/filters/skorupi.json diff --git a/examples/Filters/snorlax.json b/examples/filters/snorlax.json similarity index 100% rename from examples/Filters/snorlax.json rename to examples/filters/snorlax.json diff --git a/examples/Filters/solrock.json b/examples/filters/solrock.json similarity index 100% rename from examples/Filters/solrock.json rename to examples/filters/solrock.json diff --git a/examples/Filters/unown.json b/examples/filters/unown.json similarity index 100% rename from examples/Filters/unown.json rename to examples/filters/unown.json diff --git a/examples/Filters/wailmer.json b/examples/filters/wailmer.json similarity index 100% rename from examples/Filters/wailmer.json rename to examples/filters/wailmer.json diff --git a/examples/Filters/weather.json b/examples/filters/weather.json similarity index 100% rename from examples/Filters/weather.json rename to examples/filters/weather.json diff --git a/examples/Filters/xl_karp.json b/examples/filters/xl_karp.json similarity index 100% rename from examples/Filters/xl_karp.json rename to examples/filters/xl_karp.json diff --git a/examples/Filters/xs_rat.json b/examples/filters/xs_rat.json similarity index 100% rename from examples/Filters/xs_rat.json rename to examples/filters/xs_rat.json diff --git a/examples/Geofences/Paris.txt b/examples/geofences/Paris.txt similarity index 100% rename from examples/Geofences/Paris.txt rename to examples/geofences/Paris.txt diff --git a/examples/Geofences/ParisLondon.txt b/examples/geofences/ParisLondon.txt similarity index 100% rename from examples/Geofences/ParisLondon.txt rename to examples/geofences/ParisLondon.txt diff --git a/examples/Templates/gyms.example.json b/examples/templates/gyms.example.json similarity index 100% rename from examples/Templates/gyms.example.json rename to examples/templates/gyms.example.json diff --git a/examples/Templates/invasions.example.json b/examples/templates/invasions.example.json similarity index 100% rename from examples/Templates/invasions.example.json rename to examples/templates/invasions.example.json diff --git a/examples/Templates/lures.example.json b/examples/templates/lures.example.json similarity index 100% rename from examples/Templates/lures.example.json rename to examples/templates/lures.example.json diff --git a/examples/Templates/nests.example.json b/examples/templates/nests.example.json similarity index 100% rename from examples/Templates/nests.example.json rename to examples/templates/nests.example.json diff --git a/examples/Templates/pokemon.example.json b/examples/templates/pokemon.example.json similarity index 100% rename from examples/Templates/pokemon.example.json rename to examples/templates/pokemon.example.json diff --git a/examples/Templates/quests.example.json b/examples/templates/quests.example.json similarity index 100% rename from examples/Templates/quests.example.json rename to examples/templates/quests.example.json diff --git a/examples/Templates/raids.example.json b/examples/templates/raids.example.json similarity index 100% rename from examples/Templates/raids.example.json rename to examples/templates/raids.example.json diff --git a/examples/Templates/weather.example.json b/examples/templates/weather.example.json similarity index 100% rename from examples/Templates/weather.example.json rename to examples/templates/weather.example.json From 840e519a4dc62dbb003a01c44775ed59eece98af Mon Sep 17 00:00:00 2001 From: versx Date: Tue, 7 Jul 2020 16:01:11 -0700 Subject: [PATCH 12/19] - Get gym cache list upon startup. - Fix gym alarms --- src/Bot.cs | 25 ++++---- src/Net/Models/GymDetailsData.cs | 85 +++++++++++++++++++++++---- src/Net/Webhooks/WebhookController.cs | 48 +++++++++++---- 3 files changed, 122 insertions(+), 36 deletions(-) diff --git a/src/Bot.cs b/src/Bot.cs index f7038ce2..f4b85a72 100644 --- a/src/Bot.cs +++ b/src/Bot.cs @@ -33,6 +33,11 @@ // TODO: Manage subscriptions via DM again // TODO: Multiple discord bot tokens per server // TODO: Add map url to config and DTS options + // TODO: Add scanmap_url to DTS + // TODO: Move mentions string from alarms.json to alerts.json for alarm type as 'Description' property + // TODO: Google address option + // TODO: Cache gyms upon startup + // TODO: Only start database migrator if subscriptions are enabled public class Bot { @@ -42,7 +47,6 @@ public class Bot private readonly WebhookController _whm; private WhConfig _whConfig; private readonly SubscriptionProcessor _subProcessor; - private readonly Dictionary _gyms; private static readonly IEventLogger _logger = EventLogger.GetLogger("BOT"); @@ -59,7 +63,6 @@ public Bot(WhConfig whConfig) _logger.Trace($"WhConfig [Servers={whConfig.Servers.Count}, Port={whConfig.WebhookPort}]"); _servers = new Dictionary(); _whConfig = whConfig; - _gyms = new Dictionary(); _whm = new WebhookController(_whConfig); // Set translation language @@ -672,18 +675,13 @@ private void OnGymDetailsAlarmTriggered(object sender, AlarmEventTriggeredEventA try { - if (!_gyms.ContainsKey(gymDetails.GymId)) - { - _gyms.Add(gymDetails.GymId, gymDetails); - } - - var oldGym = _gyms[gymDetails.GymId]; - var changed = oldGym.Team != gymDetails.Team;// || /*oldGym.InBattle != gymDetails.InBattle ||*/ gymDetails.InBattle; + var oldGym = _whm.Gyms[gymDetails.GymId]; + var changed = oldGym.Team != gymDetails.Team || gymDetails.InBattle || oldGym.SlotsAvailable != gymDetails.SlotsAvailable; if (!changed) return; var client = _servers[e.GuildId]; - var eb = gymDetails.GenerateGymMessage(e.GuildId, client, _whConfig, e.Alarm, oldGym, loc?.Name ?? e.Alarm.Name); + var eb = gymDetails.GenerateGymMessage(e.GuildId, client, _whConfig, e.Alarm, _whm.Gyms[gymDetails.GymId], loc?.Name ?? e.Alarm.Name); var name = gymDetails.GymName; var jsonEmbed = new DiscordWebhookMessage { @@ -693,7 +691,9 @@ private void OnGymDetailsAlarmTriggered(object sender, AlarmEventTriggeredEventA }.Build(); NetUtil.SendWebhook(e.Alarm.Webhook, jsonEmbed); Statistics.Instance.GymAlarmsSent++; - _gyms[gymDetails.GymId] = gymDetails; + + // Gym team changed, set gym in gym cache + _whm.SetGym(gymDetails.GymId, gymDetails); Statistics.Instance.GymAlarmsSent++; } @@ -736,6 +736,9 @@ private void OnWeatherAlarmTriggered(object sender, AlarmEventTriggeredEventArgs }.Build(); NetUtil.SendWebhook(e.Alarm.Webhook, jsonEmbed); + // Weather changed, set weather in weather cache + _whm.SetWeather(weather.Id, weather.GameplayCondition); + Statistics.Instance.WeatherAlarmsSent++; } catch (Exception ex) diff --git a/src/Net/Models/GymDetailsData.cs b/src/Net/Models/GymDetailsData.cs index 63ee4d46..558d1632 100644 --- a/src/Net/Models/GymDetailsData.cs +++ b/src/Net/Models/GymDetailsData.cs @@ -3,52 +3,85 @@ using System; using System.Collections.Generic; using System.IO; - + using System.Linq; using DSharpPlus; using DSharpPlus.Entities; using Newtonsoft.Json; + using ServiceStack.DataAnnotations; + using ServiceStack.OrmLite; using WhMgr.Alarms.Alerts; using WhMgr.Alarms.Models; using WhMgr.Configuration; using WhMgr.Data; + using WhMgr.Diagnostics; using WhMgr.Utilities; /// /// RealDeviceMap Gym Details webhook model class. /// + [Alias("gym")] public sealed class GymDetailsData { + private static readonly IEventLogger _logger = EventLogger.GetLogger("GYMDETAILSDATA"); + public const string WebhookHeader = "gym_details"; #region Properties - [JsonProperty("id")] + [ + JsonProperty("id"), + Alias("id") + ] public string GymId { get; set; } - [JsonProperty("name")] + [ + JsonProperty("name"), + Alias("name") + ] public string GymName { get; set; } = "Unknown"; - [JsonProperty("url")] + [ + JsonProperty("url"), + Alias("name") + ] public string Url { get; set; } - [JsonProperty("latitude")] + [ + JsonProperty("latitude"), + Alias("lat") + ] public double Latitude { get; set; } - [JsonProperty("longitude")] + [ + JsonProperty("longitude"), + Alias("lon") + ] public double Longitude { get; set; } - [JsonProperty("team")] + [ + JsonProperty("team"), + Alias("team_id") + ] public PokemonTeam Team { get; set; } = PokemonTeam.Neutral; - [JsonProperty("slots_available")] + [ + JsonProperty("slots_available"), + Alias("availble_slots") // TODO: Typflo + ] public ushort SlotsAvailable { get; set; } - [JsonProperty("sponsor_id")] + [ + JsonProperty("sponsor_id"), + Alias("sponsor_id") + ] public bool SponsorId { get; set; } - [JsonProperty("in_battle")] + [ + JsonProperty("in_battle"), + Alias("in_battle") + ] public bool InBattle { get; set; } #endregion @@ -90,8 +123,8 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var exEmoji = exEmojiId > 0 ? string.Format(Strings.EmojiSchema, "ex", exEmojiId): "EX"; var teamEmojiId = MasterFile.Instance.Emojis[Team.ToString().ToLower()]; var teamEmoji = teamEmojiId > 0 ? string.Format(Strings.EmojiSchema, Team.ToString().ToLower(), teamEmojiId) : Team.ToString(); - var oldTeamEmojiId = MasterFile.Instance.Emojis[oldGym.Team.ToString().ToLower()]; - var oldTeamEmoji = oldTeamEmojiId > 0 ? string.Format(Strings.EmojiSchema, oldGym.Team.ToString().ToLower(), oldTeamEmojiId) : oldGym.Team.ToString(); + var oldTeamEmojiId = MasterFile.Instance.Emojis[oldGym?.Team.ToString().ToLower()]; + var oldTeamEmoji = oldTeamEmojiId > 0 ? string.Format(Strings.EmojiSchema, oldGym?.Team.ToString().ToLower(), oldTeamEmojiId) : oldGym?.Team.ToString(); var gmapsLink = string.Format(Strings.GoogleMaps, Latitude, Longitude); var appleMapsLink = string.Format(Strings.AppleMaps, Latitude, Longitude); @@ -122,7 +155,11 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh { "under_attack", Convert.ToString(InBattle) }, { "is_ex", Convert.ToString(SponsorId) }, { "ex_emoji", exEmoji }, - { "slots_available", SlotsAvailable.ToString("N0") }, + { "slots_available", SlotsAvailable == 0 + ? "Full" + : SlotsAvailable == 6 + ? "Empty" + : SlotsAvailable.ToString("N0") }, //Location properties { "geofence", city ?? defaultMissingValue }, @@ -148,5 +185,27 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh }; return dict; } + + internal static Dictionary GetGyms(string connectionString = "") + { + if (string.IsNullOrEmpty(connectionString)) + return null; + + try + { + using (var db = DataAccessLayer.CreateFactory(connectionString).Open()) + { + var gyms = db.LoadSelect(); + var dict = gyms?.ToDictionary(x => x.GymId, x => x); + return dict; + } + } + catch (Exception ex) + { + _logger.Error(ex); + } + + return null; + } } } \ No newline at end of file diff --git a/src/Net/Webhooks/WebhookController.cs b/src/Net/Webhooks/WebhookController.cs index 63f8ea1f..87414774 100644 --- a/src/Net/Webhooks/WebhookController.cs +++ b/src/Net/Webhooks/WebhookController.cs @@ -31,8 +31,8 @@ public class WebhookController private readonly Dictionary _alarms; private readonly IReadOnlyDictionary _servers; private readonly WhConfig _config; - private readonly Dictionary _gyms; private readonly Dictionary _weather; + private Dictionary _gyms; #endregion @@ -46,7 +46,17 @@ public class WebhookController /// /// Gyms cache /// - public IReadOnlyDictionary Gyms => _gyms; + public IReadOnlyDictionary Gyms + { + get + { + if (_gyms == null) + { + _gyms = GymDetailsData.GetGyms(Data.DataAccessLayer.ScannerConnectionString); + } + return _gyms; + } + } /// /// Weather cells cache @@ -800,16 +810,6 @@ private void ProcessGymDetails(GymDetailsData gymDetails) continue; } - if (!_gyms.ContainsKey(gymDetails.GymId)) - { - _gyms.Add(gymDetails.GymId, gymDetails); - } - - var oldGym = _gyms[gymDetails.GymId]; - var changed = oldGym.Team != gymDetails.Team;// || /*oldGym.InBattle != gymDetails.InBattle ||*/ gymDetails.InBattle; - if (!changed) - return; - if ((alarm.Filters?.Gyms?.UnderAttack ?? false) && !gymDetails.InBattle) { //_logger.Info($"[{alarm.Name}] Skipping gym details GymId={gymDetails.GymId}, GymName{gymDetails.GymName}, not under attack."); @@ -822,6 +822,20 @@ private void ProcessGymDetails(GymDetailsData gymDetails) continue; } + if (!_gyms.ContainsKey(gymDetails.GymId)) + { + _gyms.Add(gymDetails.GymId, gymDetails); + //OnGymDetailsAlarmTriggered(gymDetails, alarm, guildId); + //continue; + } + + /* + var oldGym = _gyms[gymDetails.GymId]; + var changed = oldGym.Team != gymDetails.Team || gymDetails.InBattle; + if (!changed) + return; + */ + OnGymDetailsAlarmTriggered(gymDetails, alarm, guildId); } } @@ -891,6 +905,16 @@ private void ProcessWeather(WeatherData weather) #endregion + public void SetGym(string id, GymDetailsData gymDetails) + { + _gyms[id] = gymDetails; + } + + public void SetWeather(long id, WeatherType type) + { + _weather[id] = type; + } + #region Geofence Utilities /// From d6c0cb5fbdb3443e0817ba1befb67dc5e18b2a95 Mon Sep 17 00:00:00 2001 From: versx Date: Tue, 7 Jul 2020 17:33:58 -0700 Subject: [PATCH 13/19] Add scanner map link to embeds, config and DTS as `scanmaps_url`. --- config.example.json | 3 ++- examples/alerts/default.json | 20 ++++++++++---------- examples/templates/gyms.example.json | 10 +--------- src/Alarms/Alerts/AlertMessage.cs | 20 ++++++++++---------- src/Configuration/UrlConfig.cs | 6 ++++++ src/Net/Models/GymDetailsData.cs | 7 ++++--- src/Net/Models/PokemonData.cs | 3 +++ src/Net/Models/PokestopData.cs | 3 +++ src/Net/Models/QuestData.cs | 3 +++ src/Net/Models/RaidData.cs | 3 +++ src/Net/Models/WeatherData.cs | 3 +++ 11 files changed, 48 insertions(+), 33 deletions(-) diff --git a/config.example.json b/config.example.json index ff217511..810a6bd7 100644 --- a/config.example.json +++ b/config.example.json @@ -107,7 +107,8 @@ 320 ], "urls": { - "staticMap": "http://tiles.example.com:8080/static/klokantech-basic/{0}/{1}/15/300/175/1/png" + "staticMap": "http://tiles.example.com:8080/static/klokantech-basic/{0}/{1}/15/300/175/1/png", + "scannerMap": "http://map.example.com/@/{0}/{1}/15" }, "iconStyles": { "Default": "https://raw.githubusercontent.com/versx/WhMgr-Assets/master/original/", diff --git a/examples/alerts/default.json b/examples/alerts/default.json index 139326d4..11a5d8c1 100644 --- a/examples/alerts/default.json +++ b/examples/alerts/default.json @@ -1,7 +1,7 @@ { "pokemon": { "avatarUrl": "", - "content": "
(//) L
**Despawn:** ( left)
**Details:** CP: IV: LV:
**Types:** | **Size:** <#has_weather> | <#is_weather_boosted> (Boosted)
**Moveset:**
<#near_pokestop>**Near Pokestop:** []()
<#is_ditto>**Catch Pokemon:**
<#has_capture_rates> % % %
<#is_pvp>
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + "content": " (//) L
**Despawn:** ( left)
**Details:** CP: IV: LV:
**Types:** | **Size:** <#has_weather> | <#is_weather_boosted> (Boosted)
**Moveset:**
<#near_pokestop>**Near Pokestop:** []()
<#is_ditto>**Catch Pokemon:**
<#has_capture_rates> % % %
<#is_pvp>
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": "", "url": "", @@ -14,7 +14,7 @@ }, "pokemonMissingStats": { "avatarUrl": "", - "content": "
**Despawn:** ( left)
**Types:**
<#near_pokestop>**Near Pokestop:** []()
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + "content": "
**Despawn:** ( left)
**Types:**
<#near_pokestop>**Near Pokestop:** []()
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": "", "url": "", @@ -27,7 +27,7 @@ }, "gyms": { "avatarUrl": "", - "content": "<#team_changed>Gym changed from to
<#in_battle>Gym is under attack!
**Slots Available:**
<#is_ex> Gym!**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + "content": "<#team_changed>Gym changed from to
<#in_battle>Gym is under attack!
**Slots Available:**
<#is_ex> Gym!**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", "url": "", @@ -40,7 +40,7 @@ }, "raids": { "avatarUrl": "", - "content": " Raid Ends: ( left)
**Perfect CP:** / :white_sun_rain_cloud:
**Worst CP:** / :white_sun_rain_cloud:
**Types:** | **Level:** | **Team:**
**Moveset:**
**Weaknesses:**
<#is_ex> Gym!
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + "content": " Raid Ends: ( left)
**Perfect CP:** / :white_sun_rain_cloud:
**Worst CP:** / :white_sun_rain_cloud:
**Types:** | **Level:** | **Team:**
**Moveset:**
**Weaknesses:**
<#is_ex> Gym!
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", "url": "", @@ -53,7 +53,7 @@ }, "eggs": { "avatarUrl": "", - "content": "Hatches: ()
**Ends:** ( left)
**Team:**
<#is_ex> Gym!
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + "content": "Hatches: ()
**Ends:** ( left)
**Team:**
<#is_ex> Gym!
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", "url": "", @@ -66,7 +66,7 @@ }, "pokestops": { "avatarUrl": "", - "content": "<#has_lure>**Lure Expires** ( left)
**Lure Type:**
<#has_invasion>**Expires:** ( left)
**Type:** | **Gender:**

**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + "content": "<#has_lure>**Lure Expires** ( left)
**Lure Type:**
<#has_invasion>**Expires:** ( left)
**Type:** | **Gender:**

**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", "url": "", @@ -79,7 +79,7 @@ }, "quests": { "avatarUrl": "", - "content": "**Quest:**
<#has_quest_conditions>**Condition(s):**
**Reward:**
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + "content": "**Quest:**
<#has_quest_conditions>**Condition(s):**
**Reward:**
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", "url": "", @@ -92,7 +92,7 @@ }, "lures": { "avatarUrl": "", - "content": "<#has_lure>**Lure Expires:** ( left)
**Lure Type:**
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + "content": "<#has_lure>**Lure Expires:** ( left)
**Lure Type:**
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", "url": "", @@ -105,7 +105,7 @@ }, "invasions": { "avatarUrl": "", - "content": "<#has_invasion>**Expires:** ( left)
**Type:** | **Gender:**

**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + "content": "<#has_invasion>**Expires:** ( left)
**Type:** | **Gender:**

**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", "url": "", @@ -118,7 +118,7 @@ }, "nests": { "avatarUrl": "", - "content": "**Pokemon:**
**Average Spawns:** /h | **Types:**
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + "content": "**Pokemon:**
**Average Spawns:** /h | **Types:**
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", "url": "", diff --git a/examples/templates/gyms.example.json b/examples/templates/gyms.example.json index 68ad87a2..b2435e0a 100644 --- a/examples/templates/gyms.example.json +++ b/examples/templates/gyms.example.json @@ -8,13 +8,5 @@ "y_offset": 0, "latitude": "{{lat}}", "longitude": "{{lon}}" - },{ - "url": "{{marker}}", - "height": "32", - "width": "32", - "x_offset": 0, - "y_offset": 0, - "latitude": "{{lat}}", - "longitude": "{{lon}}" - }] + }] } \ No newline at end of file diff --git a/src/Alarms/Alerts/AlertMessage.cs b/src/Alarms/Alerts/AlertMessage.cs index 558dda93..78a756ec 100644 --- a/src/Alarms/Alerts/AlertMessage.cs +++ b/src/Alarms/Alerts/AlertMessage.cs @@ -11,7 +11,7 @@ public class AlertMessage : Dictionary AlertMessageType.Pokemon, new AlertMessageSettings { AvatarUrl = "", - Content = " (//) L
**Despawn:** ( left)
**Details:** CP: IV: LV:
**Types:** | **Size:** <#has_weather> | <#is_weather_boosted> (Boosted)
**Moveset:**
<#near_pokestop>**Near Pokestop:** []()
<#is_ditto>**Catch Pokemon:**
<#has_capture_rates> % % %
<#is_pvp>
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + Content = " (//) L
**Despawn:** ( left)
**Details:** CP: IV: LV:
**Types:** | **Size:** <#has_weather> | <#is_weather_boosted> (Boosted)
**Moveset:**
<#near_pokestop>**Near Pokestop:** []()
<#is_ditto>**Catch Pokemon:**
<#has_capture_rates> % % %
<#is_pvp>
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", IconUrl = "", Title = "", Url = "", @@ -28,7 +28,7 @@ public class AlertMessage : Dictionary AlertMessageType.PokemonMissingStats, new AlertMessageSettings { AvatarUrl = "", - Content = "
**Despawn:** ( left)
**Types:**
<#near_pokestop>**Near Pokestop:** []()
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + Content = "
**Despawn:** ( left)
**Types:**
<#near_pokestop>**Near Pokestop:** []()
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", IconUrl = "", Title = "", Url = "", @@ -45,7 +45,7 @@ public class AlertMessage : Dictionary AlertMessageType.Gyms, new AlertMessageSettings { AvatarUrl = "", - Content = "<#team_changed>Gym changed from to
<#in_battle>Gym is under attack!
**Slots Available:**
<#is_ex> Gym!**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + Content = "<#team_changed>Gym changed from to
<#in_battle>Gym is under attack!
**Slots Available:**
<#is_ex> Gym!**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", IconUrl = "", Title = ": ", Url = "", @@ -62,7 +62,7 @@ public class AlertMessage : Dictionary AlertMessageType.Raids, new AlertMessageSettings { AvatarUrl = "", - Content = " Raid Ends: ( left)
**Perfect CP:** / :white_sun_rain_cloud:
**Worst CP:** / :white_sun_rain_cloud:
**Types:** | **Level:** | **Team:**
**Moveset:**
**Weaknesses:**
<#is_ex> Gym!
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + Content = " Raid Ends: ( left)
**Perfect CP:** / :white_sun_rain_cloud:
**Worst CP:** / :white_sun_rain_cloud:
**Types:** | **Level:** | **Team:**
**Moveset:**
**Weaknesses:**
<#is_ex> Gym!
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", IconUrl = "", Title = ": ", Url = "", @@ -79,7 +79,7 @@ public class AlertMessage : Dictionary AlertMessageType.Eggs, new AlertMessageSettings { AvatarUrl = "", - Content = "Hatches: ()
**Ends:** ( left)
**Team:**
<#is_ex> Gym!
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + Content = "Hatches: ()
**Ends:** ( left)
**Team:**
<#is_ex> Gym!
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", IconUrl = "", Title = ": ", Url = "", @@ -96,7 +96,7 @@ public class AlertMessage : Dictionary AlertMessageType.Pokestops, new AlertMessageSettings { AvatarUrl = "", - Content = "<#has_lure>**Lure Expires** ( left)
**Lure Type:**
<#has_invasion>**Expires:** ( left)
**Type:** | **Gender:**

**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + Content = "<#has_lure>**Lure Expires** ( left)
**Lure Type:**
<#has_invasion>**Expires:** ( left)
**Type:** | **Gender:**

**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", IconUrl = "", Title = ": ", Url = "", @@ -113,7 +113,7 @@ public class AlertMessage : Dictionary AlertMessageType.Quests, new AlertMessageSettings { AvatarUrl = "", - Content = "**Quest:**
<#has_quest_conditions>**Condition(s):**
**Reward:**
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + Content = "**Quest:**
<#has_quest_conditions>**Condition(s):**
**Reward:**
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", IconUrl = "", Title = ": ", Url = "", @@ -130,7 +130,7 @@ public class AlertMessage : Dictionary AlertMessageType.Invasions, new AlertMessageSettings { AvatarUrl = "", - Content = "<#has_invasion>**Expires:** ( left)
**Type:** | **Gender:**

**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + Content = "<#has_invasion>**Expires:** ( left)
**Type:** | **Gender:**

**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", IconUrl = "", Title = ": ", Url = "", @@ -147,7 +147,7 @@ public class AlertMessage : Dictionary AlertMessageType.Lures, new AlertMessageSettings { AvatarUrl = "", - Content = "<#has_lure>**Lure Expires:** ( left)
**Lure Type:**
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + Content = "<#has_lure>**Lure Expires:** ( left)
**Lure Type:**
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", IconUrl = "", Title = ": ", Url = "", @@ -164,7 +164,7 @@ public class AlertMessage : Dictionary AlertMessageType.Nests, new AlertMessageSettings { AvatarUrl = "", - Content = "**Pokemon:**
**Average Spawns:** /h | **Types:**
**[[Google Maps]()] [[Apple Maps]()] [[Waze Maps]()]**", + Content = "**Pokemon:**
**Average Spawns:** /h | **Types:**
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", IconUrl = "", Title = ": ", Url = "", diff --git a/src/Configuration/UrlConfig.cs b/src/Configuration/UrlConfig.cs index 2e3ea247..4b9d5734 100644 --- a/src/Configuration/UrlConfig.cs +++ b/src/Configuration/UrlConfig.cs @@ -12,5 +12,11 @@ public class UrlConfig ///
[JsonProperty("staticMap")] public string StaticMap { get; set; } + + /// + /// Gets or sets the scanner map url + /// + [JsonProperty("scannerMap")] + public string ScannerMap { get; set; } } } \ No newline at end of file diff --git a/src/Net/Models/GymDetailsData.cs b/src/Net/Models/GymDetailsData.cs index 558d1632..4a64e48b 100644 --- a/src/Net/Models/GymDetailsData.cs +++ b/src/Net/Models/GymDetailsData.cs @@ -129,14 +129,14 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var gmapsLink = string.Format(Strings.GoogleMaps, Latitude, Longitude); var appleMapsLink = string.Format(Strings.AppleMaps, Latitude, Longitude); var wazeMapsLink = string.Format(Strings.WazeMaps, Latitude, Longitude); - // TODO: Use team icon for gym - var gymImage = "https://static.thenounproject.com/png/727778-200.png"; + var scannerMapsLink = string.Format(whConfig.Urls.ScannerMap, Latitude, Longitude); var templatePath = Path.Combine(whConfig.StaticMaps.TemplatesFolder, whConfig.StaticMaps.GymsTemplateFile); - var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap.Replace("/15/", "/11/"), Latitude, Longitude, gymImage, Team); + var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap.Replace("/15/", "/11/"), Latitude, Longitude, /*TODO: Add team image*/string.Empty, Team); //var staticMapLink = string.Format(whConfig.Urls.StaticMap, Latitude, Longitude);//whConfig.Urls.StaticMap.Gyms.Enabled ? string.Format(whConfig.Urls.StaticMap.Gyms.Url, Latitude, Longitude) : string.Empty var gmapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? gmapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, gmapsLink); var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); + var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); const string defaultMissingValue = "?"; @@ -173,6 +173,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh { "gmaps_url", gmapsLocationLink }, { "applemaps_url", appleMapsLocationLink }, { "wazemaps_url", wazeMapsLocationLink }, + { "scanmaps_url", scannerMapsLocationLink }, // Discord Guild properties { "guild_name", guild?.Name }, diff --git a/src/Net/Models/PokemonData.cs b/src/Net/Models/PokemonData.cs index b5cad74f..c465968c 100644 --- a/src/Net/Models/PokemonData.cs +++ b/src/Net/Models/PokemonData.cs @@ -459,11 +459,13 @@ private async Task> GetProperties(DiscordGui var gmapsLink = string.Format(Strings.GoogleMaps, Latitude, Longitude); var appleMapsLink = string.Format(Strings.AppleMaps, Latitude, Longitude); var wazeMapsLink = string.Format(Strings.WazeMaps, Latitude, Longitude); + var scannerMapsLink = string.Format(whConfig.Urls.ScannerMap, Latitude, Longitude); var templatePath = Path.Combine(whConfig.StaticMaps.TemplatesFolder, whConfig.StaticMaps.PokemonTemplateFile); var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap, Latitude, Longitude, pokemonImageUrl, null); var gmapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? gmapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, gmapsLink); var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); + var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); var pokestop = Pokestop.Pokestops.ContainsKey(PokestopId) ? Pokestop.Pokestops[PokestopId] : null; @@ -560,6 +562,7 @@ private async Task> GetProperties(DiscordGui { "gmaps_url", gmapsLocationLink }, { "applemaps_url", appleMapsLocationLink }, { "wazemaps_url", wazeMapsLocationLink }, + { "scanmaps_url", scannerMapsLocationLink }, // Pokestop properties { "near_pokestop", Convert.ToString(pokestop != null) }, diff --git a/src/Net/Models/PokestopData.cs b/src/Net/Models/PokestopData.cs index 30c35bde..5b0fcd35 100644 --- a/src/Net/Models/PokestopData.cs +++ b/src/Net/Models/PokestopData.cs @@ -147,11 +147,13 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var gmapsLink = string.Format(Strings.GoogleMaps, Latitude, Longitude); var appleMapsLink = string.Format(Strings.AppleMaps, Latitude, Longitude); var wazeMapsLink = string.Format(Strings.WazeMaps, Latitude, Longitude); + var scannerMapsLink = string.Format(whConfig.Urls.ScannerMap, Latitude, Longitude); var templatePath = Path.Combine(whConfig.StaticMaps.TemplatesFolder, HasInvasion ? whConfig.StaticMaps.InvasionsTemplateFile : HasLure ? whConfig.StaticMaps.LuresTemplateFile : whConfig.StaticMaps.LuresTemplateFile); var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap, Latitude, Longitude, imageUrl, null); var gmapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? gmapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, gmapsLink); var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); + var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); var invasion = MasterFile.Instance.GruntTypes.ContainsKey(GruntType) ? MasterFile.Instance.GruntTypes[GruntType] : null; var leaderString = Translator.Instance.Translate("grunt_" + Convert.ToInt32(GruntType)); @@ -189,6 +191,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh { "gmaps_url", gmapsLocationLink }, { "applemaps_url", appleMapsLocationLink }, { "wazemaps_url", wazeMapsLocationLink }, + { "scanmaps_url", scannerMapsLocationLink }, //Pokestop properties { "pokestop_id", PokestopId ?? defaultMissingValue }, diff --git a/src/Net/Models/QuestData.cs b/src/Net/Models/QuestData.cs index 4dd77c2e..5fd3a36c 100644 --- a/src/Net/Models/QuestData.cs +++ b/src/Net/Models/QuestData.cs @@ -113,11 +113,13 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var gmapsLink = string.Format(Strings.GoogleMaps, Latitude, Longitude); var appleMapsLink = string.Format(Strings.AppleMaps, Latitude, Longitude); var wazeMapsLink = string.Format(Strings.WazeMaps, Latitude, Longitude); + var scannerMapsLink = string.Format(whConfig.Urls.ScannerMap, Latitude, Longitude); var templatePath = Path.Combine(whConfig.StaticMaps.TemplatesFolder, whConfig.StaticMaps.QuestsTemplateFile); var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap, Latitude, Longitude, questRewardImageUrl, null); var gmapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? gmapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, gmapsLink); var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); + var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); const string defaultMissingValue = "?"; @@ -144,6 +146,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh { "gmaps_url", gmapsLocationLink }, { "applemaps_url", appleMapsLocationLink }, { "wazemaps_url", wazeMapsLocationLink }, + { "scanmaps_url", scannerMapsLocationLink }, //Pokestop properties { "pokestop_id", PokestopId ?? defaultMissingValue }, diff --git a/src/Net/Models/RaidData.cs b/src/Net/Models/RaidData.cs index f742aee9..9f6cd5dc 100644 --- a/src/Net/Models/RaidData.cs +++ b/src/Net/Models/RaidData.cs @@ -198,11 +198,13 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var gmapsLink = string.Format(Strings.GoogleMaps, Latitude, Longitude); var appleMapsLink = string.Format(Strings.AppleMaps, Latitude, Longitude); var wazeMapsLink = string.Format(Strings.WazeMaps, Latitude, Longitude); + var scannerMapsLink = string.Format(whConfig.Urls.ScannerMap, Latitude, Longitude); var templatePath = Path.Combine(whConfig.StaticMaps.TemplatesFolder, whConfig.StaticMaps.RaidsTemplateFile); var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap, Latitude, Longitude, raidImageUrl, Team); var gmapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? gmapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, gmapsLink); var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); + var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); const string defaultMissingValue = "?"; @@ -257,6 +259,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh { "gmaps_url", gmapsLocationLink }, { "applemaps_url", appleMapsLocationLink }, { "wazemaps_url", wazeMapsLocationLink }, + { "scanmaps_url", scannerMapsLocationLink }, //Gym properties { "gym_id", GymId }, diff --git a/src/Net/Models/WeatherData.cs b/src/Net/Models/WeatherData.cs index 97196745..12f86bfe 100644 --- a/src/Net/Models/WeatherData.cs +++ b/src/Net/Models/WeatherData.cs @@ -147,11 +147,13 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var gmapsLink = string.Format(Strings.GoogleMaps, Latitude, Longitude); var appleMapsLink = string.Format(Strings.AppleMaps, Latitude, Longitude); var wazeMapsLink = string.Format(Strings.WazeMaps, Latitude, Longitude); + var scannerMapsLink = string.Format(whConfig.Urls.ScannerMap, Latitude, Longitude); var templatePath = Path.Combine(whConfig.StaticMaps.TemplatesFolder, whConfig.StaticMaps.WeatherTemplateFile); var staticMapLink = Utils.GetStaticMapsUrl(templatePath, whConfig.Urls.StaticMap.Replace("/15/", "/11/"), Latitude, Longitude, weatherImageUrl, null); var gmapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? gmapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, gmapsLink); var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); + var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); const string defaultMissingValue = "?"; @@ -187,6 +189,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh { "gmaps_url", gmapsLocationLink }, { "applemaps_url", appleMapsLocationLink }, { "wazemaps_url", wazeMapsLocationLink }, + { "scanmaps_url", scannerMapsLocationLink }, // Discord Guild properties { "guild_name", guild?.Name }, From 568dda6adc055618e71ca14fefbcee5d0b6343a4 Mon Sep 17 00:00:00 2001 From: versx Date: Tue, 7 Jul 2020 17:52:07 -0700 Subject: [PATCH 14/19] Update README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a2468336..c80c3c59 100644 --- a/README.md +++ b/README.md @@ -236,7 +236,7 @@ bitsadmin /transfer dotnet-install-job /download /priority FOREGROUND https://ra }, // Get text message alerts with Twilio.com "twilio": { - // Determines if text message alerts are be enabled + // Determines if text message alerts are enabled "enabled": false, // Twilio account SID (Get via Twilio dashboard) "accountSid": "", @@ -246,14 +246,14 @@ bitsadmin /transfer dotnet-install-job /download /priority FOREGROUND https://ra "from": "", // List of Discord user ids that can receive text message alerts "userIds": "", - // List of acceptable Pokemon to receive text message alerts from + // List of acceptable Pokemon to receive text message alerts for "pokemonIds": [201, 480, 481, 482, 443, 444, 445, 633, 634, 635, 610, 611, 612], - // Minimum acceptable IV value for Pokemon to be if not ultra rare (Unown, Lake Trio) + // Minimum acceptable IV value for Pokemon if not ultra rare (Unown, Lake Trio) "minIV": 100 }, // Log webhook payloads to a file for debugging "debug": false, - // Only show logs with higher or equal priority levels + // Only show logs with higher or equal priority levels (Trace, Debug, Info, Warning, Error, Fatal, None) "logLevel": "Trace" } ``` From b63f59957f366c7c1ea2ccf041359d953201370e Mon Sep 17 00:00:00 2001 From: versx Date: Tue, 7 Jul 2020 18:20:24 -0700 Subject: [PATCH 15/19] Move mentionable string to alerts.json file --- README.md | 6 ------ examples/alerts/default.json | 11 +++++++++++ src/Alarms/Alerts/AlertMessageSettings.cs | 8 +++++++- src/Alarms/Models/AlarmObject.cs | 4 ++-- src/Bot.cs | 14 +++++++++----- src/Net/Models/GymDetailsData.cs | 13 +++++-------- src/Net/Models/PokemonData.cs | 18 +++++++++--------- src/Net/Models/PokestopData.cs | 13 +++++-------- src/Net/Models/QuestData.cs | 17 ++++++++--------- src/Net/Models/RaidData.cs | 13 +++++-------- src/Net/Models/WeatherData.cs | 13 +++++-------- 11 files changed, 66 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index c80c3c59..c5a265ea 100644 --- a/README.md +++ b/README.md @@ -293,9 +293,6 @@ bitsadmin /transfer dotnet-install-job /download /priority FOREGROUND https://ra //Path to geofence file. "geofence":"geofence1.txt", - //DTS compatible mention description. - "mentions":" L ", - //Discord webhook url address. "webhook":"" },{ @@ -310,9 +307,6 @@ bitsadmin /transfer dotnet-install-job /download /priority FOREGROUND https://ra //Path to geofence file. "geofence":"geofence1.txt", - - //DTS compatible mention description. - "mentions":"" //Discord webhook url address. "webhook":"" diff --git a/examples/alerts/default.json b/examples/alerts/default.json index 11a5d8c1..4ef5b3c6 100644 --- a/examples/alerts/default.json +++ b/examples/alerts/default.json @@ -1,6 +1,7 @@ { "pokemon": { "avatarUrl": "", + "description": " L ", "content": " (//) L
**Despawn:** ( left)
**Details:** CP: IV: LV:
**Types:** | **Size:** <#has_weather> | <#is_weather_boosted> (Boosted)
**Moveset:**
<#near_pokestop>**Near Pokestop:** []()
<#is_ditto>**Catch Pokemon:**
<#has_capture_rates> % % %
<#is_pvp>
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": "", @@ -14,6 +15,7 @@ }, "pokemonMissingStats": { "avatarUrl": "", + "description": "", "content": "
**Despawn:** ( left)
**Types:**
<#near_pokestop>**Near Pokestop:** []()
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": "", @@ -27,6 +29,7 @@ }, "gyms": { "avatarUrl": "", + "description": "", "content": "<#team_changed>Gym changed from to
<#in_battle>Gym is under attack!
**Slots Available:**
<#is_ex> Gym!**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", @@ -40,6 +43,7 @@ }, "raids": { "avatarUrl": "", + "description": "", "content": " Raid Ends: ( left)
**Perfect CP:** / :white_sun_rain_cloud:
**Worst CP:** / :white_sun_rain_cloud:
**Types:** | **Level:** | **Team:**
**Moveset:**
**Weaknesses:**
<#is_ex> Gym!
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", @@ -53,6 +57,7 @@ }, "eggs": { "avatarUrl": "", + "description": "", "content": "Hatches: ()
**Ends:** ( left)
**Team:**
<#is_ex> Gym!
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", @@ -66,6 +71,7 @@ }, "pokestops": { "avatarUrl": "", + "description": "", "content": "<#has_lure>**Lure Expires** ( left)
**Lure Type:**
<#has_invasion>**Expires:** ( left)
**Type:** | **Gender:**

**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", @@ -78,6 +84,7 @@ } }, "quests": { + "description": "", "avatarUrl": "", "content": "**Quest:**
<#has_quest_conditions>**Condition(s):**
**Reward:**
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", @@ -91,6 +98,7 @@ } }, "lures": { + "description": "", "avatarUrl": "", "content": "<#has_lure>**Lure Expires:** ( left)
**Lure Type:**
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", @@ -104,6 +112,7 @@ } }, "invasions": { + "description": "", "avatarUrl": "", "content": "<#has_invasion>**Expires:** ( left)
**Type:** | **Gender:**

**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", @@ -117,6 +126,7 @@ } }, "nests": { + "description": "", "avatarUrl": "", "content": "**Pokemon:**
**Average Spawns:** /h | **Types:**
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", @@ -130,6 +140,7 @@ } }, "weather": { + "description": "", "avatarUrl": "", "content": "**Weather Condition:**
**Weather Cell ID:** #", "iconUrl": "", diff --git a/src/Alarms/Alerts/AlertMessageSettings.cs b/src/Alarms/Alerts/AlertMessageSettings.cs index d640c9b3..a53e0a5c 100644 --- a/src/Alarms/Alerts/AlertMessageSettings.cs +++ b/src/Alarms/Alerts/AlertMessageSettings.cs @@ -8,7 +8,13 @@ public class AlertMessageSettings { /// - /// Gets or sets the Discord message content. + /// Gets or sets the Discord message content outside of the embed message. (above it) + /// + [JsonProperty("description")] + public string Description { get; set; } + + /// + /// Gets or sets the Discord message content within the embed message. /// [JsonProperty("content")] public string Content { get; set; } diff --git a/src/Alarms/Models/AlarmObject.cs b/src/Alarms/Models/AlarmObject.cs index 294f20cf..7c454ff7 100644 --- a/src/Alarms/Models/AlarmObject.cs +++ b/src/Alarms/Models/AlarmObject.cs @@ -67,8 +67,8 @@ public class AlarmObject /// /// Gets or sets the Discord mentions string to use in the Discord message description /// - [JsonProperty("mentions")] - public string Mentions { get; set; } + //[JsonProperty("mentions")] + //public string Mentions { get; set; } /// /// Instantiate a new class diff --git a/src/Bot.cs b/src/Bot.cs index f4b85a72..14aa5173 100644 --- a/src/Bot.cs +++ b/src/Bot.cs @@ -32,8 +32,6 @@ // TODO: List all subscriptions with info command // TODO: Manage subscriptions via DM again // TODO: Multiple discord bot tokens per server - // TODO: Add map url to config and DTS options - // TODO: Add scanmap_url to DTS // TODO: Move mentions string from alarms.json to alerts.json for alarm type as 'Description' property // TODO: Google address option // TODO: Cache gyms upon startup @@ -499,6 +497,7 @@ private async void OnPokemonAlarmTriggered(object sender, AlarmEventTriggeredEve { Username = eb.Username, AvatarUrl = eb.IconUrl, + Content = eb.Description, Embeds = eb.Embeds }.Build(); NetUtil.SendWebhook(e.Alarm.Webhook, jsonEmbed); @@ -545,6 +544,7 @@ private void OnRaidAlarmTriggered(object sender, AlarmEventTriggeredEventArgs { eb } + Username = eb.Username, + AvatarUrl = eb.IconUrl, + Content = eb.Description, + Embeds = eb.Embeds }.Build(); NetUtil.SendWebhook(e.Alarm.Webhook, jsonEmbed); Statistics.Instance.QuestAlarmsSent++; @@ -628,6 +629,7 @@ private void OnPokestopAlarmTriggered(object sender, AlarmEventTriggeredEventArg { Username = eb.Username ?? Translator.Instance.Translate("UNKNOWN_POKESTOP"), AvatarUrl = eb.IconUrl, + Content = eb.Description, Embeds = eb.Embeds }.Build(); NetUtil.SendWebhook(e.Alarm.Webhook, jsonEmbed); @@ -687,6 +689,7 @@ private void OnGymDetailsAlarmTriggered(object sender, AlarmEventTriggeredEventA { Username = eb.Username, AvatarUrl = eb.IconUrl, + Content = eb.Description, Embeds = eb.Embeds }.Build(); NetUtil.SendWebhook(e.Alarm.Webhook, jsonEmbed); @@ -732,6 +735,7 @@ private void OnWeatherAlarmTriggered(object sender, AlarmEventTriggeredEventArgs { Username = eb.Username, AvatarUrl = eb.IconUrl, + Content = eb.Description, Embeds = eb.Embeds }.Build(); NetUtil.SendWebhook(e.Alarm.Webhook, jsonEmbed); diff --git a/src/Net/Models/GymDetailsData.cs b/src/Net/Models/GymDetailsData.cs index 4a64e48b..3e311d4f 100644 --- a/src/Net/Models/GymDetailsData.cs +++ b/src/Net/Models/GymDetailsData.cs @@ -91,30 +91,27 @@ public DiscordEmbedNotification GenerateGymMessage(ulong guildId, DiscordClient var alertType = AlertMessageType.Gyms; var alert = alarm?.Alerts[alertType] ?? AlertMessage.Defaults[alertType]; var properties = GetProperties(client.Guilds[guildId], whConfig, city, oldGym); - var mention = DynamicReplacementEngine.ReplaceText(alarm.Mentions, properties); - var description = DynamicReplacementEngine.ReplaceText(alert.Content, properties); - var footerText = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? $"{Strings.Creator} | {DateTime.Now}", properties); - var footerIconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties); var eb = new DiscordEmbedBuilder { Title = DynamicReplacementEngine.ReplaceText(alert.Title, properties), Url = DynamicReplacementEngine.ReplaceText(alert.Url, properties), ImageUrl = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties), ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), - Description = mention + description, + Description = DynamicReplacementEngine.ReplaceText(alert.Content, properties), Color = Team == PokemonTeam.Mystic ? DiscordColor.Blue : Team == PokemonTeam.Valor ? DiscordColor.Red : Team == PokemonTeam.Instinct ? DiscordColor.Yellow : DiscordColor.LightGray, Footer = new DiscordEmbedBuilder.EmbedFooter { - Text = footerText, - IconUrl = footerIconUrl + Text = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? DateTime.Now.ToString(), properties), + IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties) } }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - return new DiscordEmbedNotification(username, iconUrl, new List { eb.Build() }); + var description = DynamicReplacementEngine.ReplaceText(alert.Description, properties); + return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } private IReadOnlyDictionary GetProperties(DiscordGuild guild, WhConfig whConfig, string city, GymDetailsData oldGym) diff --git a/src/Net/Models/PokemonData.cs b/src/Net/Models/PokemonData.cs index c465968c..279f929b 100644 --- a/src/Net/Models/PokemonData.cs +++ b/src/Net/Models/PokemonData.cs @@ -397,27 +397,24 @@ public async Task GeneratePokemonMessage(ulong guildId var server = whConfig.Servers[guildId]; var pokemonImageUrl = Id.GetPokemonIcon(FormId, Costume, whConfig, server.IconStyle); var properties = await GetProperties(client.Guilds[guildId], whConfig, city, pokemonImageUrl); - var mention = DynamicReplacementEngine.ReplaceText(alarm?.Mentions ?? string.Empty, properties); - var description = DynamicReplacementEngine.ReplaceText(alert.Content, properties); - var footerText = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? $"{Strings.Creator} | {DateTime.Now}", properties); - var footerIconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties); var eb = new DiscordEmbedBuilder { Title = DynamicReplacementEngine.ReplaceText(alert.Title, properties), Url = DynamicReplacementEngine.ReplaceText(alert.Url, properties), ImageUrl = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties), ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), - Description = mention + description, + Description = DynamicReplacementEngine.ReplaceText(alert.Content, properties), Color = IV.BuildColor(), Footer = new DiscordEmbedBuilder.EmbedFooter { - Text = footerText, - IconUrl = footerIconUrl + Text = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? DateTime.Now.ToString(), properties), + IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties) } }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - return await Task.FromResult(new DiscordEmbedNotification(username, iconUrl, new List { eb.Build() })); + var description = alert.Description?.Length > 0 ? DynamicReplacementEngine.ReplaceText(alert.Description, properties) : string.Empty; + return await Task.FromResult(new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() })); } #endregion @@ -697,12 +694,15 @@ public class DiscordEmbedNotification public string IconUrl { get; set; } + public string Description { get; set; } + public List Embeds { get; set; } - public DiscordEmbedNotification(string username, string iconUrl, List embeds) + public DiscordEmbedNotification(string username, string iconUrl, string description, List embeds) { Username = username; IconUrl = iconUrl; + Description = description; Embeds = embeds; } } diff --git a/src/Net/Models/PokestopData.cs b/src/Net/Models/PokestopData.cs index 5b0fcd35..e4070419 100644 --- a/src/Net/Models/PokestopData.cs +++ b/src/Net/Models/PokestopData.cs @@ -107,17 +107,13 @@ public DiscordEmbedNotification GeneratePokestopMessage(ulong guildId, DiscordCl var alertType = HasInvasion ? AlertMessageType.Invasions : HasLure ? AlertMessageType.Lures : AlertMessageType.Pokestops; var alert = alarm?.Alerts[alertType] ?? AlertMessage.Defaults[alertType]; var properties = GetProperties(client.Guilds[guildId], whConfig, city); - var mention = DynamicReplacementEngine.ReplaceText(alarm?.Mentions ?? string.Empty, properties); - var description = DynamicReplacementEngine.ReplaceText(alert.Content, properties); - var footerText = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? $"{Strings.Creator} | {DateTime.Now}", properties); - var footerIconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties); var eb = new DiscordEmbedBuilder { Title = DynamicReplacementEngine.ReplaceText(alert.Title, properties), Url = DynamicReplacementEngine.ReplaceText(alert.Url, properties), ImageUrl = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties), ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), - Description = mention + description, + Description = DynamicReplacementEngine.ReplaceText(alert.Content, properties), Color = HasInvasion ? DiscordColor.Red : HasLure ? (LureType == PokestopLureType.Normal ? DiscordColor.HotPink : LureType == PokestopLureType.Glacial ? DiscordColor.CornflowerBlue @@ -126,13 +122,14 @@ public DiscordEmbedNotification GeneratePokestopMessage(ulong guildId, DiscordCl : DiscordColor.CornflowerBlue) : DiscordColor.CornflowerBlue, Footer = new DiscordEmbedBuilder.EmbedFooter { - Text = footerText, - IconUrl = footerIconUrl + Text = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? DateTime.Now.ToString(), properties), + IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties) } }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - return new DiscordEmbedNotification(username, iconUrl, new List { eb.Build() }); + var description = DynamicReplacementEngine.ReplaceText(alert.Description ?? string.Empty, properties); + return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } #endregion diff --git a/src/Net/Models/QuestData.cs b/src/Net/Models/QuestData.cs index 5fd3a36c..4d6ae2bf 100644 --- a/src/Net/Models/QuestData.cs +++ b/src/Net/Models/QuestData.cs @@ -79,30 +79,29 @@ public QuestData() Conditions = new List(); } - public DiscordEmbed GenerateQuestMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city) + public DiscordEmbedNotification GenerateQuestMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city) { var alertType = AlertMessageType.Quests; var alert = alarm?.Alerts[alertType] ?? AlertMessage.Defaults[alertType]; var properties = GetProperties(client.Guilds[guildId], whConfig, city, this.GetQuestIcon(whConfig, whConfig.Servers[guildId].IconStyle)); - var mention = DynamicReplacementEngine.ReplaceText(alarm?.Mentions ?? string.Empty, properties); - var description = DynamicReplacementEngine.ReplaceText(alert.Content, properties); - var footerText = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? $"{Strings.Creator} | {DateTime.Now}", properties); - var footerIconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties); var eb = new DiscordEmbedBuilder { Title = DynamicReplacementEngine.ReplaceText(alert.Title, properties), Url = DynamicReplacementEngine.ReplaceText(alert.Url, properties), ImageUrl = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties), ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), - Description = mention + description, + Description = DynamicReplacementEngine.ReplaceText(alert.Content, properties), Color = DiscordColor.Orange, Footer = new DiscordEmbedBuilder.EmbedFooter { - Text = footerText, - IconUrl = footerIconUrl + Text = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? DateTime.Now.ToString(), properties), + IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties) } }; - return eb.Build(); + var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); + var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); + var description = DynamicReplacementEngine.ReplaceText(alert.Description ?? string.Empty, properties); + return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } private IReadOnlyDictionary GetProperties(DiscordGuild guild, WhConfig whConfig, string city, string questRewardImageUrl) diff --git a/src/Net/Models/RaidData.cs b/src/Net/Models/RaidData.cs index 9f6cd5dc..649cc6b6 100644 --- a/src/Net/Models/RaidData.cs +++ b/src/Net/Models/RaidData.cs @@ -147,27 +147,24 @@ public DiscordEmbedNotification GenerateRaidMessage(ulong guildId, DiscordClient this.GetRaidEggIcon(whConfig, server.IconStyle) : PokemonId.GetPokemonIcon(Form, 0, whConfig, server.IconStyle); var properties = GetProperties(client.Guilds[guildId], whConfig, city, raidImageUrl); - var mention = DynamicReplacementEngine.ReplaceText(alarm?.Mentions ?? string.Empty, properties); - var description = DynamicReplacementEngine.ReplaceText(alert.Content, properties); - var footerText = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? $"{Strings.Creator} | {DateTime.Now}", properties); - var footerIconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties); var eb = new DiscordEmbedBuilder { Title = DynamicReplacementEngine.ReplaceText(alert.Title, properties), Url = DynamicReplacementEngine.ReplaceText(alert.Url, properties), ImageUrl = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties), ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), - Description = mention + description, + Description = DynamicReplacementEngine.ReplaceText(alert.Content, properties), Color = Level.BuildRaidColor(), Footer = new DiscordEmbedBuilder.EmbedFooter { - Text = footerText, - IconUrl = footerIconUrl + Text = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? DateTime.Now.ToString(), properties), + IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties) } }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - return new DiscordEmbedNotification(username, iconUrl, new List { eb.Build() }); + var description = DynamicReplacementEngine.ReplaceText(alert.Description ?? string.Empty, properties); + return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } private IReadOnlyDictionary GetProperties(DiscordGuild guild, WhConfig whConfig, string city, string raidImageUrl) diff --git a/src/Net/Models/WeatherData.cs b/src/Net/Models/WeatherData.cs index 12f86bfe..b1b72bbf 100644 --- a/src/Net/Models/WeatherData.cs +++ b/src/Net/Models/WeatherData.cs @@ -115,27 +115,24 @@ public DiscordEmbedNotification GenerateWeatherMessage(ulong guildId, DiscordCli var server = whConfig.Servers[guildId]; var weatherImageUrl = this.GetWeatherIcon(whConfig, server.IconStyle); var properties = GetProperties(client.Guilds[guildId], whConfig, city, weatherImageUrl); - var mention = DynamicReplacementEngine.ReplaceText(alarm.Mentions, properties); - var description = DynamicReplacementEngine.ReplaceText(alert.Content, properties); - var footerText = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? $"{Strings.Creator} | {DateTime.Now}", properties); - var footerIconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties); var eb = new DiscordEmbedBuilder { Title = DynamicReplacementEngine.ReplaceText(alert.Title, properties), Url = DynamicReplacementEngine.ReplaceText(alert.Url, properties), ImageUrl = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties), ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), - Description = mention + description, + Description = DynamicReplacementEngine.ReplaceText(alert.Content, properties), Color = GameplayCondition.BuildWeatherColor(), Footer = new DiscordEmbedBuilder.EmbedFooter { - Text = footerText, - IconUrl = footerIconUrl + Text = DynamicReplacementEngine.ReplaceText(alert.Footer?.Text ?? client.Guilds[guildId]?.Name ?? DateTime.Now.ToString(), properties), + IconUrl = DynamicReplacementEngine.ReplaceText(alert.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties) } }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - return new DiscordEmbedNotification(username, iconUrl, new List { eb.Build() }); + var description = DynamicReplacementEngine.ReplaceText(alert.Description, properties); + return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } private IReadOnlyDictionary GetProperties(DiscordGuild guild, WhConfig whConfig, string city, string weatherImageUrl) From bcb89c841f0cc2ea8de9c7a195f75979d6c52d74 Mon Sep 17 00:00:00 2001 From: versx Date: Tue, 7 Jul 2020 18:45:12 -0700 Subject: [PATCH 16/19] Add google address lookup to alarms with DTS option --- src/Bot.cs | 4 +- src/Commands/Nests.cs | 18 +++-- src/Configuration/WhConfig.cs | 6 ++ .../Subscriptions/SubscriptionProcessor.cs | 5 +- src/Geofence/Location.cs | 25 +++++++ src/Net/Models/GymDetailsData.cs | 3 + src/Net/Models/PokemonData.cs | 3 + src/Net/Models/PokestopData.cs | 3 + src/Net/Models/QuestData.cs | 3 + src/Net/Models/RaidData.cs | 3 + src/Net/Models/WeatherData.cs | 3 + src/Utilities/Utils.cs | 71 ++++++++++++++++++- 12 files changed, 136 insertions(+), 11 deletions(-) diff --git a/src/Bot.cs b/src/Bot.cs index 14aa5173..ee778bea 100644 --- a/src/Bot.cs +++ b/src/Bot.cs @@ -32,10 +32,8 @@ // TODO: List all subscriptions with info command // TODO: Manage subscriptions via DM again // TODO: Multiple discord bot tokens per server - // TODO: Move mentions string from alarms.json to alerts.json for alarm type as 'Description' property - // TODO: Google address option - // TODO: Cache gyms upon startup // TODO: Only start database migrator if subscriptions are enabled + // TODO: Shiny stats crash/fail first time public class Bot { diff --git a/src/Commands/Nests.cs b/src/Commands/Nests.cs index b409df49..b2df5150 100644 --- a/src/Commands/Nests.cs +++ b/src/Commands/Nests.cs @@ -79,8 +79,7 @@ public async Task PostNestsAsync(CommandContext ctx) try { - var pkmnImage = nest.PokemonId.GetPokemonIcon(0, 0, _dep.WhConfig, server.IconStyle); - var eb = GenerateNestMessage(ctx.Guild.Id, ctx.Client, nest, pkmnImage); + var eb = GenerateNestMessage(ctx.Guild.Id, ctx.Client, nest); var geofences = _dep.Whm.Geofences.Values.ToList(); var geofence = GeofenceService.GetGeofence(geofences, new Location(nest.Latitude, nest.Longitude)); if (geofence == null) @@ -101,23 +100,25 @@ public async Task PostNestsAsync(CommandContext ctx) } } - public DiscordEmbed GenerateNestMessage(ulong guildId, DiscordClient client, Nest nest, string pokemonImageUrl) + public DiscordEmbed GenerateNestMessage(ulong guildId, DiscordClient client, Nest nest) { var alertMessageType = AlertMessageType.Nests; var alertMessage = /*alarm?.Alerts[alertMessageType] ??*/ AlertMessage.Defaults[alertMessageType]; // TODO: Add nestAlert config option + var server = _dep.WhConfig.Servers[guildId]; + var pokemonImageUrl = nest.PokemonId.GetPokemonIcon(0, 0, _dep.WhConfig, server.IconStyle); var properties = GetProperties(nest, pokemonImageUrl); var eb = new DiscordEmbedBuilder { Title = DynamicReplacementEngine.ReplaceText(alertMessage.Title, properties), Url = DynamicReplacementEngine.ReplaceText(alertMessage.Url, properties), ImageUrl = DynamicReplacementEngine.ReplaceText(alertMessage.ImageUrl, properties), - ThumbnailUrl = pokemonImageUrl, + ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alertMessage.IconUrl, properties), Description = DynamicReplacementEngine.ReplaceText(alertMessage.Content, properties), Color = DiscordColor.Green, Footer = new DiscordEmbedBuilder.EmbedFooter { - Text = $"{(client.Guilds.ContainsKey(guildId) ? client.Guilds[guildId]?.Name : Strings.Creator)} | {DateTime.Now}", - IconUrl = client.Guilds.ContainsKey(guildId) ? client.Guilds[guildId]?.IconUrl : string.Empty + Text = DynamicReplacementEngine.ReplaceText(alertMessage.Footer?.Text ?? client.Guilds[guildId]?.Name ?? DateTime.Now.ToString(), properties), + IconUrl = DynamicReplacementEngine.ReplaceText(alertMessage.Footer?.IconUrl ?? client.Guilds[guildId]?.IconUrl ?? string.Empty, properties) } }; return eb.Build(); @@ -136,8 +137,10 @@ public IReadOnlyDictionary GetProperties(Nest nest, string pokem var gmapsLink = string.Format(Strings.GoogleMaps, nest.Latitude, nest.Longitude); var appleMapsLink = string.Format(Strings.AppleMaps, nest.Latitude, nest.Longitude); var wazeMapsLink = string.Format(Strings.WazeMaps, nest.Latitude, nest.Longitude); + var scannerMapsLink = string.Format(_dep.WhConfig.Urls.ScannerMap, nest.Latitude, nest.Longitude); var templatePath = Path.Combine(_dep.WhConfig.StaticMaps.TemplatesFolder, _dep.WhConfig.StaticMaps.NestsTemplateFile); var staticMapLink = Utils.GetStaticMapsUrl(templatePath, _dep.WhConfig.Urls.StaticMap, nest.Latitude, nest.Longitude, pkmnImage, null, _dep.OsmManager.GetNest(nest.Name)?.FirstOrDefault()); + var googleAddress = Utils.GetGoogleAddress(nest.Latitude, nest.Longitude, _dep.WhConfig.GoogleMapsKey); var geofences = _dep.Whm.Geofences.Values.ToList(); var geofence = GeofenceService.GetGeofence(geofences, new Location(nest.Latitude, nest.Longitude)); var city = geofence?.Name ?? "Unknown"; @@ -170,6 +173,9 @@ public IReadOnlyDictionary GetProperties(Nest nest, string pokem { "gmaps_url", gmapsLink }, { "applemaps_url", appleMapsLink }, { "wazemaps_url", wazeMapsLink }, + { "scanmaps_url", scannerMapsLink }, + + { "address", googleAddress?.Address }, { "date_time", DateTime.Now.ToString() }, diff --git a/src/Configuration/WhConfig.cs b/src/Configuration/WhConfig.cs index 2b16d87a..36fda4cd 100644 --- a/src/Configuration/WhConfig.cs +++ b/src/Configuration/WhConfig.cs @@ -86,6 +86,12 @@ public class WhConfig [JsonProperty("twilio")] public TwilioConfig Twilio { get; set; } + /// + /// Gets or sets the Google maps key for location lookup + /// + [JsonProperty("gmapsKey")] + public string GoogleMapsKey { get; set; } + /// /// Gets or sets whether to log incoming webhook data to a file /// diff --git a/src/Data/Subscriptions/SubscriptionProcessor.cs b/src/Data/Subscriptions/SubscriptionProcessor.cs index 1110e19a..3bc2cc0d 100644 --- a/src/Data/Subscriptions/SubscriptionProcessor.cs +++ b/src/Data/Subscriptions/SubscriptionProcessor.cs @@ -547,7 +547,10 @@ public async Task ProcessQuestSubscription(QuestData quest) } var embed = quest.GenerateQuestMessage(user.GuildId, client, _whConfig, null, loc.Name); - _queue.Enqueue(new NotificationItem(user, member, embed, questName, loc.Name)); + foreach (var emb in embed.Embeds) + { + _queue.Enqueue(new NotificationItem(user, member, emb, questName, loc.Name)); + } Statistics.Instance.SubscriptionQuestsSent++; Thread.Sleep(5); diff --git a/src/Geofence/Location.cs b/src/Geofence/Location.cs index f2ea7a7c..a3878aa9 100644 --- a/src/Geofence/Location.cs +++ b/src/Geofence/Location.cs @@ -5,6 +5,16 @@ /// public class Location { + /// + /// Gets the address for the location + /// + public string Address { get; set; } + + /// + /// Gets the city of the address + /// + public string City { get; } + /// /// Gets the geocoordinate latitude /// @@ -26,6 +36,21 @@ public Location(double lat, double lng) Longitude = lng; } + /// + /// Instantiates a new class + /// + /// Address of geocoordinates + /// City of address + /// Geocoordinate latitude + /// Geocoordinate longitude + public Location(string address, string city, double lat, double lng) + { + Address = address; + City = city; + Latitude = lat; + Longitude = lng; + } + /// /// Returns the string representation of class /// diff --git a/src/Net/Models/GymDetailsData.cs b/src/Net/Models/GymDetailsData.cs index 3e311d4f..aea6fa8f 100644 --- a/src/Net/Models/GymDetailsData.cs +++ b/src/Net/Models/GymDetailsData.cs @@ -134,6 +134,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); + var googleAddress = Utils.GetGoogleAddress(Latitude, Longitude, whConfig.GoogleMapsKey); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); const string defaultMissingValue = "?"; @@ -172,6 +173,8 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh { "wazemaps_url", wazeMapsLocationLink }, { "scanmaps_url", scannerMapsLocationLink }, + { "address", googleAddress?.Address }, + // Discord Guild properties { "guild_name", guild?.Name }, { "guild_img_url", guild?.IconUrl }, diff --git a/src/Net/Models/PokemonData.cs b/src/Net/Models/PokemonData.cs index 279f929b..12f0986b 100644 --- a/src/Net/Models/PokemonData.cs +++ b/src/Net/Models/PokemonData.cs @@ -463,6 +463,7 @@ private async Task> GetProperties(DiscordGui var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); + var googleAddress = Utils.GetGoogleAddress(Latitude, Longitude, whConfig.GoogleMapsKey); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); var pokestop = Pokestop.Pokestops.ContainsKey(PokestopId) ? Pokestop.Pokestops[PokestopId] : null; @@ -561,6 +562,8 @@ private async Task> GetProperties(DiscordGui { "wazemaps_url", wazeMapsLocationLink }, { "scanmaps_url", scannerMapsLocationLink }, + { "address", googleAddress?.Address }, + // Pokestop properties { "near_pokestop", Convert.ToString(pokestop != null) }, { "pokestop_id", PokestopId ?? defaultMissingValue }, diff --git a/src/Net/Models/PokestopData.cs b/src/Net/Models/PokestopData.cs index e4070419..81d871bb 100644 --- a/src/Net/Models/PokestopData.cs +++ b/src/Net/Models/PokestopData.cs @@ -151,6 +151,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); + var googleAddress = Utils.GetGoogleAddress(Latitude, Longitude, whConfig.GoogleMapsKey); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); var invasion = MasterFile.Instance.GruntTypes.ContainsKey(GruntType) ? MasterFile.Instance.GruntTypes[GruntType] : null; var leaderString = Translator.Instance.Translate("grunt_" + Convert.ToInt32(GruntType)); @@ -197,6 +198,8 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh { "lure_img_url", lureImageUrl }, { "invasion_img_url", invasionImageUrl }, + { "address", googleAddress?.Address }, + // Discord Guild properties { "guild_name", guild?.Name }, { "guild_img_url", guild?.IconUrl }, diff --git a/src/Net/Models/QuestData.cs b/src/Net/Models/QuestData.cs index 4d6ae2bf..d3289aef 100644 --- a/src/Net/Models/QuestData.cs +++ b/src/Net/Models/QuestData.cs @@ -119,6 +119,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); + var googleAddress = Utils.GetGoogleAddress(Latitude, Longitude, whConfig.GoogleMapsKey); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); const string defaultMissingValue = "?"; @@ -147,6 +148,8 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh { "wazemaps_url", wazeMapsLocationLink }, { "scanmaps_url", scannerMapsLocationLink }, + { "address", googleAddress?.Address }, + //Pokestop properties { "pokestop_id", PokestopId ?? defaultMissingValue }, { "pokestop_name", PokestopName ?? defaultMissingValue }, diff --git a/src/Net/Models/RaidData.cs b/src/Net/Models/RaidData.cs index 649cc6b6..b44990b5 100644 --- a/src/Net/Models/RaidData.cs +++ b/src/Net/Models/RaidData.cs @@ -202,6 +202,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); + var googleAddress = Utils.GetGoogleAddress(Latitude, Longitude, whConfig.GoogleMapsKey); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); const string defaultMissingValue = "?"; @@ -258,6 +259,8 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh { "wazemaps_url", wazeMapsLocationLink }, { "scanmaps_url", scannerMapsLocationLink }, + { "address", googleAddress?.Address }, + //Gym properties { "gym_id", GymId }, { "gym_name", GymName }, diff --git a/src/Net/Models/WeatherData.cs b/src/Net/Models/WeatherData.cs index b1b72bbf..015e7e98 100644 --- a/src/Net/Models/WeatherData.cs +++ b/src/Net/Models/WeatherData.cs @@ -151,6 +151,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); + var googleAddress = Utils.GetGoogleAddress(Latitude, Longitude, whConfig.GoogleMapsKey); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); const string defaultMissingValue = "?"; @@ -188,6 +189,8 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh { "wazemaps_url", wazeMapsLocationLink }, { "scanmaps_url", scannerMapsLocationLink }, + { "address", googleAddress?.Address }, + // Discord Guild properties { "guild_name", guild?.Name }, { "guild_img_url", guild?.IconUrl }, diff --git a/src/Utilities/Utils.cs b/src/Utilities/Utils.cs index 7a7bf8a8..8960e44d 100644 --- a/src/Utilities/Utils.cs +++ b/src/Utilities/Utils.cs @@ -2,19 +2,26 @@ { using System; using System.Collections.Generic; + using System.IO; + using System.Net; + using System.Text; using Newtonsoft.Json; - + using Newtonsoft.Json.Linq; using Twilio; using Twilio.Rest.Api.V2010.Account; using WhMgr.Configuration; + using WhMgr.Diagnostics; + using WhMgr.Geofence; using WhMgr.Net.Models; using WhMgr.Osm; using WhMgr.Osm.Models; public static class Utils { + private static readonly IEventLogger _logger = EventLogger.GetLogger("UTILS"); + // TODO: Provide better way for replacement values public static string GetStaticMapsUrl(string templateFileName, string staticMapUrl, double latitude, double longitude, string markerImageUrl, PokemonTeam? team, OsmFeature feature = null, MultiPolygon multiPolygon = null) { @@ -71,5 +78,67 @@ public static bool SendSmsMessage(string body, TwilioConfig config, string toPho //Console.WriteLine($"Response: {message}"); return message.ErrorCode == null; } + + public static Location GetGoogleAddress(double lat, double lng, string gmapsKey) + { + var apiKey = string.IsNullOrEmpty(gmapsKey) ? string.Empty : $"&key={gmapsKey}"; + var url = $"https://maps.googleapis.com/maps/api/geocode/json?latlng={lat},{lng}&sensor=true{apiKey}"; + var unknown = "Unknown"; + try + { + var request = (HttpWebRequest)WebRequest.Create(url); + var response = request.GetResponse(); + using (var responseStream = response.GetResponseStream()) + { + var reader = new StreamReader(responseStream, Encoding.UTF8); + var data = reader.ReadToEnd(); + var parseJson = JObject.Parse(data); + var status = Convert.ToString(parseJson["status"]); + if (string.Compare(status, "OK", true) == 0) + return null; + + var jsonres = parseJson["results"][0]; + var address = Convert.ToString(jsonres["formatted_address"]); + var addrComponents = jsonres["address_components"]; + var city = unknown; + var items = JsonConvert.DeserializeObject>>(addrComponents.ToString()); + foreach (var item in items) + { + foreach (var key in item) + { + if (string.Compare(key.Key, "types", true) != 0) + continue; + + if (!(key.Value is JArray types)) + continue; + + foreach (var type in types) + { + var t = type.ToString(); + if (string.Compare(t, "locality", true) != 0) + continue; + + city = Convert.ToString(item["short_name"]); + break; + } + + if (city != unknown) + break; + } + + if (city != unknown) + break; + } + + return new Location(address, city, lat, lng); + } + } + catch (Exception ex) + { + _logger.Error(ex); + } + + return null; + } } } \ No newline at end of file From 1302cbf887a8547308ca8936afe13cabfd387abd Mon Sep 17 00:00:00 2001 From: versx Date: Tue, 7 Jul 2020 20:02:18 -0700 Subject: [PATCH 17/19] Add delay between shiny posts --- src/Bot.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Bot.cs b/src/Bot.cs index ee778bea..77b9dd32 100644 --- a/src/Bot.cs +++ b/src/Bot.cs @@ -33,7 +33,6 @@ // TODO: Manage subscriptions via DM again // TODO: Multiple discord bot tokens per server // TODO: Only start database migrator if subscriptions are enabled - // TODO: Shiny stats crash/fail first time public class Bot { @@ -951,8 +950,15 @@ private async Task PostShinyStats(DiscordClient client, DiscordServerConfig serv _logger.Debug($"Posting shiny stats for guild {client.Guilds[guildId].Name} ({guildId}) in channel {server.ShinyStats.ChannelId}"); // Subtract an hour to make sure it shows yesterday's date. await statsChannel.SendMessageAsync(Translator.Instance.Translate("SHINY_STATS_TITLE").FormatText(DateTime.Now.Subtract(TimeSpan.FromHours(1)).ToLongDateString())); + Thread.Sleep(500); await statsChannel.SendMessageAsync(Translator.Instance.Translate("SHINY_STATS_NEWLINE")); var stats = await ShinyStats.GetShinyStats(_whConfig.Database.Scanner.ToString()); + if (stats == null) + { + _logger.Error($"Failed to get list of shiny stats for guild {guildId}, skipping..."); + return; + } + var sorted = stats.Keys.ToList(); sorted.Sort(); @@ -975,6 +981,7 @@ private async Task PostShinyStats(DiscordClient client, DiscordServerConfig serv { await statsChannel.SendMessageAsync(Translator.Instance.Translate("SHINY_STATS_MESSAGE_WITH_RATIO").FormatText(pkmn.Name, pokemon, pkmnStats.Shiny.ToString("N0"), pkmnStats.Total.ToString("N0"), chance)); } + Thread.Sleep(500); } var total = stats[0]; From da3a0f1cf586e0af91331e5eaeda1cb0811db83b Mon Sep 17 00:00:00 2001 From: versx Date: Thu, 9 Jul 2020 16:58:11 -0700 Subject: [PATCH 18/19] Revert mention description from alerts.json to alarms.json --- alarms.example.json | 21 +++++++++++++++++++++ examples/alerts/default.json | 11 ----------- examples/templates/gyms.example.json | 14 +++++++------- src/Alarms/Alerts/AlertMessageSettings.cs | 6 ------ src/Alarms/Models/AlarmObject.cs | 12 ++++++------ src/Bot.cs | 3 +++ src/Net/Models/GymDetailsData.cs | 2 +- src/Net/Models/PokemonData.cs | 2 +- src/Net/Models/PokestopData.cs | 2 +- src/Net/Models/QuestData.cs | 2 +- src/Net/Models/RaidData.cs | 2 +- src/Net/Models/WeatherData.cs | 2 +- 12 files changed, 43 insertions(+), 36 deletions(-) diff --git a/alarms.example.json b/alarms.example.json index c54473e9..96e46bdf 100644 --- a/alarms.example.json +++ b/alarms.example.json @@ -9,6 +9,7 @@ [ { "name":"City1-Rare", + "description": " L ", "alerts": "default.json", "filters":"all.json", "geofence":"City1.txt", @@ -17,6 +18,7 @@ }, { "name":"City1-100iv", + "description": "", "alerts": "default.json", "filters":"100iv.json", "geofence":"City1.txt", @@ -24,6 +26,7 @@ }, { "name":"City1-Raids", + "description": "", "alerts": "default.json", "filters":"raids.json", "geofence":"City1.txt", @@ -31,6 +34,7 @@ }, { "name":"City1-LegendaryRaids", + "description": "", "alerts": "default.json", "filters":"legendary_raids.json", "geofence":"City1.txt", @@ -38,6 +42,7 @@ }, { "name":"City1-ExRaids", + "description": "", "alerts": "default.json", "filters":"ex_raids.json", "geofence":"City1.txt", @@ -45,6 +50,7 @@ }, { "name": "City1-Quests", + "description": "", "alerts": "default.json", "filters": "quests.json", "geofence": "City1.txt", @@ -52,6 +58,7 @@ }, { "name": "City1-Lures", + "description": "", "alerts": "default.json", "filters": "lures.json", "geofence": "City1.txt", @@ -59,6 +66,7 @@ }, { "name": "City1-Invasions", + "description": "", "alerts": "default.json", "filters": "invasions.json", "geofence": "City1.txt", @@ -66,6 +74,7 @@ }, { "name": "City1-Gyms", + "description": "", "alerts": "default.json", "filters": "gyms.json", "geofence": "City1.txt", @@ -73,6 +82,7 @@ }, { "name":"City1-Weather", + "description": "", "alerts": "default.json", "filters":"weather.json", "geofence":"City1.txt", @@ -80,6 +90,7 @@ }, { "name":"City2-Rare", + "description": "", "alerts": "default.json", "filters":"all.json", "geofence":"City2.txt", @@ -87,6 +98,7 @@ }, { "name":"City2-100iv", + "description": "", "alerts": "default.json", "filters":"100iv.json", "geofence":"City2.txt", @@ -94,6 +106,7 @@ }, { "name":"City2-Raids", + "description": "", "alerts": "default.json", "filters":"raids.json", "geofence":"City2.txt", @@ -101,6 +114,7 @@ }, { "name":"City2-LegendaryRaids", + "description": "", "alerts": "default.json", "filters":"legendary_raids.json", "geofence":"City2.txt", @@ -108,6 +122,7 @@ }, { "name":"City2-ExRaids", + "description": "", "alerts": "default.json", "filters":"ex_raids.json", "geofence":"City2.txt", @@ -115,6 +130,7 @@ }, { "name": "City2-Quests", + "description": "", "alerts": "default.json", "filters": "quests.json", "geofence": "City2.txt", @@ -122,6 +138,7 @@ }, { "name": "City2-Lures", + "description": "", "alerts": "default.json", "filters": "lures.json", "geofence": "City2.txt", @@ -129,6 +146,7 @@ }, { "name": "City2-Invasions", + "description": "", "alerts": "default.json", "filters": "invasions.json", "geofence": "City2.txt", @@ -136,6 +154,7 @@ }, { "name": "City2-Gyms", + "description": "", "alerts": "default.json", "filters": "gyms.json", "geofence": "City2.txt", @@ -143,6 +162,7 @@ }, { "name":"Absol-Quests", + "description": "", "alerts": "default.json", "filters":"quests_absol.json", "geofence":"City2.txt", @@ -150,6 +170,7 @@ }, { "name":"City2-Weather", + "description": "", "alerts": "default.json", "filters":"weather.json", "geofence":"City2.txt", diff --git a/examples/alerts/default.json b/examples/alerts/default.json index 4ef5b3c6..11a5d8c1 100644 --- a/examples/alerts/default.json +++ b/examples/alerts/default.json @@ -1,7 +1,6 @@ { "pokemon": { "avatarUrl": "", - "description": " L ", "content": " (//) L
**Despawn:** ( left)
**Details:** CP: IV: LV:
**Types:** | **Size:** <#has_weather> | <#is_weather_boosted> (Boosted)
**Moveset:**
<#near_pokestop>**Near Pokestop:** []()
<#is_ditto>**Catch Pokemon:**
<#has_capture_rates> % % %
<#is_pvp>
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": "", @@ -15,7 +14,6 @@ }, "pokemonMissingStats": { "avatarUrl": "", - "description": "", "content": "
**Despawn:** ( left)
**Types:**
<#near_pokestop>**Near Pokestop:** []()
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": "", @@ -29,7 +27,6 @@ }, "gyms": { "avatarUrl": "", - "description": "", "content": "<#team_changed>Gym changed from to
<#in_battle>Gym is under attack!
**Slots Available:**
<#is_ex> Gym!**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", @@ -43,7 +40,6 @@ }, "raids": { "avatarUrl": "", - "description": "", "content": " Raid Ends: ( left)
**Perfect CP:** / :white_sun_rain_cloud:
**Worst CP:** / :white_sun_rain_cloud:
**Types:** | **Level:** | **Team:**
**Moveset:**
**Weaknesses:**
<#is_ex> Gym!
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", @@ -57,7 +53,6 @@ }, "eggs": { "avatarUrl": "", - "description": "", "content": "Hatches: ()
**Ends:** ( left)
**Team:**
<#is_ex> Gym!
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", @@ -71,7 +66,6 @@ }, "pokestops": { "avatarUrl": "", - "description": "", "content": "<#has_lure>**Lure Expires** ( left)
**Lure Type:**
<#has_invasion>**Expires:** ( left)
**Type:** | **Gender:**

**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", "title": ": ", @@ -84,7 +78,6 @@ } }, "quests": { - "description": "", "avatarUrl": "", "content": "**Quest:**
<#has_quest_conditions>**Condition(s):**
**Reward:**
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", @@ -98,7 +91,6 @@ } }, "lures": { - "description": "", "avatarUrl": "", "content": "<#has_lure>**Lure Expires:** ( left)
**Lure Type:**
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", @@ -112,7 +104,6 @@ } }, "invasions": { - "description": "", "avatarUrl": "", "content": "<#has_invasion>**Expires:** ( left)
**Type:** | **Gender:**

**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", @@ -126,7 +117,6 @@ } }, "nests": { - "description": "", "avatarUrl": "", "content": "**Pokemon:**
**Average Spawns:** /h | **Types:**
**[[Google]()] [[Apple]()] [[Waze]()] [[Scanner]()]**", "iconUrl": "", @@ -140,7 +130,6 @@ } }, "weather": { - "description": "", "avatarUrl": "", "content": "**Weather Condition:**
**Weather Cell ID:** #", "iconUrl": "", diff --git a/examples/templates/gyms.example.json b/examples/templates/gyms.example.json index b2435e0a..d75d285b 100644 --- a/examples/templates/gyms.example.json +++ b/examples/templates/gyms.example.json @@ -2,11 +2,11 @@ "staticmap_url": "{{tilemaps_url}}", "markers": [{ "url": "https://raw.githubusercontent.com/versx/WhMgr-Assets/master/original/gyms/gym_{{team_id}}.png", - "height": "32", - "width": "32", - "x_offset": 0, - "y_offset": 0, - "latitude": "{{lat}}", - "longitude": "{{lon}}" - }] + "height": "32", + "width": "32", + "x_offset": 0, + "y_offset": 0, + "latitude": "{{lat}}", + "longitude": "{{lon}}" + }] } \ No newline at end of file diff --git a/src/Alarms/Alerts/AlertMessageSettings.cs b/src/Alarms/Alerts/AlertMessageSettings.cs index a53e0a5c..4dea46d0 100644 --- a/src/Alarms/Alerts/AlertMessageSettings.cs +++ b/src/Alarms/Alerts/AlertMessageSettings.cs @@ -7,12 +7,6 @@ ///
public class AlertMessageSettings { - /// - /// Gets or sets the Discord message content outside of the embed message. (above it) - /// - [JsonProperty("description")] - public string Description { get; set; } - /// /// Gets or sets the Discord message content within the embed message. /// diff --git a/src/Alarms/Models/AlarmObject.cs b/src/Alarms/Models/AlarmObject.cs index 7c454ff7..4120d362 100644 --- a/src/Alarms/Models/AlarmObject.cs +++ b/src/Alarms/Models/AlarmObject.cs @@ -40,6 +40,12 @@ public class AlarmObject [JsonProperty("name")] public string Name { get; set; } + /// + /// Gets or sets the Discord message content outside of the embed message. (above it, can contain role/user mentions, DTS, etc) + /// + [JsonProperty("description")] + public string Description { get; set; } + /// /// Gets or sets the filters file to load /// @@ -64,12 +70,6 @@ public class AlarmObject [JsonProperty("webhook")] public string Webhook { get; set; } - /// - /// Gets or sets the Discord mentions string to use in the Discord message description - /// - //[JsonProperty("mentions")] - //public string Mentions { get; set; } - /// /// Instantiate a new class /// diff --git a/src/Bot.cs b/src/Bot.cs index 77b9dd32..2fa5a105 100644 --- a/src/Bot.cs +++ b/src/Bot.cs @@ -33,6 +33,9 @@ // TODO: Manage subscriptions via DM again // TODO: Multiple discord bot tokens per server // TODO: Only start database migrator if subscriptions are enabled + // TODO: Move 'description' back to alarms just include outside of embed as message description instead + // TODO: Check nests again + // TODO: Random pokemon image in static map occasionally public class Bot { diff --git a/src/Net/Models/GymDetailsData.cs b/src/Net/Models/GymDetailsData.cs index aea6fa8f..a8295666 100644 --- a/src/Net/Models/GymDetailsData.cs +++ b/src/Net/Models/GymDetailsData.cs @@ -110,7 +110,7 @@ public DiscordEmbedNotification GenerateGymMessage(ulong guildId, DiscordClient }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - var description = DynamicReplacementEngine.ReplaceText(alert.Description, properties); + var description = DynamicReplacementEngine.ReplaceText(alarm.Description, properties); return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } diff --git a/src/Net/Models/PokemonData.cs b/src/Net/Models/PokemonData.cs index 12f0986b..5d07fd39 100644 --- a/src/Net/Models/PokemonData.cs +++ b/src/Net/Models/PokemonData.cs @@ -413,7 +413,7 @@ public async Task GeneratePokemonMessage(ulong guildId }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - var description = alert.Description?.Length > 0 ? DynamicReplacementEngine.ReplaceText(alert.Description, properties) : string.Empty; + var description = DynamicReplacementEngine.ReplaceText(alarm.Description, properties); return await Task.FromResult(new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() })); } diff --git a/src/Net/Models/PokestopData.cs b/src/Net/Models/PokestopData.cs index 81d871bb..65ff062c 100644 --- a/src/Net/Models/PokestopData.cs +++ b/src/Net/Models/PokestopData.cs @@ -128,7 +128,7 @@ public DiscordEmbedNotification GeneratePokestopMessage(ulong guildId, DiscordCl }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - var description = DynamicReplacementEngine.ReplaceText(alert.Description ?? string.Empty, properties); + var description = DynamicReplacementEngine.ReplaceText(alarm.Description ?? string.Empty, properties); return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } diff --git a/src/Net/Models/QuestData.cs b/src/Net/Models/QuestData.cs index d3289aef..2c472743 100644 --- a/src/Net/Models/QuestData.cs +++ b/src/Net/Models/QuestData.cs @@ -100,7 +100,7 @@ public DiscordEmbedNotification GenerateQuestMessage(ulong guildId, DiscordClien }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - var description = DynamicReplacementEngine.ReplaceText(alert.Description ?? string.Empty, properties); + var description = DynamicReplacementEngine.ReplaceText(alarm.Description ?? string.Empty, properties); return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } diff --git a/src/Net/Models/RaidData.cs b/src/Net/Models/RaidData.cs index b44990b5..126fc30e 100644 --- a/src/Net/Models/RaidData.cs +++ b/src/Net/Models/RaidData.cs @@ -163,7 +163,7 @@ public DiscordEmbedNotification GenerateRaidMessage(ulong guildId, DiscordClient }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - var description = DynamicReplacementEngine.ReplaceText(alert.Description ?? string.Empty, properties); + var description = DynamicReplacementEngine.ReplaceText(alarm.Description ?? string.Empty, properties); return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } diff --git a/src/Net/Models/WeatherData.cs b/src/Net/Models/WeatherData.cs index 015e7e98..029abb74 100644 --- a/src/Net/Models/WeatherData.cs +++ b/src/Net/Models/WeatherData.cs @@ -131,7 +131,7 @@ public DiscordEmbedNotification GenerateWeatherMessage(ulong guildId, DiscordCli }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - var description = DynamicReplacementEngine.ReplaceText(alert.Description, properties); + var description = DynamicReplacementEngine.ReplaceText(alarm.Description, properties); return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } From e16fb5f8bf64f5f8522f9d720ca85ab531ce2e62 Mon Sep 17 00:00:00 2001 From: versx Date: Fri, 10 Jul 2020 07:36:33 -0700 Subject: [PATCH 19/19] Fix google address lookup --- src/Bot.cs | 2 -- src/Commands/Nests.cs | 2 +- src/Net/Models/GymDetailsData.cs | 4 +-- src/Net/Models/PokemonData.cs | 4 +-- src/Net/Models/PokestopData.cs | 4 +-- src/Net/Models/QuestData.cs | 4 +-- src/Net/Models/RaidData.cs | 4 +-- src/Net/Models/WeatherData.cs | 4 +-- src/Utilities/Utils.cs | 44 +++++--------------------------- 9 files changed, 20 insertions(+), 52 deletions(-) diff --git a/src/Bot.cs b/src/Bot.cs index 2fa5a105..dd0c969a 100644 --- a/src/Bot.cs +++ b/src/Bot.cs @@ -33,9 +33,7 @@ // TODO: Manage subscriptions via DM again // TODO: Multiple discord bot tokens per server // TODO: Only start database migrator if subscriptions are enabled - // TODO: Move 'description' back to alarms just include outside of embed as message description instead // TODO: Check nests again - // TODO: Random pokemon image in static map occasionally public class Bot { diff --git a/src/Commands/Nests.cs b/src/Commands/Nests.cs index b2df5150..4301cb58 100644 --- a/src/Commands/Nests.cs +++ b/src/Commands/Nests.cs @@ -140,10 +140,10 @@ public IReadOnlyDictionary GetProperties(Nest nest, string pokem var scannerMapsLink = string.Format(_dep.WhConfig.Urls.ScannerMap, nest.Latitude, nest.Longitude); var templatePath = Path.Combine(_dep.WhConfig.StaticMaps.TemplatesFolder, _dep.WhConfig.StaticMaps.NestsTemplateFile); var staticMapLink = Utils.GetStaticMapsUrl(templatePath, _dep.WhConfig.Urls.StaticMap, nest.Latitude, nest.Longitude, pkmnImage, null, _dep.OsmManager.GetNest(nest.Name)?.FirstOrDefault()); - var googleAddress = Utils.GetGoogleAddress(nest.Latitude, nest.Longitude, _dep.WhConfig.GoogleMapsKey); var geofences = _dep.Whm.Geofences.Values.ToList(); var geofence = GeofenceService.GetGeofence(geofences, new Location(nest.Latitude, nest.Longitude)); var city = geofence?.Name ?? "Unknown"; + var googleAddress = Utils.GetGoogleAddress(city, nest.Latitude, nest.Longitude, _dep.WhConfig.GoogleMapsKey); var dict = new Dictionary { diff --git a/src/Net/Models/GymDetailsData.cs b/src/Net/Models/GymDetailsData.cs index a8295666..0e000b43 100644 --- a/src/Net/Models/GymDetailsData.cs +++ b/src/Net/Models/GymDetailsData.cs @@ -110,7 +110,7 @@ public DiscordEmbedNotification GenerateGymMessage(ulong guildId, DiscordClient }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - var description = DynamicReplacementEngine.ReplaceText(alarm.Description, properties); + var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties); return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } @@ -134,7 +134,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); - var googleAddress = Utils.GetGoogleAddress(Latitude, Longitude, whConfig.GoogleMapsKey); + var googleAddress = Utils.GetGoogleAddress(city, Latitude, Longitude, whConfig.GoogleMapsKey); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); const string defaultMissingValue = "?"; diff --git a/src/Net/Models/PokemonData.cs b/src/Net/Models/PokemonData.cs index 5d07fd39..5d36a892 100644 --- a/src/Net/Models/PokemonData.cs +++ b/src/Net/Models/PokemonData.cs @@ -413,7 +413,7 @@ public async Task GeneratePokemonMessage(ulong guildId }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - var description = DynamicReplacementEngine.ReplaceText(alarm.Description, properties); + var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties); return await Task.FromResult(new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() })); } @@ -463,7 +463,7 @@ private async Task> GetProperties(DiscordGui var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); - var googleAddress = Utils.GetGoogleAddress(Latitude, Longitude, whConfig.GoogleMapsKey); + var googleAddress = Utils.GetGoogleAddress(city, Latitude, Longitude, whConfig.GoogleMapsKey); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); var pokestop = Pokestop.Pokestops.ContainsKey(PokestopId) ? Pokestop.Pokestops[PokestopId] : null; diff --git a/src/Net/Models/PokestopData.cs b/src/Net/Models/PokestopData.cs index 65ff062c..d6324c70 100644 --- a/src/Net/Models/PokestopData.cs +++ b/src/Net/Models/PokestopData.cs @@ -128,7 +128,7 @@ public DiscordEmbedNotification GeneratePokestopMessage(ulong guildId, DiscordCl }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - var description = DynamicReplacementEngine.ReplaceText(alarm.Description ?? string.Empty, properties); + var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties); return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } @@ -151,7 +151,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); - var googleAddress = Utils.GetGoogleAddress(Latitude, Longitude, whConfig.GoogleMapsKey); + var googleAddress = Utils.GetGoogleAddress(city, Latitude, Longitude, whConfig.GoogleMapsKey); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); var invasion = MasterFile.Instance.GruntTypes.ContainsKey(GruntType) ? MasterFile.Instance.GruntTypes[GruntType] : null; var leaderString = Translator.Instance.Translate("grunt_" + Convert.ToInt32(GruntType)); diff --git a/src/Net/Models/QuestData.cs b/src/Net/Models/QuestData.cs index 2c472743..e8b97525 100644 --- a/src/Net/Models/QuestData.cs +++ b/src/Net/Models/QuestData.cs @@ -100,7 +100,7 @@ public DiscordEmbedNotification GenerateQuestMessage(ulong guildId, DiscordClien }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - var description = DynamicReplacementEngine.ReplaceText(alarm.Description ?? string.Empty, properties); + var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties); return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } @@ -119,7 +119,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); - var googleAddress = Utils.GetGoogleAddress(Latitude, Longitude, whConfig.GoogleMapsKey); + var googleAddress = Utils.GetGoogleAddress(city, Latitude, Longitude, whConfig.GoogleMapsKey); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); const string defaultMissingValue = "?"; diff --git a/src/Net/Models/RaidData.cs b/src/Net/Models/RaidData.cs index 126fc30e..7fb515b0 100644 --- a/src/Net/Models/RaidData.cs +++ b/src/Net/Models/RaidData.cs @@ -163,7 +163,7 @@ public DiscordEmbedNotification GenerateRaidMessage(ulong guildId, DiscordClient }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - var description = DynamicReplacementEngine.ReplaceText(alarm.Description ?? string.Empty, properties); + var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties); return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } @@ -202,7 +202,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); - var googleAddress = Utils.GetGoogleAddress(Latitude, Longitude, whConfig.GoogleMapsKey); + var googleAddress = Utils.GetGoogleAddress(city, Latitude, Longitude, whConfig.GoogleMapsKey); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); const string defaultMissingValue = "?"; diff --git a/src/Net/Models/WeatherData.cs b/src/Net/Models/WeatherData.cs index 029abb74..2b0cf94c 100644 --- a/src/Net/Models/WeatherData.cs +++ b/src/Net/Models/WeatherData.cs @@ -131,7 +131,7 @@ public DiscordEmbedNotification GenerateWeatherMessage(ulong guildId, DiscordCli }; var username = DynamicReplacementEngine.ReplaceText(alert.Username, properties); var iconUrl = DynamicReplacementEngine.ReplaceText(alert.AvatarUrl, properties); - var description = DynamicReplacementEngine.ReplaceText(alarm.Description, properties); + var description = DynamicReplacementEngine.ReplaceText(alarm?.Description, properties); return new DiscordEmbedNotification(username, iconUrl, description, new List { eb.Build() }); } @@ -151,7 +151,7 @@ private IReadOnlyDictionary GetProperties(DiscordGuild guild, Wh var appleMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? appleMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, appleMapsLink); var wazeMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? wazeMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, wazeMapsLink); var scannerMapsLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? scannerMapsLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, scannerMapsLink); - var googleAddress = Utils.GetGoogleAddress(Latitude, Longitude, whConfig.GoogleMapsKey); + var googleAddress = Utils.GetGoogleAddress(city, Latitude, Longitude, whConfig.GoogleMapsKey); //var staticMapLocationLink = string.IsNullOrEmpty(whConfig.ShortUrlApiUrl) ? staticMapLink : NetUtil.CreateShortUrl(whConfig.ShortUrlApiUrl, staticMapLink); const string defaultMissingValue = "?"; diff --git a/src/Utilities/Utils.cs b/src/Utilities/Utils.cs index 8960e44d..e5b39055 100644 --- a/src/Utilities/Utils.cs +++ b/src/Utilities/Utils.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.IO; + using System.Linq; using System.Net; using System.Text; @@ -79,7 +80,7 @@ public static bool SendSmsMessage(string body, TwilioConfig config, string toPho return message.ErrorCode == null; } - public static Location GetGoogleAddress(double lat, double lng, string gmapsKey) + public static Location GetGoogleAddress(string city, double lat, double lng, string gmapsKey) { var apiKey = string.IsNullOrEmpty(gmapsKey) ? string.Empty : $"&key={gmapsKey}"; var url = $"https://maps.googleapis.com/maps/api/geocode/json?latlng={lat},{lng}&sensor=true{apiKey}"; @@ -94,50 +95,19 @@ public static Location GetGoogleAddress(double lat, double lng, string gmapsKey) var data = reader.ReadToEnd(); var parseJson = JObject.Parse(data); var status = Convert.ToString(parseJson["status"]); - if (string.Compare(status, "OK", true) == 0) + if (string.Compare(status, "OK", true) != 0) return null; - var jsonres = parseJson["results"][0]; - var address = Convert.ToString(jsonres["formatted_address"]); - var addrComponents = jsonres["address_components"]; - var city = unknown; - var items = JsonConvert.DeserializeObject>>(addrComponents.ToString()); - foreach (var item in items) - { - foreach (var key in item) - { - if (string.Compare(key.Key, "types", true) != 0) - continue; - - if (!(key.Value is JArray types)) - continue; - - foreach (var type in types) - { - var t = type.ToString(); - if (string.Compare(t, "locality", true) != 0) - continue; - - city = Convert.ToString(item["short_name"]); - break; - } - - if (city != unknown) - break; - } - - if (city != unknown) - break; - } - - return new Location(address, city, lat, lng); + var result = parseJson["results"].FirstOrDefault(); + var address = Convert.ToString(result["formatted_address"]); + //var area = Convert.ToString(result["address_components"][2]["long_name"]); + return new Location(address, city ?? unknown, lat, lng); } } catch (Exception ex) { _logger.Error(ex); } - return null; } }