Skip to content

Commit

Permalink
Multiple Cities Per Alarm (#65)
Browse files Browse the repository at this point in the history
* Allow subscribing and unsubscribing of multiple cities at once.

* Allow multiple geofence files per alarm

* Fix example alarms
  • Loading branch information
versx committed Nov 28, 2020
1 parent a865b19 commit 7b670ba
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 79 deletions.
138 changes: 69 additions & 69 deletions alarms.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,173 +8,173 @@
"alarms":
[
{
"name":"City1-Rare",
"name": "City1-Rare",
"description": "<!@324234324> <iv> L<lvl> <geofence>",
"alerts": "default.json",
"filters":"all.json",
"geofence":"City1.txt",
"mentions":"<!@324234324> <iv> L<lvl> <geofence>",
"webhook":"<DISCORD_WEBHOOK_URL>"
"filters": "all.json",
"geofences":["City1.txt", "City2.txt"],
"mentions": "<!@324234324> <iv> L<lvl> <geofence>",
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name":"City1-100iv",
"name": "City1-100iv",
"description": "",
"alerts": "default.json",
"filters":"100iv.json",
"geofence":"City1.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"filters": "100iv.json",
"geofences":["City1.txt", "City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name":"City1-Raids",
"name": "City1-Raids",
"description": "",
"alerts": "default.json",
"filters":"raids.json",
"geofence":"City1.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"filters": "raids.json",
"geofences":["City1.txt", "City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name":"City1-LegendaryRaids",
"name": "City1-LegendaryRaids",
"description": "",
"alerts": "default.json",
"filters":"legendary_raids.json",
"geofence":"City1.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"filters": "legendary_raids.json",
"geofences":["City1.txt", "City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name":"City1-ExRaids",
"name": "City1-ExRaids",
"description": "",
"alerts": "default.json",
"filters":"ex_raids.json",
"geofence":"City1.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"filters": "ex_raids.json",
"geofences":["City1.txt", "City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name": "City1-Quests",
"description": "",
"alerts": "default.json",
"filters": "quests.json",
"geofence": "City1.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"geofences":["City1.txt", "City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name": "City1-Lures",
"description": "",
"alerts": "default.json",
"filters": "lures.json",
"geofence": "City1.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"geofences":["City1.txt", "City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name": "City1-Invasions",
"description": "",
"alerts": "default.json",
"filters": "invasions.json",
"geofence": "City1.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"geofences":["City1.txt", "City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name": "City1-Gyms",
"description": "",
"alerts": "default.json",
"filters": "gyms.json",
"geofence": "City1.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"geofences":["City1.txt", "City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name":"City1-Weather",
"name": "City1-Weather",
"description": "",
"alerts": "default.json",
"filters":"weather.json",
"geofence":"City1.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"filters": "weather.json",
"geofences":["City1.txt", "City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name":"City2-Rare",
"name": "City2-Rare",
"description": "",
"alerts": "default.json",
"filters":"all.json",
"geofence":"City2.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"filters": "all.json",
"geofences": ["City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name":"City2-100iv",
"name": "City2-100iv",
"description": "",
"alerts": "default.json",
"filters":"100iv.json",
"geofence":"City2.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"filters": "100iv.json",
"geofences": ["City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name":"City2-Raids",
"name": "City2-Raids",
"description": "",
"alerts": "default.json",
"filters":"raids.json",
"geofence":"City2.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"filters": "raids.json",
"geofences": ["City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name":"City2-LegendaryRaids",
"name": "City2-LegendaryRaids",
"description": "",
"alerts": "default.json",
"filters":"legendary_raids.json",
"geofence":"City2.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"filters": "legendary_raids.json",
"geofences": ["City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name":"City2-ExRaids",
"name": "City2-ExRaids",
"description": "",
"alerts": "default.json",
"filters":"ex_raids.json",
"geofence":"City2.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"filters": "ex_raids.json",
"geofences": ["City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name": "City2-Quests",
"description": "",
"alerts": "default.json",
"filters": "quests.json",
"geofence": "City2.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"geofences": ["City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name": "City2-Lures",
"description": "",
"alerts": "default.json",
"filters": "lures.json",
"geofence": "City2.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"geofences": ["City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name": "City2-Invasions",
"description": "",
"alerts": "default.json",
"filters": "invasions.json",
"geofence": "City2.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"geofences": ["City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name": "City2-Gyms",
"description": "",
"alerts": "default.json",
"filters": "gyms.json",
"geofence": "City2.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"geofences": ["City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name":"Absol-Quests",
"name": "Absol-Quests",
"description": "",
"alerts": "default.json",
"filters":"quests_absol.json",
"geofence":"City2.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"filters": "quests_absol.json",
"geofences": ["City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
},
{
"name":"City2-Weather",
"name": "City2-Weather",
"description": "",
"alerts": "default.json",
"filters":"weather.json",
"geofence":"City2.txt",
"webhook":"<DISCORD_WEBHOOK_URL>"
"filters": "weather.json",
"geofences": ["City2.txt"],
"webhook": "<DISCORD_WEBHOOK_URL>"
}
]
}
31 changes: 21 additions & 10 deletions src/Alarms/Models/AlarmObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using Newtonsoft.Json;

Expand Down Expand Up @@ -61,8 +62,8 @@ public class AlarmObject
/// <summary>
/// Gets or sets the geofences file to load
/// </summary>
[JsonProperty("geofence")]
public string GeofenceFile { get; set; }
[JsonProperty("geofences")]
public List<string> GeofenceFiles { get; set; }

/// <summary>
/// Gets or sets the Discord channel webhook url address
Expand All @@ -75,6 +76,7 @@ public class AlarmObject
/// </summary>
public AlarmObject()
{
GeofenceFiles = new List<string>();
LoadGeofence();
LoadAlerts();
LoadFilters();
Expand All @@ -86,14 +88,23 @@ public AlarmObject()
/// <returns>Returns parsed geofence list</returns>
public List<GeofenceItem> LoadGeofence()
{
if (string.IsNullOrEmpty(GeofenceFile))
return null;

var path = Path.Combine(Strings.GeofenceFolder, GeofenceFile);
if (!File.Exists(path))
throw new FileNotFoundException($"Geofence file {path} not found.", path);

return Geofences = GeofenceItem.FromFile(path);
var geofences = new List<GeofenceItem>();
if (GeofenceFiles.Count == 0)
return geofences;

foreach (var geofenceFile in GeofenceFiles)
{
var path = Path.Combine(Strings.GeofenceFolder, geofenceFile);
if (!File.Exists(path))
{
throw new FileNotFoundException($"Geofence file {path} not found.", path);
}

// Only return the first geofence
var geofence = GeofenceItem.FromFile(path).FirstOrDefault();
geofences.Add(geofence);
}
return Geofences = geofences;
}

/// <summary>
Expand Down

0 comments on commit 7b670ba

Please sign in to comment.