2017-07-17 19:42:36 +00:00
|
|
|
|
using System;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using ImageSharp;
|
|
|
|
|
using NadekoBot.Common;
|
|
|
|
|
using NadekoBot.Extensions;
|
2017-10-13 04:14:54 +00:00
|
|
|
|
using NadekoBot.Core.Services;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using NLog;
|
2017-07-18 16:26:55 +00:00
|
|
|
|
using SixLabors.Primitives;
|
2017-05-27 08:19:27 +00:00
|
|
|
|
|
2017-07-17 19:42:36 +00:00
|
|
|
|
namespace NadekoBot.Modules.Games.Common
|
2017-05-27 08:19:27 +00:00
|
|
|
|
{
|
|
|
|
|
public class GirlRating
|
|
|
|
|
{
|
|
|
|
|
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
|
|
|
|
public double Crazy { get; }
|
|
|
|
|
public double Hot { get; }
|
|
|
|
|
public int Roll { get; }
|
|
|
|
|
public string Advice { get; }
|
|
|
|
|
public AsyncLazy<string> Url { get; }
|
|
|
|
|
|
|
|
|
|
public GirlRating(IImagesService _images, double crazy, double hot, int roll, string advice)
|
|
|
|
|
{
|
|
|
|
|
Crazy = crazy;
|
|
|
|
|
Hot = hot;
|
|
|
|
|
Roll = roll;
|
|
|
|
|
Advice = advice; // convenient to have it here, even though atm there are only few different ones.
|
|
|
|
|
|
|
|
|
|
Url = new AsyncLazy<string>(async () =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var ms = new MemoryStream(_images.WifeMatrix.ToArray(), false))
|
2017-07-18 16:26:55 +00:00
|
|
|
|
using (var img = Image.Load(ms))
|
2017-05-27 08:19:27 +00:00
|
|
|
|
{
|
|
|
|
|
const int minx = 35;
|
|
|
|
|
const int miny = 385;
|
|
|
|
|
const int length = 345;
|
|
|
|
|
|
|
|
|
|
var pointx = (int)(minx + length * (Hot / 10));
|
|
|
|
|
var pointy = (int)(miny - length * ((Crazy - 4) / 6));
|
|
|
|
|
|
|
|
|
|
using (var pointMs = new MemoryStream(_images.RategirlDot.ToArray(), false))
|
2017-07-18 16:26:55 +00:00
|
|
|
|
using (var pointImg = Image.Load(pointMs))
|
2017-05-27 08:19:27 +00:00
|
|
|
|
{
|
|
|
|
|
img.DrawImage(pointImg, 100, default(Size), new Point(pointx - 10, pointy - 10));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string url;
|
|
|
|
|
using (var http = new HttpClient())
|
|
|
|
|
using (var imgStream = new MemoryStream())
|
|
|
|
|
{
|
2017-07-18 16:26:55 +00:00
|
|
|
|
img.SaveAsPng(imgStream);
|
2017-05-27 08:19:27 +00:00
|
|
|
|
var byteContent = new ByteArrayContent(imgStream.ToArray());
|
|
|
|
|
http.AddFakeHeaders();
|
|
|
|
|
|
|
|
|
|
var reponse = await http.PutAsync("https://transfer.sh/img.png", byteContent);
|
|
|
|
|
url = await reponse.Content.ReadAsStringAsync();
|
|
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_log.Warn(ex);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|