Add Meme Stuff, Add Documentation, Ver Bump & Test
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SysEx.Net.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SysEx.Net
|
||||
{
|
||||
@@ -15,24 +18,45 @@ namespace SysEx.Net
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Llama image
|
||||
/// </summary>
|
||||
public async Task<string> GetLlamaAsync() =>
|
||||
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/llama.json"));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Seal image
|
||||
/// </summary>
|
||||
public async Task<string> GetSealAsync() =>
|
||||
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/seal.json"));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Duck image
|
||||
/// </summary>
|
||||
public async Task<string> GetDuckAsync() =>
|
||||
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/duck.json"));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Squirrel image
|
||||
/// </summary>
|
||||
public async Task<string> GetSquirrelAsync() =>
|
||||
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/squirrel.json"));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Lizard image
|
||||
/// </summary>
|
||||
public async Task<string> GetLizardAsync() =>
|
||||
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/lizard.json"));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a morphed animal image
|
||||
/// </summary>
|
||||
public async Task<string> GetMorphAsync() =>
|
||||
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/morphs.json"));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a Snake image
|
||||
/// </summary>
|
||||
public async Task<string> GetSnakeAsync() =>
|
||||
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/snake.json"));
|
||||
|
||||
@@ -45,6 +69,9 @@ namespace SysEx.Net
|
||||
return animal;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a roast
|
||||
/// </summary>
|
||||
public async Task<string> GetRoastAsync()
|
||||
{
|
||||
var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/v1/roasts.json"));
|
||||
@@ -53,6 +80,9 @@ namespace SysEx.Net
|
||||
return items[random.Next(0, items.Count)].Roast;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a terrible, terrible Dad joke
|
||||
/// </summary>
|
||||
public async Task<Joke> GetDadJokeAsync()
|
||||
{
|
||||
var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/v1/dadjokes.json"));
|
||||
@@ -61,6 +91,9 @@ namespace SysEx.Net
|
||||
return items[random.Next(0, items.Count)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a terrible, terrible pickup line
|
||||
/// </summary>
|
||||
public async Task<Joke> GetPickupLineAsync()
|
||||
{
|
||||
var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/v1/pickuplines.json"));
|
||||
@@ -69,18 +102,74 @@ namespace SysEx.Net
|
||||
return items[random.Next(0, items.Count)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets A Weeb Action Gif
|
||||
/// </summary>
|
||||
/// <param name="type">Gif Action Type</param>
|
||||
/// <returns>Url of image</returns>
|
||||
public async Task<string> GetWeebActionGifAsync(GifType type)
|
||||
{
|
||||
var resp = await WebRequest.GetRedirectUriAsync(new Uri("https://api.systemexit.co.uk/actions/?action=" + type.ToString().ToLowerInvariant()));
|
||||
return resp.OriginalString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets A Weeb Reaction Gif
|
||||
/// </summary>
|
||||
/// <returns>Url of image</returns>
|
||||
public async Task<string> GetWeebReactionGifAsync()
|
||||
{
|
||||
var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/reactions/"));
|
||||
return resp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a meme image based on given input
|
||||
/// </summary>
|
||||
/// <param name="template">Template to use</param>
|
||||
/// <param name="images">Source images to use with template</param>
|
||||
/// <returns>Either Object. MemeResponse on empty input or failure, or MemoryStream on success</returns>
|
||||
public async Task<object> GetMemeImageAsync(string template = null, params string[] images)
|
||||
{
|
||||
var endpoints = JsonConvert.DeserializeObject<MemeResponse>(await WebRequest.ReturnStringAsync(new Uri("https://api.skuldbot.uk/fun/meme/?endpoints")));
|
||||
if (template == null && (images.Length <= 0 || images == null))
|
||||
{
|
||||
return endpoints;
|
||||
}
|
||||
if(endpoints.Endpoints.Exists(x=>x.Name.ToLowerInvariant() == template.ToLowerInvariant()))
|
||||
{
|
||||
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())
|
||||
{
|
||||
queryString += $"source{x}={image}";
|
||||
}
|
||||
else
|
||||
{
|
||||
queryString += $"source{x}={image}&";
|
||||
}
|
||||
x++;
|
||||
}
|
||||
|
||||
var resp = await WebRequest.GetStreamAsync(new Uri($"https://api.skuldbot.uk/fun/meme/{template}/?{queryString}"));
|
||||
if(resp != null)
|
||||
{
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
return new MemeResponse
|
||||
{
|
||||
Successful = false,
|
||||
Endpoints = endpoints.Endpoints
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a NSFW image of a "Kitsune"
|
||||
/// </summary>
|
||||
public async Task<string> GetLewdKitsuneAsync()
|
||||
{
|
||||
var rawresp = await WebRequest.ReturnStringAsync(new Uri("https://kitsu.systemexit.co.uk/lewd"));
|
||||
@@ -89,6 +178,9 @@ namespace SysEx.Net
|
||||
if (img == null) return null;
|
||||
return img;
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets a SFW* image of a "Kitsune" (*potentially)
|
||||
/// </summary>
|
||||
public async Task<string> GetKitsuneAsync()
|
||||
{
|
||||
var rawresp = await WebRequest.ReturnStringAsync(new Uri("https://kitsu.systemexit.co.uk/kitsune"));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SysEx.Net
|
||||
namespace SysEx.Net.Models
|
||||
{
|
||||
public class Animal
|
||||
{
|
||||
|
||||
8
SysEx.Net/Models/MemeEndpoints.cs
Normal file
8
SysEx.Net/Models/MemeEndpoints.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace SysEx.Net.Models
|
||||
{
|
||||
public struct MemeEndpoints
|
||||
{
|
||||
public string Name;
|
||||
public int RequiredSources;
|
||||
}
|
||||
}
|
||||
14
SysEx.Net/Models/MemeResponse.cs
Normal file
14
SysEx.Net/Models/MemeResponse.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SysEx.Net.Models
|
||||
{
|
||||
public struct MemeResponse
|
||||
{
|
||||
public bool Successful;
|
||||
public string Example;
|
||||
|
||||
[JsonProperty(PropertyName = "availabletemplates")]
|
||||
public List<MemeEndpoints> Endpoints;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace SysEx.Net
|
||||
namespace SysEx.Net.Models
|
||||
{
|
||||
public class Joke
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace SysEx.Net
|
||||
namespace SysEx.Net.Models
|
||||
{
|
||||
public class Roasts
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace SysEx.Net
|
||||
namespace SysEx.Net.Models
|
||||
{
|
||||
public class WeebGif
|
||||
{
|
||||
@@ -9,7 +8,7 @@ namespace SysEx.Net
|
||||
public string URL { get; set; }
|
||||
|
||||
[JsonProperty(PropertyName = "type")]
|
||||
public GifType GifType { get; set; }
|
||||
public GifType GifType { get; set; }
|
||||
}
|
||||
public enum GifType
|
||||
{
|
||||
|
||||
@@ -15,11 +15,14 @@
|
||||
<NeutralLanguage>en-GB</NeutralLanguage>
|
||||
<RepositoryType>Library</RepositoryType>
|
||||
<PackageLicenseUrl>https://github.com/exsersewo/SysEx.Net/blob/master/LICENSE</PackageLicenseUrl>
|
||||
<Version>1.0.5</Version>
|
||||
<Version>1.0.6</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<Optimize>true</Optimize>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SysEx.Net.Models;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
@@ -59,5 +60,52 @@ namespace SysEx.Net
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static async Task<MemoryStream> GetStreamAsync(Uri url)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = CreateWebRequest(url);
|
||||
|
||||
var resp = (HttpWebResponse)(await client.GetResponseAsync());
|
||||
if (resp.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
var reader = resp.GetResponseStream();
|
||||
long contLength = resp.ContentLength;
|
||||
|
||||
var stream = resp.GetResponseStream();
|
||||
|
||||
byte[] outData;
|
||||
using (var tempStream = new MemoryStream())
|
||||
{
|
||||
byte[] buffer = new byte[128];
|
||||
while (true)
|
||||
{
|
||||
int read = stream.Read(buffer, 0, buffer.Length);
|
||||
if (read <= 0)
|
||||
{
|
||||
outData = tempStream.ToArray();
|
||||
break;
|
||||
}
|
||||
tempStream.Write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
|
||||
resp.Dispose();
|
||||
client.Abort();
|
||||
|
||||
return new MemoryStream(outData);
|
||||
}
|
||||
else
|
||||
{
|
||||
resp.Dispose();
|
||||
client.Abort();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user