diff --git a/NadekoBot.Core/Services/ShardsCoordinator.cs b/NadekoBot.Core/Services/ShardsCoordinator.cs index 7816d466..6c799103 100644 --- a/NadekoBot.Core/Services/ShardsCoordinator.cs +++ b/NadekoBot.Core/Services/ShardsCoordinator.cs @@ -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); diff --git a/NadekoBot.Modules.Xp/Services/XpService.cs b/NadekoBot.Modules.Xp/Services/XpService.cs index 5c1443e3..ac8a2630 100644 --- a/NadekoBot.Modules.Xp/Services/XpService.cs +++ b/NadekoBot.Modules.Xp/Services/XpService.cs @@ -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,42 +686,53 @@ namespace NadekoBot.Modules.Xp.Services } //club image - if (!string.IsNullOrWhiteSpace(stats.User.Club?.ImageUrl)) - { - var imgUrl = stats.User.Club.ImageUrl; - try - { - var (succ, data) = await _cache.TryGetImageDataAsync(imgUrl); - 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)) - { - ApplyRoundedCorners(tempDraw, 22.5f); - data = tempDraw.ToStream().ToArray(); - } - - await _cache.SetImageDataAsync(imgUrl, data); - } - var toDraw = Image.Load(data); - - img.DrawImage(toDraw, - 1, - new Size(45, 45), - new Point(722, 25)); - } - catch (Exception ex) - { - _log.Warn(ex); - } - } + await DrawClubImage(img, stats).ConfigureAwait(false); return img.Resize(432, 211).ToStream(); } }); + private async Task DrawClubImage(Image img, FullUserStats stats) + { + if (!string.IsNullOrWhiteSpace(stats.User.Club?.ImageUrl)) + { + var imgUrl = stats.User.Club.ImageUrl; + try + { + var (succ, data) = await _cache.TryGetImageDataAsync(imgUrl); + if (!succ) + { + //todo make sure it's a picture + 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); + } + var toDraw = Image.Load(data); + + img.DrawImage(toDraw, + 1, + new Size(45, 45), + new Point(722, 25)); + } + catch (Exception ex) + { + _log.Warn(ex); + } + } + } + // https://github.com/SixLabors/ImageSharp/tree/master/samples/AvatarWithRoundedCorner public static void ApplyRoundedCorners(Image img, float cornerRadius) { diff --git a/src/NadekoBot/Program.cs b/src/NadekoBot/Program.cs index 6935f084..4ffebca0 100644 --- a/src/NadekoBot/Program.cs +++ b/src/NadekoBot/Program.cs @@ -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(); }