Add Meme Stuff, Add Documentation, Ver Bump & Test
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.IO;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using SysEx.Net;
|
|
||||||
|
|
||||||
namespace SysEx.Net.Tests
|
namespace SysEx.Net.Tests
|
||||||
{
|
{
|
||||||
@@ -17,9 +15,17 @@ namespace SysEx.Net.Tests
|
|||||||
{
|
{
|
||||||
var client = new SysExClient();
|
var client = new SysExClient();
|
||||||
|
|
||||||
var resp = await client.GetWeebActionGifAsync(GifType.Slap);
|
var resp = await client.GetMemeImageAsync("22million", "https://cdn.discordapp.com/avatars/270047199184945152/e6a23a1c72703edb5e178411bba9190c.png");
|
||||||
|
|
||||||
Console.WriteLine(resp);
|
if(resp is Stream)
|
||||||
|
{
|
||||||
|
Console.Write("Got Successfully");
|
||||||
|
}
|
||||||
|
|
||||||
|
var re = resp as MemoryStream;
|
||||||
|
|
||||||
|
Image img = Image.FromStream(re);
|
||||||
|
img.Save(AppContext.BaseDirectory + "image.jpg");
|
||||||
|
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,15 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Drawing.Common, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\System.Drawing.Common.4.6.0-preview.19073.11\lib\net461\System.Drawing.Common.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
@@ -47,6 +54,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\SysEx.Net\SysEx.Net.csproj">
|
<ProjectReference Include="..\SysEx.Net\SysEx.Net.csproj">
|
||||||
|
|||||||
5
SysEx.Net.Tests/packages.config
Normal file
5
SysEx.Net.Tests/packages.config
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net472" />
|
||||||
|
<package id="System.Drawing.Common" version="4.6.0-preview.19073.11" targetFramework="net472" />
|
||||||
|
</packages>
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
using System;
|
using Newtonsoft.Json;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Newtonsoft.Json.Linq;
|
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
|
namespace SysEx.Net
|
||||||
{
|
{
|
||||||
@@ -15,24 +18,45 @@ namespace SysEx.Net
|
|||||||
random = new Random();
|
random = new Random();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a Llama image
|
||||||
|
/// </summary>
|
||||||
public async Task<string> GetLlamaAsync() =>
|
public async Task<string> GetLlamaAsync() =>
|
||||||
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/llama.json"));
|
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/llama.json"));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a Seal image
|
||||||
|
/// </summary>
|
||||||
public async Task<string> GetSealAsync() =>
|
public async Task<string> GetSealAsync() =>
|
||||||
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/seal.json"));
|
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/seal.json"));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a Duck image
|
||||||
|
/// </summary>
|
||||||
public async Task<string> GetDuckAsync() =>
|
public async Task<string> GetDuckAsync() =>
|
||||||
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/duck.json"));
|
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/duck.json"));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a Squirrel image
|
||||||
|
/// </summary>
|
||||||
public async Task<string> GetSquirrelAsync() =>
|
public async Task<string> GetSquirrelAsync() =>
|
||||||
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/squirrel.json"));
|
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/squirrel.json"));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a Lizard image
|
||||||
|
/// </summary>
|
||||||
public async Task<string> GetLizardAsync() =>
|
public async Task<string> GetLizardAsync() =>
|
||||||
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/lizard.json"));
|
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/lizard.json"));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a morphed animal image
|
||||||
|
/// </summary>
|
||||||
public async Task<string> GetMorphAsync() =>
|
public async Task<string> GetMorphAsync() =>
|
||||||
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/morphs.json"));
|
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/morphs.json"));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a Snake image
|
||||||
|
/// </summary>
|
||||||
public async Task<string> GetSnakeAsync() =>
|
public async Task<string> GetSnakeAsync() =>
|
||||||
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/snake.json"));
|
await GetAnimalAsync(new Uri("https://api.systemexit.co.uk/v1/snake.json"));
|
||||||
|
|
||||||
@@ -45,6 +69,9 @@ namespace SysEx.Net
|
|||||||
return animal;
|
return animal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a roast
|
||||||
|
/// </summary>
|
||||||
public async Task<string> GetRoastAsync()
|
public async Task<string> GetRoastAsync()
|
||||||
{
|
{
|
||||||
var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/v1/roasts.json"));
|
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;
|
return items[random.Next(0, items.Count)].Roast;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a terrible, terrible Dad joke
|
||||||
|
/// </summary>
|
||||||
public async Task<Joke> GetDadJokeAsync()
|
public async Task<Joke> GetDadJokeAsync()
|
||||||
{
|
{
|
||||||
var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/v1/dadjokes.json"));
|
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)];
|
return items[random.Next(0, items.Count)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a terrible, terrible pickup line
|
||||||
|
/// </summary>
|
||||||
public async Task<Joke> GetPickupLineAsync()
|
public async Task<Joke> GetPickupLineAsync()
|
||||||
{
|
{
|
||||||
var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/v1/pickuplines.json"));
|
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)];
|
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)
|
public async Task<string> GetWeebActionGifAsync(GifType type)
|
||||||
{
|
{
|
||||||
var resp = await WebRequest.GetRedirectUriAsync(new Uri("https://api.systemexit.co.uk/actions/?action=" + type.ToString().ToLowerInvariant()));
|
var resp = await WebRequest.GetRedirectUriAsync(new Uri("https://api.systemexit.co.uk/actions/?action=" + type.ToString().ToLowerInvariant()));
|
||||||
return resp.OriginalString;
|
return resp.OriginalString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets A Weeb Reaction Gif
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Url of image</returns>
|
||||||
public async Task<string> GetWeebReactionGifAsync()
|
public async Task<string> GetWeebReactionGifAsync()
|
||||||
{
|
{
|
||||||
var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/reactions/"));
|
var resp = await WebRequest.ReturnStringAsync(new Uri("https://api.systemexit.co.uk/reactions/"));
|
||||||
return resp;
|
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()
|
public async Task<string> GetLewdKitsuneAsync()
|
||||||
{
|
{
|
||||||
var rawresp = await WebRequest.ReturnStringAsync(new Uri("https://kitsu.systemexit.co.uk/lewd"));
|
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;
|
if (img == null) return null;
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a SFW* image of a "Kitsune" (*potentially)
|
||||||
|
/// </summary>
|
||||||
public async Task<string> GetKitsuneAsync()
|
public async Task<string> GetKitsuneAsync()
|
||||||
{
|
{
|
||||||
var rawresp = await WebRequest.ReturnStringAsync(new Uri("https://kitsu.systemexit.co.uk/kitsune"));
|
var rawresp = await WebRequest.ReturnStringAsync(new Uri("https://kitsu.systemexit.co.uk/kitsune"));
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SysEx.Net
|
namespace SysEx.Net.Models
|
||||||
{
|
{
|
||||||
public class Animal
|
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
|
public class Joke
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
namespace SysEx.Net
|
namespace SysEx.Net.Models
|
||||||
{
|
{
|
||||||
public class Roasts
|
public class Roasts
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace SysEx.Net
|
namespace SysEx.Net.Models
|
||||||
{
|
{
|
||||||
public class WeebGif
|
public class WeebGif
|
||||||
{
|
{
|
||||||
@@ -9,7 +8,7 @@ namespace SysEx.Net
|
|||||||
public string URL { get; set; }
|
public string URL { get; set; }
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "type")]
|
[JsonProperty(PropertyName = "type")]
|
||||||
public GifType GifType { get; set; }
|
public GifType GifType { get; set; }
|
||||||
}
|
}
|
||||||
public enum GifType
|
public enum GifType
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,11 +15,14 @@
|
|||||||
<NeutralLanguage>en-GB</NeutralLanguage>
|
<NeutralLanguage>en-GB</NeutralLanguage>
|
||||||
<RepositoryType>Library</RepositoryType>
|
<RepositoryType>Library</RepositoryType>
|
||||||
<PackageLicenseUrl>https://github.com/exsersewo/SysEx.Net/blob/master/LICENSE</PackageLicenseUrl>
|
<PackageLicenseUrl>https://github.com/exsersewo/SysEx.Net/blob/master/LICENSE</PackageLicenseUrl>
|
||||||
<Version>1.0.5</Version>
|
<Version>1.0.6</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using SysEx.Net.Models;
|
||||||
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -59,5 +60,52 @@ namespace SysEx.Net
|
|||||||
return null;
|
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