diff --git a/alarms.example.json b/alarms.example.json index 96e46bdf..29c8f14d 100644 --- a/alarms.example.json +++ b/alarms.example.json @@ -8,173 +8,173 @@ "alarms": [ { - "name":"City1-Rare", + "name": "City1-Rare", "description": " L ", "alerts": "default.json", - "filters":"all.json", - "geofence":"City1.txt", - "mentions":" L ", - "webhook":"" + "filters": "all.json", + "geofences":["City1.txt", "City2.txt"], + "mentions": " L ", + "webhook": "" }, { - "name":"City1-100iv", + "name": "City1-100iv", "description": "", "alerts": "default.json", - "filters":"100iv.json", - "geofence":"City1.txt", - "webhook":"" + "filters": "100iv.json", + "geofences":["City1.txt", "City2.txt"], + "webhook": "" }, { - "name":"City1-Raids", + "name": "City1-Raids", "description": "", "alerts": "default.json", - "filters":"raids.json", - "geofence":"City1.txt", - "webhook":"" + "filters": "raids.json", + "geofences":["City1.txt", "City2.txt"], + "webhook": "" }, { - "name":"City1-LegendaryRaids", + "name": "City1-LegendaryRaids", "description": "", "alerts": "default.json", - "filters":"legendary_raids.json", - "geofence":"City1.txt", - "webhook":"" + "filters": "legendary_raids.json", + "geofences":["City1.txt", "City2.txt"], + "webhook": "" }, { - "name":"City1-ExRaids", + "name": "City1-ExRaids", "description": "", "alerts": "default.json", - "filters":"ex_raids.json", - "geofence":"City1.txt", - "webhook":"" + "filters": "ex_raids.json", + "geofences":["City1.txt", "City2.txt"], + "webhook": "" }, { "name": "City1-Quests", "description": "", "alerts": "default.json", "filters": "quests.json", - "geofence": "City1.txt", - "webhook":"" + "geofences":["City1.txt", "City2.txt"], + "webhook": "" }, { "name": "City1-Lures", "description": "", "alerts": "default.json", "filters": "lures.json", - "geofence": "City1.txt", - "webhook":"" + "geofences":["City1.txt", "City2.txt"], + "webhook": "" }, { "name": "City1-Invasions", "description": "", "alerts": "default.json", "filters": "invasions.json", - "geofence": "City1.txt", - "webhook":"" + "geofences":["City1.txt", "City2.txt"], + "webhook": "" }, { "name": "City1-Gyms", "description": "", "alerts": "default.json", "filters": "gyms.json", - "geofence": "City1.txt", - "webhook":"" + "geofences":["City1.txt", "City2.txt"], + "webhook": "" }, { - "name":"City1-Weather", + "name": "City1-Weather", "description": "", "alerts": "default.json", - "filters":"weather.json", - "geofence":"City1.txt", - "webhook":"" + "filters": "weather.json", + "geofences":["City1.txt", "City2.txt"], + "webhook": "" }, { - "name":"City2-Rare", + "name": "City2-Rare", "description": "", "alerts": "default.json", - "filters":"all.json", - "geofence":"City2.txt", - "webhook":"" + "filters": "all.json", + "geofences": ["City2.txt"], + "webhook": "" }, { - "name":"City2-100iv", + "name": "City2-100iv", "description": "", "alerts": "default.json", - "filters":"100iv.json", - "geofence":"City2.txt", - "webhook":"" + "filters": "100iv.json", + "geofences": ["City2.txt"], + "webhook": "" }, { - "name":"City2-Raids", + "name": "City2-Raids", "description": "", "alerts": "default.json", - "filters":"raids.json", - "geofence":"City2.txt", - "webhook":"" + "filters": "raids.json", + "geofences": ["City2.txt"], + "webhook": "" }, { - "name":"City2-LegendaryRaids", + "name": "City2-LegendaryRaids", "description": "", "alerts": "default.json", - "filters":"legendary_raids.json", - "geofence":"City2.txt", - "webhook":"" + "filters": "legendary_raids.json", + "geofences": ["City2.txt"], + "webhook": "" }, { - "name":"City2-ExRaids", + "name": "City2-ExRaids", "description": "", "alerts": "default.json", - "filters":"ex_raids.json", - "geofence":"City2.txt", - "webhook":"" + "filters": "ex_raids.json", + "geofences": ["City2.txt"], + "webhook": "" }, { "name": "City2-Quests", "description": "", "alerts": "default.json", "filters": "quests.json", - "geofence": "City2.txt", - "webhook":"" + "geofences": ["City2.txt"], + "webhook": "" }, { "name": "City2-Lures", "description": "", "alerts": "default.json", "filters": "lures.json", - "geofence": "City2.txt", - "webhook":"" + "geofences": ["City2.txt"], + "webhook": "" }, { "name": "City2-Invasions", "description": "", "alerts": "default.json", "filters": "invasions.json", - "geofence": "City2.txt", - "webhook":"" + "geofences": ["City2.txt"], + "webhook": "" }, { "name": "City2-Gyms", "description": "", "alerts": "default.json", "filters": "gyms.json", - "geofence": "City2.txt", - "webhook":"" + "geofences": ["City2.txt"], + "webhook": "" }, { - "name":"Absol-Quests", + "name": "Absol-Quests", "description": "", "alerts": "default.json", - "filters":"quests_absol.json", - "geofence":"City2.txt", - "webhook":"" + "filters": "quests_absol.json", + "geofences": ["City2.txt"], + "webhook": "" }, { - "name":"City2-Weather", + "name": "City2-Weather", "description": "", "alerts": "default.json", - "filters":"weather.json", - "geofence":"City2.txt", - "webhook":"" + "filters": "weather.json", + "geofences": ["City2.txt"], + "webhook": "" } ] } \ No newline at end of file diff --git a/src/Alarms/Models/AlarmObject.cs b/src/Alarms/Models/AlarmObject.cs index 4120d362..b19b6406 100644 --- a/src/Alarms/Models/AlarmObject.cs +++ b/src/Alarms/Models/AlarmObject.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.IO; + using System.Linq; using Newtonsoft.Json; @@ -61,8 +62,8 @@ public class AlarmObject /// /// Gets or sets the geofences file to load /// - [JsonProperty("geofence")] - public string GeofenceFile { get; set; } + [JsonProperty("geofences")] + public List GeofenceFiles { get; set; } /// /// Gets or sets the Discord channel webhook url address @@ -75,6 +76,7 @@ public class AlarmObject /// public AlarmObject() { + GeofenceFiles = new List(); LoadGeofence(); LoadAlerts(); LoadFilters(); @@ -86,14 +88,23 @@ public AlarmObject() /// Returns parsed geofence list public List 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(); + 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; } ///