public Stream GetColorList(SCurrency currency) { using (var image = _img.GetFColorsView(currency)) { return(image.ToPngStream()); } }
public static int Price(this FColor color, SCurrency currency) { if (color == FColor.CleanColor) { return(0); } if (currency == SCurrency.Sc) { return(30000); } switch (color) { case FColor.DefinitelyNotWhite: return(400); default: return(800); } }
public async Task ToggleColorRoleAsync([Summary("kolor z listy(brak - lista)")] FColor color = FColor.None, [Summary("waluta(SC/TC)")] SCurrency currency = SCurrency.Tc) { var user = Context.User as SocketGuildUser; if (user == null) { return; } if (color == FColor.None) { using (var img = _profile.GetColorList(currency)) { await Context.Channel.SendFileAsync(img, "list.png"); return; } } using (var db = new Database.UserContext(Config)) { var botuser = await db.GetUserOrCreateAsync(user.Id); var points = currency == SCurrency.Tc ? botuser.TcCnt : botuser.ScCnt; if (points < color.Price(currency)) { await ReplyAsync("", embed : $"{user.Mention} nie posiadasz wystarczającej liczby {currency.ToString().ToUpper()}!".ToEmbedMessage(EMType.Error).Build()); return; } var colort = botuser.TimeStatuses.FirstOrDefault(x => x.Type == Database.Models.StatusType.Color && x.Guild == Context.Guild.Id); if (colort == null) { colort = new Database.Models.TimeStatus { Type = Database.Models.StatusType.Color, Guild = Context.Guild.Id, EndsAt = DateTime.Now, }; botuser.TimeStatuses.Add(colort); } await _profile.RomoveUserColorAsync(user); if (color == FColor.CleanColor) { colort.EndsAt = DateTime.Now; } else { using (var cdb = new Database.GuildConfigContext(Config)) { var gConfig = await cdb.GetCachedGuildFullConfigAsync(Context.Guild.Id); if (!await _profile.SetUserColorAsync(user, gConfig.AdminRole, color)) { await ReplyAsync("", embed : $"Coś poszło nie tak!".ToEmbedMessage(EMType.Error).Build()); return; } colort.EndsAt = colort.EndsAt.AddMonths(1); if (currency == SCurrency.Tc) { botuser.TcCnt -= color.Price(currency); } else { botuser.ScCnt -= color.Price(currency); } } } await db.SaveChangesAsync(); QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" }); await ReplyAsync("", embed : $"{user.Mention} wykupił kolor!".ToEmbedMessage(EMType.Success).Build()); } }
public Image <Rgba32> GetFColorsView(SCurrency currency) { var message = new Font(_latoRegular, 16); var firstColumnMaxLength = TextMeasurer.Measure("A", new RendererOptions(message)); var secondColumnMaxLength = TextMeasurer.Measure("A", new RendererOptions(message)); var arrayOfColours = Enum.GetValues(typeof(FColor)); var inFirstColumn = arrayOfColours.Length / 2; for (int i = 0; i < arrayOfColours.Length; i++) { var val = (uint)arrayOfColours.GetValue(i); var thisColor = (FColor)val; if (thisColor == FColor.None) { continue; } var name = $"{thisColor.ToString()} ({thisColor.Price(currency)} {currency.ToString().ToUpper()})"; var nLen = TextMeasurer.Measure(name, new RendererOptions(message)); if (i < inFirstColumn + 1) { if (firstColumnMaxLength.Width < nLen.Width) { firstColumnMaxLength = nLen; } } else { if (secondColumnMaxLength.Width < nLen.Width) { secondColumnMaxLength = nLen; } } } int posY = 5; int posX = 0; int realWidth = (int)(firstColumnMaxLength.Width + secondColumnMaxLength.Width + 20); int realHeight = (int)(firstColumnMaxLength.Height + 2) * (inFirstColumn + 1); var imgBase = new Image <Rgba32>(realWidth, realHeight); imgBase.Mutate(x => x.BackgroundColor(Rgba32.FromHex("#36393e"))); imgBase.Mutate(x => x.DrawText("Lista:", message, Rgba32.FromHex("#000000"), new Point(0, 0))); for (int i = 0; i < arrayOfColours.Length; i++) { if (inFirstColumn + 1 == i) { posY = 5; posX = (int)firstColumnMaxLength.Width + 10; } var val = (uint)arrayOfColours.GetValue(i); var thisColor = (FColor)val; if (thisColor == FColor.None) { continue; } posY += (int)firstColumnMaxLength.Height + 2; var tname = $"{thisColor.ToString()} ({thisColor.Price(currency)} {currency.ToString().ToUpper()})"; imgBase.Mutate(x => x.DrawText(tname, message, Rgba32.FromHex(val.ToString("X6")), new Point(posX, posY))); } return(imgBase); }