diff --git a/.gitignore b/.gitignore index 3c4efe2..f135625 100644 --- a/.gitignore +++ b/.gitignore @@ -258,4 +258,5 @@ paket-files/ # Python Tools for Visual Studio (PTVS) __pycache__/ -*.pyc \ No newline at end of file +*.pyc +/SysEx.Net/Properties/PublishProfiles/FolderProfile.pubxml diff --git a/SysEx.Net/Client.cs b/SysEx.Net/Client.cs index f6f8821..f8c22ca 100644 --- a/SysEx.Net/Client.cs +++ b/SysEx.Net/Client.cs @@ -12,6 +12,8 @@ namespace SysEx.Net public class SysExClient { readonly Random random; + readonly Uri APIBase = new Uri("https://api.exsersewo.dev"); + readonly Uri KitsuBase = new Uri("https://kitsu.exsersewo.dev"); public SysExClient() { @@ -22,43 +24,43 @@ namespace SysEx.Net /// Gets a Llama image /// public async Task GetLlamaAsync() => - await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/llama.json")); + await GetAnimalAsync(new Uri(APIBase, "/v1/llama.json")); /// /// Gets a Seal image /// public async Task GetSealAsync() => - await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/seal.json")); + await GetAnimalAsync(new Uri(APIBase, "/v1/seal.json")); /// /// Gets a Duck image /// public async Task GetDuckAsync() => - await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/duck.json")); + await GetAnimalAsync(new Uri(APIBase, "/v1/duck.json")); /// /// Gets a Squirrel image /// public async Task GetSquirrelAsync() => - await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/squirrel.json")); + await GetAnimalAsync(new Uri(APIBase, "/v1/squirrel.json")); /// /// Gets a Lizard image /// public async Task GetLizardAsync() => - await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/lizard.json")); + await GetAnimalAsync(new Uri(APIBase, "/v1/lizard.json")); /// /// Gets a morphed animal image /// public async Task GetMorphAsync() => - await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/morphs.json")); + await GetAnimalAsync(new Uri(APIBase, "/v1/morphs.json")); /// /// Gets a Snake image /// public async Task GetSnakeAsync() => - await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/snake.json")); + await GetAnimalAsync(new Uri(APIBase, "/v1/snake.json")); async Task GetAnimalAsync(Uri url) { @@ -74,7 +76,7 @@ namespace SysEx.Net /// public async Task GetRoastAsync() { - var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/v1/roasts.json")); + var resp = await WebRequest.ReturnStringAsync(new Uri(APIBase, "/v1/roasts.json")); var items = JsonConvert.DeserializeObject>(resp); if (items == null) return null; return items[random.Next(0, items.Count)].Roast; @@ -85,7 +87,7 @@ namespace SysEx.Net /// public async Task GetDadJokeAsync() { - var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/v1/dadjokes.json")); + var resp = await WebRequest.ReturnStringAsync(new Uri(APIBase, "/v1/dadjokes.json")); var items = JsonConvert.DeserializeObject>(resp); if (items == null) return null; return items[random.Next(0, items.Count)]; @@ -96,33 +98,13 @@ namespace SysEx.Net /// public async Task GetPickupLineAsync() { - var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/v1/pickuplines.json")); + var resp = await WebRequest.ReturnStringAsync(new Uri(APIBase, "/v1/pickuplines.json")); var items = JsonConvert.DeserializeObject>(resp); if (items == null) return null; return items[random.Next(0, items.Count)]; } - /// - /// Gets A Weeb Action Gif - /// - /// Gif Action Type - /// Url of image - public async Task GetWeebActionGifAsync(GifType type) - { - var resp = await WebRequest.GetRedirectUriAsync(new Uri("https://api.systemexit.co.uk/actions/?action=" + type.ToString().ToLowerInvariant())); - return resp.OriginalString; - } - - /// - /// Gets A Weeb Reaction Gif - /// - /// Url of image - public async Task GetWeebReactionGifAsync() - { - var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/reactions/")); - return resp; - } - + private Uri MemeAPIBase = new Uri("https://api.skuldbot.uk/meme/"); /// /// Gets a meme image based on given input /// @@ -131,40 +113,38 @@ namespace SysEx.Net /// Either Object. MemeResponse on empty input or failure, or MemoryStream on success public async Task GetMemeImageAsync(string template = null, params string[] images) { - var endpoints = JsonConvert.DeserializeObject(await WebRequest.ReturnStringAsync(new Uri("https://api.skuldbot.uk/fun/meme/?endpoints"))); if (template == null && (images.Length <= 0 || images == null)) { - return endpoints; + return JsonConvert.DeserializeObject(await WebRequest.ReturnStringAsync(MemeAPIBase)); } - if(endpoints.Endpoints.Exists(x=>x.Name.ToLowerInvariant() == template.ToLowerInvariant())) + + string queryString = ""; + int x = 1; + foreach(var image in images) { - var endpoint = endpoints.Endpoints.FirstOrDefault(z => z.Name.ToLowerInvariant() == template.ToLowerInvariant()); - string queryString = ""; - int x = 1; - foreach(var image in images) + if(image == images.Last()) { - if(image == images.Last()) - { - queryString += $"source{x}={image}"; - } - else - { - queryString += $"source{x}={image}&"; - } - x++; + queryString += $"source{x}={image}"; } - - var resp = await WebRequest.GetStreamAsync(new Uri($"https://api.skuldbot.uk/fun/meme/{template}/?{queryString}")); - if(resp != null) + else { - return resp; + queryString += $"source{x}={image}&"; } + x++; + } + + var templateURL = new Uri(MemeAPIBase, $"template/{template}/?{queryString}"); + + var resp = await WebRequest.GetStreamAsync(templateURL); + if(resp != null) + { + return resp; } - return new MemeResponse + else { - Successful = false, - Endpoints = endpoints.Endpoints - }; + dynamic reason = JsonConvert.DeserializeObject(await WebRequest.ReturnStringAsync(templateURL)); + throw new Exception(reason["reason"]); + } } /// @@ -172,7 +152,7 @@ namespace SysEx.Net /// public async Task GetLewdKitsuneAsync() { - var rawresp = await WebRequest.ReturnStringAsync(new Uri("https://kitsu.systemexit.co.uk/lewd")); + var rawresp = await WebRequest.ReturnStringAsync(new Uri(KitsuBase, "/lewd")); dynamic item = JObject.Parse(rawresp); var img = item["kitsune"]; if (img == null) return null; @@ -183,7 +163,7 @@ namespace SysEx.Net /// public async Task GetKitsuneAsync() { - var rawresp = await WebRequest.ReturnStringAsync(new Uri("https://kitsu.systemexit.co.uk/kitsune")); + var rawresp = await WebRequest.ReturnStringAsync(new Uri(KitsuBase, "/kitsune")); dynamic item = JObject.Parse(rawresp); var img = item["kitsune"]; if (img == null) return null; diff --git a/SysEx.Net/Models/MemeEndpoints.cs b/SysEx.Net/Models/MemeEndpoints.cs index a9a5399..ee646b9 100644 --- a/SysEx.Net/Models/MemeEndpoints.cs +++ b/SysEx.Net/Models/MemeEndpoints.cs @@ -4,9 +4,9 @@ namespace SysEx.Net.Models { public struct MemeEndpoints { - [JsonProperty("Name")] + [JsonProperty("endpoint")] public string Name; - [JsonProperty("RequiredSources")] + [JsonProperty("sources")] public int RequiredSources; } } diff --git a/SysEx.Net/Models/MemeResponse.cs b/SysEx.Net/Models/MemeResponse.cs index ca2f73c..2659f5f 100644 --- a/SysEx.Net/Models/MemeResponse.cs +++ b/SysEx.Net/Models/MemeResponse.cs @@ -5,12 +5,10 @@ namespace SysEx.Net.Models { public struct MemeResponse { - [JsonProperty("Successful")] + [JsonProperty("success")] public bool Successful; - [JsonProperty("example")] - public string Example; - [JsonProperty("available-templates")] + [JsonProperty("data")] public List Endpoints; } } diff --git a/SysEx.Net/SysEx.Net.csproj b/SysEx.Net/SysEx.Net.csproj index e0f74b4..5b71040 100644 --- a/SysEx.Net/SysEx.Net.csproj +++ b/SysEx.Net/SysEx.Net.csproj @@ -9,13 +9,15 @@ https://github.com/exsersewo/SysEx.Net false false - A .Net Wrapper for utilties hosted at: https://api.systemexit.co.uk/ & https://kitsu.systemexit.co.uk/ + A .Net Wrapper for utilties hosted at: https://api.exsersewo.dev/ & https://kitsu.exsersewo.dev/ & https://api.skuldbot.uk/meme exsersewo Initial Release en-GB Library https://github.com/exsersewo/SysEx.Net/blob/master/LICENSE - 1.0.7 + 1.0.9 + 1.0.9.0 + 1.0.9.0