Skip to content

Commit

Permalink
Add customizable minimum IV for event Pokemon (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
versx committed Nov 15, 2020
1 parent 83cb320 commit 944ef36
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions src/Configuration/WhConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public class WhConfig
[JsonProperty("eventPokemonIds")]
public List<int> EventPokemonIds { get; set; }

/// <summary>
/// Gets or sets the minimum IV value for an event Pokemon to be to process
/// for channel alarms or direct message subscriptions
/// </summary>
[JsonProperty("eventMinimumIV")]
public int EventMinimumIV { get; set; }

/// <summary>
/// Gets or sets the icon styles
/// </summary>
Expand Down Expand Up @@ -141,6 +148,7 @@ public WhConfig()
Database = new ConnectionStringsConfig();
Urls = new UrlConfig();
EventPokemonIds = new List<int>();
EventMinimumIV = 90;
IconStyles = new Dictionary<string, string>();
StaticMaps = new StaticMaps();
Twilio = new TwilioConfig();
Expand Down
5 changes: 5 additions & 0 deletions src/Net/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Net/Webhooks/WebhookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private void Http_PokemonReceived(object sender, DataReceivedEventArgs<PokemonDa

var iv = PokemonData.GetIV(pkmn.Attack, pkmn.Defense, pkmn.Stamina);
// Skip Pokemon if IV is greater than 0%, less than 90%, and does not match any PvP league stats.
if (iv > 0 && iv < 90 && !pkmn.MatchesGreatLeague && !pkmn.MatchesUltraLeague)
if (iv > 0 && iv < _config.EventMinimumIV && !pkmn.MatchesGreatLeague && !pkmn.MatchesUltraLeague)
return;
}

Expand Down

0 comments on commit 944ef36

Please sign in to comment.