public AuctionResult(SaveAuction a) { AuctionId = a.Uuid; HighestBid = a.HighestBidAmount; ItemName = a.ItemName; End = a.End; }
public int GetOrCreateItemIdForAuction(SaveAuction auction, HypixelContext context) { var clearedName = ItemReferences.RemoveReforgesAndLevel(auction.ItemName); var tag = GetIdForName(auction.Tag ?? clearedName); if (tag != null && TagLookup.TryGetValue(tag, out int value)) { return(value); } Console.WriteLine($"Creating item {clearedName} ({auction.ItemName},{auction.Tag})"); // doesn't exist yet, create it var itemByTag = context.Items.Where(item => item.Tag == auction.Tag).FirstOrDefault(); if (itemByTag != null) { // new alternative name if (clearedName != null) { this.ReverseNames[clearedName] = auction.Tag; } TagLookup.Add(auction.Tag, itemByTag.Id); var exists = context.AltItemNames .Where(name => name.Name == clearedName && name.DBItemId == itemByTag.Id) .Any(); if (!exists) { context.AltItemNames.Add(new AlternativeName() { DBItemId = itemByTag.Id, Name = clearedName }); } return(itemByTag.Id); } Console.WriteLine($"!! completely new !! {JsonConvert.SerializeObject(auction)}"); // new Item //var tempAuction = new Hypixel.NET.SkyblockApi.Auction(){Category=auction.Category,}; //AddNewItem(tempAuction,auction.ItemName,auction.Tag,null); var item = new DBItem() { Tag = auction.Tag, Name = auction.ItemName, Names = new List <AlternativeName>() { new AlternativeName() { Name = auction.ItemName } } }; if (item.Tag == null) { // unindexable item return(MAX_MEDIUM_INT); } ToFillDetails[item.Tag] = item; return(AddItemToDB(item)); //throw new CoflnetException("can_add","can't add this item"); }
private static void NumberAuction(HypixelContext context, SaveAuction auction) { auction.SellerId = GetOrCreatePlayerId(context, auction.AuctioneerId); if (auction.SellerId == 0) { // his player has not yet received his number return; } if (auction.ItemId == 0) { var id = ItemDetails.Instance.GetOrCreateItemIdForAuction(auction, context); auction.ItemId = id; foreach (var enchant in auction.Enchantments) { enchant.ItemType = auction.ItemId; } } context.Auctions.Update(auction); }
private static void WaitForDatabaseCreation() { try { using (var context = new HypixelContext()) { try { var testAuction = new SaveAuction() { Uuid = "00000000000000000000000000000000" }; context.Auctions.Add(testAuction); context.SaveChanges(); context.Auctions.Remove(testAuction); context.SaveChanges(); } catch (Exception) { // looks like db doesn't exist yet Console.WriteLine("Waiting for db creating in the background"); System.Threading.Thread.Sleep(10000); } // TODO: switch to .Migrate() context.Database.Migrate(); } } catch (Exception e) { Console.WriteLine($"Waiting for db creating in the background {e.Message} {e.InnerException?.Message}"); System.Threading.Thread.Sleep(10000); } }
private static void MigrateAuction(SaveAuction auction) { if (auction.Reforge == ItemReferences.Reforge.Migration) { auction.Reforge = ItemReferences.Reforge.Unknown; } }
public void Outbid(SubscribeItem sub, SaveAuction auction, SaveBids bid) { var outBidBy = auction.HighestBidAmount - bid.Amount; var text = $"You were outbid on {auction.ItemName} by {PlayerSearch.Instance.GetNameWithCache(auction.Bids.FirstOrDefault().Bidder)} by {outBidBy}"; Task.Run(() => Send(sub.UserId, "Outbid", text, AuctionUrl(auction), ItemIconUrl(auction.Tag), FormatAuction(auction))).ConfigureAwait(false); }
private static void AddToQueue(SaveAuction auction) { auctionsQueue.Enqueue(auction); if (QueueCount > MAX_QUEUE_SIZE) { PersistQueueBatch(); } }
public void PushOrIgnore(SaveAuction auction) { NotifyChange(auction.Uuid, auction); NotifyChange(auction.AuctioneerId, auction); foreach (var bids in auction.Bids) { NotifyChange(bids.Bidder, auction); } }
public AuctionResult(SaveAuction a) { AuctionId = a.Uuid; HighestBid = a.HighestBidAmount; ItemName = a.ItemName; End = a.End; Tag = a.Tag; StartingBid = a.StartingBid; Bin = a.Bin; }
public ItemIndexElement(SaveAuction auction) : this( auction.Uuid, auction.End, auction.HighestBidAmount, ItemReferences.GetReforges(auction.ItemName), auction.Enchantments, auction.Count, (short)auction.Bids.Count) { }
private static int DetermineWorth(int c, SaveAuction auction) { var price = auction.HighestBidAmount == 0 ? auction.StartingBid : auction.HighestBidAmount; if (price > 500_000) { return(c + 1); } return(c - 20); }
private static BidResult NewBidResult(SaveAuction a, SaveBids highestOwn) { return(new BidResult() { AuctionId = a.Uuid, HighestBid = a.Bids.Last().Amount, HighestOwnBid = highestOwn.Amount, ItemName = a.ItemName, End = a.End }); }
private static AveragePrice AverageFromAuction(SaveAuction auction) { return(new AveragePrice() { Avg = auction.HighestBidAmount, Date = auction.End, Volume = auction.Count, Min = auction.HighestBidAmount, Max = auction.HighestBidAmount, ItemId = auction.ItemId }); }
public static void FillDetails(SaveAuction auction, string itemBytes) { var f = File(Convert.FromBase64String(itemBytes)); var a = f.RootTag.ToString(); auction.Tag = ItemID(f).Truncate(40); auction.Enchantments = Enchantments(f); auction.AnvilUses = AnvilUses(f); auction.Count = Count(f); auction.ItemCreatedAt = GetDateTime(f); auction.Reforge = GetReforge(f); auction.NbtData = new NbtData(f); }
/// <summary> /// Called from <see cref="BinUpdater"/> /// </summary> /// <param name="auction"></param> public void BinSold(SaveAuction auction) { var key = auction.AuctioneerId; NotifyIfExisting(this.Sold, key, sub => { NotificationService.Instance.Sold(sub, auction); }); NotifyIfExisting(this.AuctionSub, auction.Uuid, sub => { NotificationService.Instance.AuctionOver(sub, auction); }); }
public BidResult(SaveAuction a, string userUuid) { var highestOwn = a.Bids?.Where(bid => bid.Bidder == userUuid) .OrderByDescending(bid => bid.Amount).FirstOrDefault(); AuctionId = a.Uuid; if (a.Bids != null) { HighestBid = a.Bids.Last().Amount; } if (highestOwn != null) { HighestOwnBid = highestOwn.Amount; } ItemName = a.ItemName; End = a.End; Tag = a.Tag; }
public static void GrabAuctions(HypixelApi hypixelApi) { var expired = hypixelApi.getAuctionsEnded(); var auctions = expired.Auctions.Select(item => { var a = new SaveAuction() { Uuid = item.Uuid, AuctioneerId = item.Seller, Bids = new List <SaveBids>() { new SaveBids() { Amount = item.Price, Bidder = item.Buyer, Timestamp = item.TimeStamp, ProfileId = "unknown" } }, HighestBidAmount = item.Price, Bin = item.BuyItemNow, End = DateTime.Now, UId = AuctionService.Instance.GetId(item.Uuid) }; NBT.FillDetails(a, item.ItemBytes); return(a); }).ToList(); SoldLastMin = auctions; Indexer.AddToQueue(auctions); Task.Run(() => { foreach (var item in auctions) { SubscribeEngine.Instance.BinSold(item); Flipper.FlipperEngine.Instance.AuctionSold(item); } }).ConfigureAwait(false); Console.WriteLine($"Updated {expired.Auctions.Count} bin sells eg {expired.Auctions.First().Uuid}"); }
/// <summary> /// Called from the <see cref="Indexer"/> /// </summary> /// <param name="auction"></param> public void NewBids(SaveAuction auction) { foreach (var bid in auction.Bids.OrderByDescending(b => b.Amount).Skip(1)) { NotifyIfExisting(this.outbid, bid.Bidder, sub => { NotificationService.Instance.Outbid(sub, auction, bid); }); } NotifyIfExisting(this.AuctionSub, auction.Uuid, sub => { NotificationService.Instance.NewBid(sub, auction, auction.Bids.OrderBy(b => b.Amount).Last()); }); foreach (var bid in auction.Bids) { NotifyIfExisting(UserAuction, bid.Bidder, sub => { sub.NotifyAuction(auction); }); } }
/// <summary> /// Called from <see cref="Updater"/> /// </summary> /// <param name="auction"></param> public void NewAuction(SaveAuction auction) { if (this.PriceUpdate.TryGetValue(auction.Tag, out ConcurrentBag <SubscribeItem> subscribers)) { foreach (var item in subscribers) { if ((auction.StartingBid < item.Price && item.Type.HasFlag(SubscribeItem.SubType.PRICE_LOWER_THAN) || auction.StartingBid > item.Price && item.Type.HasFlag(SubscribeItem.SubType.PRICE_HIGHER_THAN)) && (!item.Type.HasFlag(SubscribeItem.SubType.BIN) || auction.Bin)) { NotificationService.Instance.AuctionPriceAlert(item, auction); } } } if (this.UserAuction.TryGetValue(auction.AuctioneerId, out subscribers)) { foreach (var item in subscribers) { item.NotifyAuction(auction); } } }
private static void UpdateAuction(HypixelContext context, BidComparer comparer, SaveAuction auction, SaveAuction dbauction) { if (auction.AuctioneerId == null) { // an ended auction dbauction.End = auction.End; context.Auctions.Update(dbauction); return; } SubscribeEngine.Instance.NewBids(auction); foreach (var bid in auction.Bids) { bid.Auction = dbauction; if (!dbauction.Bids.Contains(bid, comparer)) { context.Bids.Add(bid); dbauction.HighestBidAmount = auction.HighestBidAmount; } } if (auction.Bin) { dbauction.Bin = true; } if (dbauction.ItemName == null) { dbauction.ItemName = auction.ItemName; } if (dbauction.ProfileId == null) { dbauction.ProfileId = auction.ProfileId; } if (dbauction.Start == default(DateTime)) { dbauction.Start = auction.Start; } dbauction.End = auction.End; if (dbauction.Category == Category.UNKNOWN) { dbauction.Category = auction.Category; } // update context.Auctions.Update(dbauction); }
internal void Sold(SubscribeItem sub, SaveAuction auction) { var text = $"{auction.ItemName} was sold to {PlayerSearch.Instance.GetNameWithCache(auction.Bids.FirstOrDefault().Bidder)} for {auction.HighestBidAmount}"; Task.Run(() => Send(sub.UserId, "Item Sold", text, AuctionUrl(auction), ItemIconUrl(auction.Tag), FormatAuction(auction))).ConfigureAwait(false); }
public void AddNew(SaveAuction auction) { AddNew(AverageFromAuction(auction)); }
private static SaveBids FindHighestOwnBid(Player databaseResult, SaveAuction a) { return(a.Bids.Where(bid => bid.Bidder == databaseResult.UuId) .OrderByDescending(bid => bid.Amount).FirstOrDefault()); }
public void NewBid(SubscribeItem sub, SaveAuction auction, SaveBids bid) { var text = $"New bid on {auction.ItemName} by {PlayerSearch.Instance.GetNameWithCache(auction.Bids.FirstOrDefault().Bidder)} for {auction.HighestBidAmount}"; Task.Run(() => Send(sub.UserId, "New bid", text, AuctionUrl(auction), ItemIconUrl(auction.Tag), auction)).ConfigureAwait(false); }
public override async void NotifyAuction(SaveAuction auction) { OnNewAuction(auction); if (this.GeneratedAt < DateTime.Now - TimeSpan.FromMinutes(10)) await SubscribeEngine.Instance.Unsubscribe(this.UserId, this.TopicId, this.Type); }
internal void AuctionOver(SubscribeItem sub, SaveAuction auction) { var text = $"Highest bid is {auction.HighestBidAmount}"; Task.Run(() => Send(sub.UserId, $"Auction for {auction.ItemName} ended", text, AuctionUrl(auction), ItemIconUrl(auction.Tag), FormatAuction(auction))).ConfigureAwait(false); }
// builds the index for all auctions in the last hour Task <int> Save(GetAuctionPage res, DateTime lastUpdate, ConcurrentDictionary <string, bool> activeUuids) { int count = 0; var processed = res.Auctions.Where(item => { activeUuids[item.Uuid] = true; // nothing changed if the last bid is older than the last update return(!(item.Bids.Count > 0 && item.Bids[item.Bids.Count - 1].Timestamp < lastUpdate || item.Bids.Count == 0 && item.Start < lastUpdate)); }) .Select(a => { if (Program.Migrated) { ItemDetails.Instance.AddOrIgnoreDetails(a); } count++; var auction = new SaveAuction(a); return(auction); }).ToList(); if (DateTime.Now.Minute % 30 == 7) { foreach (var a in res.Auctions) { var auction = new SaveAuction(a); AuctionCount.AddOrUpdate(auction.Tag, k => { return(DetermineWorth(0, auction)); }, (k, c) => { return(DetermineWorth(c, auction)); }); } } var ended = res.Auctions.Where(a => a.End < DateTime.Now).Select(a => new SaveAuction(a)); /* var variableHereToRemoveWarning = taskFactory.StartNew(async () => * { * await Task.Delay(TimeSpan.FromSeconds(20)); * await ItemPrices.Instance.AddEndedAuctions(ended); * });*/ if (Program.FullServerMode) { Indexer.AddToQueue(processed); } else { FileController.SaveAs($"apull/{DateTime.Now.Ticks}", processed); } var started = processed.Where(a => a.Start > lastUpdate).ToList(); // do not slow down the update var min = DateTime.Now - TimeSpan.FromMinutes(15); Flipper.FlipperEngine.Instance.NewAuctions(started.Where(a => a.Start > min)); foreach (var auction in started) { SubscribeEngine.Instance.NewAuction(auction); } return(Task.FromResult(count)); }
string AuctionUrl(SaveAuction auction) { return(BaseUrl + "/auction/" + auction.Uuid); }
private object FormatAuction(SaveAuction auction) { return(new { type = "auction", auction = JsonConvert.SerializeObject(auction) }); }
internal void AuctionPriceAlert(SubscribeItem sub, SaveAuction auction) { var text = $"New Auction for {auction.ItemName} for {auction.StartingBid}"; Task.Run(() => Send(sub.UserId, $"Price Alert", text, AuctionUrl(auction), ItemIconUrl(auction.Tag), FormatAuction(auction))).ConfigureAwait(false); }