From 944ef36b4cfc34255b5d3ca66aeabd00697fa3ed Mon Sep 17 00:00:00 2001 From: versx Date: Sun, 15 Nov 2020 11:05:14 -0800 Subject: [PATCH] Add customizable minimum IV for event Pokemon (#66) --- README.md | 2 ++ config.example.json | 1 + src/Configuration/WhConfig.cs | 8 ++++++++ src/Net/HttpServer.cs | 5 +++++ src/Net/Webhooks/WebhookController.cs | 2 +- 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 36c859f7..e39445e1 100644 --- a/README.md +++ b/README.md @@ -217,6 +217,8 @@ bitsadmin /transfer dotnet-install-job /download /priority FOREGROUND https://ra 456, 320 ], + // Minimum IV value for an event Pokemon to have to meet in order to post via Discord channel alarm or direct message subscription. + "eventMinimumIV": "90", // Image URL config "urls": { // Static tile map images template. diff --git a/config.example.json b/config.example.json index 8a95d381..2620c0af 100644 --- a/config.example.json +++ b/config.example.json @@ -92,6 +92,7 @@ 456, 320 ], + "eventMinimumIV": "90", "urls": { "staticMap": "http://tiles.example.com:8080/static/klokantech-basic/{0}/{1}/{2}/300/175/1/png", "scannerMap": "http://map.example.com/@/{0}/{1}/15" diff --git a/src/Configuration/WhConfig.cs b/src/Configuration/WhConfig.cs index d3ea09fa..15c74904 100644 --- a/src/Configuration/WhConfig.cs +++ b/src/Configuration/WhConfig.cs @@ -68,6 +68,13 @@ public class WhConfig [JsonProperty("eventPokemonIds")] public List EventPokemonIds { get; set; } + /// + /// Gets or sets the minimum IV value for an event Pokemon to be to process + /// for channel alarms or direct message subscriptions + /// + [JsonProperty("eventMinimumIV")] + public int EventMinimumIV { get; set; } + /// /// Gets or sets the icon styles /// @@ -141,6 +148,7 @@ public WhConfig() Database = new ConnectionStringsConfig(); Urls = new UrlConfig(); EventPokemonIds = new List(); + EventMinimumIV = 90; IconStyles = new Dictionary(); StaticMaps = new StaticMaps(); Twilio = new TwilioConfig(); diff --git a/src/Net/HttpServer.cs b/src/Net/HttpServer.cs index df764db9..36ff9fc6 100644 --- a/src/Net/HttpServer.cs +++ b/src/Net/HttpServer.cs @@ -219,10 +219,12 @@ private void RequestHandler() if (context.Request?.InputStream == null) continue; + // Read from the POST data input stream of the request using (var sr = new StreamReader(context.Request.InputStream)) { try { + // Read to the end of the stream as a string var data = sr.ReadToEnd(); ParseData(data); } @@ -237,12 +239,15 @@ private void RequestHandler() try { + // Convert the default response message to UTF8 encoded bytes var buffer = Encoding.UTF8.GetBytes(Strings.DefaultResponseMessage); response.ContentLength64 = buffer.Length; if (response?.OutputStream != null) { + // Write the response buffer to the output stream response.OutputStream.Write(buffer, 0, buffer.Length); } + // Close the response context.Response.Close(); } catch (Exception ex) diff --git a/src/Net/Webhooks/WebhookController.cs b/src/Net/Webhooks/WebhookController.cs index 53677a36..1cc4985f 100644 --- a/src/Net/Webhooks/WebhookController.cs +++ b/src/Net/Webhooks/WebhookController.cs @@ -253,7 +253,7 @@ private void Http_PokemonReceived(object sender, DataReceivedEventArgs 0 && iv < 90 && !pkmn.MatchesGreatLeague && !pkmn.MatchesUltraLeague) + if (iv > 0 && iv < _config.EventMinimumIV && !pkmn.MatchesGreatLeague && !pkmn.MatchesUltraLeague) return; }