Add Meme Stuff, Add Documentation, Ver Bump & Test

master
exsersewo 6 years ago
parent 1c6faf58ae
commit 7f1ec8264d
  1. 18
      SysEx.Net.Tests/Program.cs
  2. 8
      SysEx.Net.Tests/SysEx.Net.Tests.csproj
  3. 5
      SysEx.Net.Tests/packages.config
  4. 100
      SysEx.Net/Client.cs
  5. 2
      SysEx.Net/Models/Animal.cs
  6. 8
      SysEx.Net/Models/MemeEndpoints.cs
  7. 14
      SysEx.Net/Models/MemeResponse.cs
  8. 2
      SysEx.Net/Models/PickupLine.cs
  9. 2
      SysEx.Net/Models/Roast.cs
  10. 5
      SysEx.Net/Models/WeebGif.cs
  11. 5
      SysEx.Net/SysEx.Net.csproj
  12. 50
      SysEx.Net/WebRequest.cs

@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using System.Threading.Tasks;
using SysEx.Net;
namespace SysEx.Net.Tests
{
@ -17,9 +15,17 @@ namespace SysEx.Net.Tests
{
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();
}

@ -32,8 +32,15 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<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.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.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@ -47,6 +54,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SysEx.Net\SysEx.Net.csproj">

@ -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 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
{

@ -0,0 +1,8 @@
namespace SysEx.Net.Models
{
public struct MemeEndpoints
{
public string Name;
public int RequiredSources;
}
}

@ -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;
}
}
}
}

Loading…
Cancel
Save