global nadeko won't cache nsfw images

This commit is contained in:
Master Kwoth 2017-09-12 23:49:37 +02:00
parent 46f9de01d6
commit 438f68cde7
3 changed files with 140 additions and 142 deletions

View File

@ -76,11 +76,13 @@ namespace NadekoBot.Modules.Searches.Common
if (images.Length == 0)
return null;
var toReturn = images[_rng.Next(images.Length)];
#if !GLOBAL_NADEKO
foreach (var dledImg in images)
{
if(dledImg != toReturn)
_cache.Add(dledImg);
}
#endif
return toReturn;
}
}

View File

@ -549,7 +549,7 @@ namespace NadekoBot.Modules.Xp.Services
}
}
public Task<Image<Rgba32>> GenerateImageAsync(IGuildUser user)
public Task<MemoryStream> GenerateImageAsync(IGuildUser user)
{
return GenerateImageAsync(GetUserStats(user));
}
@ -565,9 +565,10 @@ namespace NadekoBot.Modules.Xp.Services
_timeFont = _fonts.Find("Whitney-Bold").CreateFont(20);
}
public Task<Image<Rgba32>> GenerateImageAsync(FullUserStats stats) => Task.Run(async () =>
public Task<MemoryStream> GenerateImageAsync(FullUserStats stats) => Task.Run(async () =>
{
using (var img = Image.Load(_images.XpCard.ToArray()))
{
var img = Image.Load(_images.XpCard.ToArray());
var username = stats.User.ToString();
var usernameFont = _usernameFontFamily
@ -668,9 +669,8 @@ namespace NadekoBot.Modules.Xp.Services
if (!succ)
{
using (var temp = await http.GetStreamAsync(avatarUrl))
using (var tempDraw = Image.Load(temp).Resize(69, 70))
{
var tempDraw = Image.Load(temp);
tempDraw = tempDraw.Resize(69, 70);
ApplyRoundedCorners(tempDraw, 35);
data = tempDraw.ToStream().ToArray();
}
@ -702,9 +702,8 @@ namespace NadekoBot.Modules.Xp.Services
if (!succ)
{
using (var temp = await http.GetStreamAsync(imgUrl))
using (var tempDraw = Image.Load(temp).Resize(45, 45))
{
var tempDraw = Image.Load(temp);
tempDraw = tempDraw.Resize(45, 45);
ApplyRoundedCorners(tempDraw, 22.5f);
data = tempDraw.ToStream().ToArray();
}
@ -723,12 +722,9 @@ namespace NadekoBot.Modules.Xp.Services
_log.Warn(ex);
}
}
img.Resize(432, 211);
var arr = img.ToStream().ToArray();
//_log.Info("{0:F2} KB", arr.Length * 1.0f / 1.KB());
return img;
return img.Resize(432, 211).ToStream();
}
});

View File

@ -32,7 +32,7 @@ namespace NadekoBot.Modules.Xp
sw.Stop();
_log.Info("Generating finished in {0:F2}s", sw.Elapsed.TotalSeconds);
sw.Restart();
await Context.Channel.SendFileAsync(img.ToStream(), $"{user.Id}_xp.png")
await Context.Channel.SendFileAsync(img, $"{user.Id}_xp.png")
.ConfigureAwait(false);
sw.Stop();
_log.Info("Sending finished in {0:F2}s", sw.Elapsed.TotalSeconds);