-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configurable StaticMaps Toggle (#290)
* - Add static map toggle to config. - Add reusable location links generator. - Update internal default embeds example. - Let user know if emoji does not exist. - Fix locales directory path. * Update docs
- Loading branch information
Showing
24 changed files
with
352 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
namespace WhMgr.Extensions | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
using WhMgr.Common; | ||
using WhMgr.Configuration; | ||
using WhMgr.Services.Cache; | ||
using WhMgr.Services.StaticMap; | ||
using WhMgr.Services.Webhook.Models; | ||
|
||
public static class StaticMapExtensions | ||
{ | ||
public static string GenerateStaticMap(this StaticMapConfig config, StaticMapType mapType, IWebhookPoint coord, string imageUrl, IMapDataCache cache = null, PokemonTeam? team = null, string polygonPath = null) | ||
{ | ||
var url = GenerateStaticMapAsync(config, mapType, coord, imageUrl, cache, team, polygonPath).Result; | ||
return url; | ||
} | ||
|
||
public static async Task<string> GenerateStaticMapAsync(this StaticMapConfig config, StaticMapType mapType, IWebhookPoint coord, string imageUrl, IMapDataCache cache = null, PokemonTeam? team = null, string polygonPath = null) | ||
{ | ||
if (!(config?.Enabled ?? false)) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
if (string.IsNullOrEmpty(config.Url)) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
var staticMap = new StaticMapGenerator(new StaticMapOptions | ||
{ | ||
BaseUrl = config.Url, | ||
MapType = mapType, | ||
TemplateType = config.Type, | ||
Latitude = coord.Latitude, | ||
Longitude = coord.Longitude, | ||
SecondaryImageUrl = imageUrl, | ||
Gyms = config.IncludeNearbyGyms && cache != null | ||
// Fetch nearby gyms from MapDataCache | ||
? await cache?.GetGymsNearby(coord.Latitude, coord.Longitude) | ||
: new(), | ||
Pokestops = config.IncludeNearbyPokestops && cache != null | ||
// Fetch nearby pokestops from MapDataCache | ||
? await cache?.GetPokestopsNearby(coord.Latitude, coord.Longitude) | ||
: new(), | ||
Team = team, | ||
PolygonPath = polygonPath, | ||
Pregenerate = config.Pregenerate, | ||
Regeneratable = true, | ||
}); | ||
|
||
var url = staticMap.GenerateLink(); | ||
return url ?? string.Empty; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
namespace WhMgr.Services.Webhook.Models | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
using DSharpPlus.Entities; | ||
|
||
using WhMgr.Configuration; | ||
using WhMgr.Extensions; | ||
using WhMgr.Services.Geofence; | ||
using WhMgr.Services.Geofence.Geocoding; | ||
using WhMgr.Services.Yourls; | ||
|
||
public class GenericEmbedProperties | ||
{ | ||
public string GoogleMapsLocationLink { get; set; } | ||
|
||
public string AppleMapsLocationLink { get; set; } | ||
|
||
public string WazeMapsLocationLink { get; set; } | ||
|
||
public string ScannerMapsLocationLink { get; set; } | ||
|
||
public string Address { get; set; } | ||
|
||
public DiscordGuild Guild { get; set; } | ||
|
||
public DateTime Now { get; set; } | ||
|
||
|
||
public static GenericEmbedProperties Generate(Config config, IReadOnlyDictionary<ulong, DiscordGuild> guilds, ulong guildId, IWebhookPoint coord) | ||
{ | ||
var data = GenerateAsync(config, guilds, guildId, coord).Result; | ||
return data; | ||
} | ||
|
||
public static async Task<GenericEmbedProperties> GenerateAsync(Config config, IReadOnlyDictionary<ulong, DiscordGuild> guilds, ulong guildId, IWebhookPoint coord) | ||
{ | ||
var gmapsLink = string.Format(Strings.Defaults.GoogleMaps, coord.Latitude, coord.Longitude); | ||
var appleMapsLink = string.Format(Strings.Defaults.AppleMaps, coord.Latitude, coord.Longitude); | ||
var wazeMapsLink = string.Format(Strings.Defaults.WazeMaps, coord.Latitude, coord.Longitude); | ||
var scannerMapsLink = string.Format(config.Urls.ScannerMap, coord.Latitude, coord.Longitude); | ||
|
||
var urlShortener = new UrlShortener(config.ShortUrlApi); | ||
var gmapsLocationLink = await urlShortener.CreateAsync(gmapsLink); | ||
var appleMapsLocationLink = await urlShortener.CreateAsync(appleMapsLink); | ||
var wazeMapsLocationLink = await urlShortener.CreateAsync(wazeMapsLink); | ||
var scannerMapsLocationLink = await urlShortener.CreateAsync(scannerMapsLink); | ||
var address = await ReverseGeocodingLookup.Instance.GetAddressAsync(new Coordinate(coord)); | ||
|
||
var now = DateTime.UtcNow.ConvertTimeFromCoordinates(coord); | ||
var guild = guilds?.ContainsKey(guildId) ?? false | ||
? guilds[guildId] | ||
: null; | ||
|
||
return new GenericEmbedProperties | ||
{ | ||
GoogleMapsLocationLink = gmapsLocationLink, | ||
AppleMapsLocationLink = appleMapsLocationLink, | ||
WazeMapsLocationLink = wazeMapsLocationLink, | ||
ScannerMapsLocationLink = scannerMapsLocationLink, | ||
Address = address ?? string.Empty, | ||
Guild = guild, | ||
Now = now, | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.