From 30606f9f0c3da4d66cb31a66b65e782ba608e3b3 Mon Sep 17 00:00:00 2001 From: exsersewo Date: Wed, 23 May 2018 20:42:15 +0100 Subject: [PATCH] update stuff --- SysEx.Net/Class1.cs | 8 --- SysEx.Net/Client.cs | 104 +++++++++++++++++++++++++++++++++ SysEx.Net/Models/Animal.cs | 10 ++++ SysEx.Net/Models/PickupLine.cs | 8 +++ SysEx.Net/Models/Roast.cs | 7 +++ SysEx.Net/Models/WeebGif.cs | 48 +++++++++++++++ SysEx.Net/SysEx.Net.csproj | 19 ++++++ SysEx.Net/WebRequest.cs | 49 ++++++++++++++++ 8 files changed, 245 insertions(+), 8 deletions(-) delete mode 100644 SysEx.Net/Class1.cs create mode 100644 SysEx.Net/Client.cs create mode 100644 SysEx.Net/Models/Animal.cs create mode 100644 SysEx.Net/Models/PickupLine.cs create mode 100644 SysEx.Net/Models/Roast.cs create mode 100644 SysEx.Net/Models/WeebGif.cs create mode 100644 SysEx.Net/WebRequest.cs diff --git a/SysEx.Net/Class1.cs b/SysEx.Net/Class1.cs deleted file mode 100644 index 5680640..0000000 --- a/SysEx.Net/Class1.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace SysEx.Net -{ - public class Class1 - { - } -} diff --git a/SysEx.Net/Client.cs b/SysEx.Net/Client.cs new file mode 100644 index 0000000..425b5dc --- /dev/null +++ b/SysEx.Net/Client.cs @@ -0,0 +1,104 @@ +using System; +using System.Threading.Tasks; +using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json.Linq; + +namespace SysEx.Net +{ + public class SysExClient + { + readonly Random random; + + public SysExClient() + { + random = new Random(); + } + + public async Task GetLlamaAsync() => + await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/get/llama.json")); + + public async Task GetSealAsync() => + await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/get/seal.json")); + + public async Task GetDuckAsync() => + await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/get/duck.json")); + + public async Task GetSquirrelAsync() => + await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/get/squirrel.json")); + + public async Task GetLizardAsync() => + await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/get/lizard.json")); + + public async Task GetMorphAsync() => + await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/get/morphs.json")); + + public async Task GetSnakeAsync() => + await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/get/snake.json")); + + async Task GetAnimalAsync(Uri url) + { + var resp = await WebRequest.ReturnStringAsync(url); + var items = JsonConvert.DeserializeObject>(resp); + if (items == null) return null; + var animal = items[random.Next(0, items.Count)].URL; + return animal; + } + + public async Task GetRoastAsync() + { + var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/get/roasts.json")); + var items = JsonConvert.DeserializeObject>(resp); + if (items == null) return null; + return items[random.Next(0, items.Count)].Roast; + } + + public async Task GetDadJokeAsync() + { + var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/get/dadjokes.json")); + var items = JsonConvert.DeserializeObject>(resp); + if (items == null) return null; + return items[random.Next(0, items.Count)]; + } + + public async Task GetPickupLineAsync() + { + var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/get/pickuplines.json")); + var items = JsonConvert.DeserializeObject>(resp); + if (items == null) return null; + return items[random.Next(0, items.Count)]; + } + + public async Task GetWeebActionGifAsync(GifType type) + { + var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/get/actions/type/" + type + ".json")); + var items = JsonConvert.DeserializeObject>(resp); + return items[random.Next(0, items.Count)]; + } + + public async Task GetWeebReactionGifAsync() + { + var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/get/reactions.json")); + var items = JsonConvert.DeserializeObject>(resp); + if (items == null) return null; + return items[random.Next(0, items.Count)]; + } + + public async Task GetLewdKitsuneAsync() + { + var rawresp = await WebRequest.ReturnStringAsync(new Uri("https://kitsu.systemexit.co.uk/lewd")); + dynamic item = JObject.Parse(rawresp); + var img = item["kitsune"]; + if (img == null) return null; + return img; + } + public async Task GetKitsuneAsync() + { + var rawresp = await WebRequest.ReturnStringAsync(new Uri("https://kitsu.systemexit.co.uk/kitsune")); + dynamic item = JObject.Parse(rawresp); + var img = item["kitsune"]; + if (img == null) return null; + return img; + } + } +} diff --git a/SysEx.Net/Models/Animal.cs b/SysEx.Net/Models/Animal.cs new file mode 100644 index 0000000..6dfa5ff --- /dev/null +++ b/SysEx.Net/Models/Animal.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace SysEx.Net +{ + public class Animal + { + [JsonProperty(PropertyName = "file")] + public string URL { get; set; } + } +} diff --git a/SysEx.Net/Models/PickupLine.cs b/SysEx.Net/Models/PickupLine.cs new file mode 100644 index 0000000..bf8abf2 --- /dev/null +++ b/SysEx.Net/Models/PickupLine.cs @@ -0,0 +1,8 @@ +namespace SysEx.Net +{ + public class Joke + { + public string Setup { get; set; } + public string Punchline { get; set; } + } +} diff --git a/SysEx.Net/Models/Roast.cs b/SysEx.Net/Models/Roast.cs new file mode 100644 index 0000000..e9d024e --- /dev/null +++ b/SysEx.Net/Models/Roast.cs @@ -0,0 +1,7 @@ +namespace SysEx.Net +{ + public class Roasts + { + public string Roast { get; set; } + } +} diff --git a/SysEx.Net/Models/WeebGif.cs b/SysEx.Net/Models/WeebGif.cs new file mode 100644 index 0000000..9871d43 --- /dev/null +++ b/SysEx.Net/Models/WeebGif.cs @@ -0,0 +1,48 @@ +using Newtonsoft.Json; +using System; + +namespace SysEx.Net +{ + public class WeebGif + { + [JsonProperty(PropertyName = "url")] + public string URL { get; set; } + + [JsonProperty(PropertyName = "type")] + public GifType GifType { get; set; } + } + public enum GifType + { + Adore, + Amazed, + Approve, + Blush, + Bored, + Cuddle, + Dance, + Disgust, + Disapprove, + Feels, + Glare, + Grope, + Happy, + Hug, + Kill, + Kiss, + Lewd, + Mad, + Moe, + Nani, + Nope, + Pet, + Punch, + Sad, + Shock, + Shrug, + Slap, + Smug, + Stab, + Triggered, + Unamused + } +} diff --git a/SysEx.Net/SysEx.Net.csproj b/SysEx.Net/SysEx.Net.csproj index 9f5c4f4..e0ea1ec 100644 --- a/SysEx.Net/SysEx.Net.csproj +++ b/SysEx.Net/SysEx.Net.csproj @@ -2,6 +2,25 @@ netstandard2.0 + true + exsersewo + + https://github.com/exsersewo/SysEx.Net + 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/ + exsersewo + + true + + + + + + + + diff --git a/SysEx.Net/WebRequest.cs b/SysEx.Net/WebRequest.cs new file mode 100644 index 0000000..8b33801 --- /dev/null +++ b/SysEx.Net/WebRequest.cs @@ -0,0 +1,49 @@ +using System; +using System.Net; +using System.Threading.Tasks; +using System.IO; + +namespace SysEx.Net +{ + class WebRequest + { + public static HttpWebRequest CreateWebRequest(Uri uri) + { + var cli = (HttpWebRequest)System.Net.WebRequest.Create(uri); + + cli.AllowAutoRedirect = true; + cli.KeepAlive = false; + cli.Timeout = 20000; + cli.ProtocolVersion = HttpVersion.Version10; + + return cli; + } + public static async Task ReturnStringAsync(Uri url) + { + try + { + var client = CreateWebRequest(url); + + var resp = (HttpWebResponse)(await client.GetResponseAsync()); + if (resp.StatusCode == HttpStatusCode.OK) + { + var reader = new StreamReader(resp.GetResponseStream()); + var responce = await reader.ReadToEndAsync(); + resp.Dispose(); + client.Abort(); + return responce; + } + else + { + resp.Dispose(); + client.Abort(); + return null; + } + } + catch + { + return null; + } + } + } +}