Fixed a performance and stability bug with club images.
This commit is contained in:
parent
e32446335e
commit
998c048874
@ -110,7 +110,8 @@ namespace NadekoBot.Services
|
||||
|
||||
public async Task RunAsync()
|
||||
{
|
||||
for (int i = 0; i < _creds.TotalShards; i++)
|
||||
//todo change to 0
|
||||
for (int i = 1; i < _creds.TotalShards; i++)
|
||||
{
|
||||
var p = StartShard(i);
|
||||
|
||||
|
@ -152,7 +152,8 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
|
||||
var oldGuildLevelData = new LevelStats(usr.Xp + usr.AwardedXp);
|
||||
usr.Xp += xp;
|
||||
du.TotalXp += xp;
|
||||
//todo revert
|
||||
du.TotalXp += xp * 1000;
|
||||
if (du.Club != null)
|
||||
du.Club.Xp += xp;
|
||||
var newGuildLevelData = new LevelStats(usr.Xp + usr.AwardedXp);
|
||||
@ -685,6 +686,15 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
}
|
||||
|
||||
//club image
|
||||
await DrawClubImage(img, stats).ConfigureAwait(false);
|
||||
|
||||
return img.Resize(432, 211).ToStream();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
private async Task DrawClubImage(Image<Rgba32> img, FullUserStats stats)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(stats.User.Club?.ImageUrl))
|
||||
{
|
||||
var imgUrl = stats.User.Club.ImageUrl;
|
||||
@ -694,12 +704,18 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
if (!succ)
|
||||
{
|
||||
//todo make sure it's a picture
|
||||
using (var temp = await http.GetStreamAsync(imgUrl))
|
||||
using (var tempDraw = Image.Load(temp).Resize(45, 45))
|
||||
using (var temp = await http.GetAsync(imgUrl, HttpCompletionOption.ResponseHeadersRead))
|
||||
{
|
||||
if (temp.Content.Headers.ContentType.MediaType != "image/png"
|
||||
&& temp.Content.Headers.ContentType.MediaType != "image/jpeg"
|
||||
&& temp.Content.Headers.ContentType.MediaType != "image/gif")
|
||||
return;
|
||||
using (var tempDraw = Image.Load(await temp.Content.ReadAsStreamAsync()).Resize(45, 45))
|
||||
{
|
||||
ApplyRoundedCorners(tempDraw, 22.5f);
|
||||
data = tempDraw.ToStream().ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
await _cache.SetImageDataAsync(imgUrl, data);
|
||||
}
|
||||
@ -715,11 +731,7 @@ namespace NadekoBot.Modules.Xp.Services
|
||||
_log.Warn(ex);
|
||||
}
|
||||
}
|
||||
|
||||
return img.Resize(432, 211).ToStream();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// https://github.com/SixLabors/ImageSharp/tree/master/samples/AvatarWithRoundedCorner
|
||||
public static void ApplyRoundedCorners(Image<Rgba32> img, float cornerRadius)
|
||||
|
@ -1,4 +1,5 @@
|
||||
using NadekoBot.Services;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot
|
||||
@ -16,6 +17,9 @@ namespace NadekoBot
|
||||
}
|
||||
else
|
||||
{
|
||||
//todo revert
|
||||
var _ = new NadekoBot(0, Process.GetCurrentProcess().Id)
|
||||
.RunAsync(args);
|
||||
return new ShardsCoordinator()
|
||||
.RunAndBlockAsync();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user