public static async Task CreateAva(int id) { var ava = new AvastarObject(); ava.id = id; string metadatastr = ""; using (System.Net.WebClient wc = new System.Net.WebClient()) { try { metadatastr = await wc.DownloadStringTaskAsync("https://avastars.io/metadata/" + id.ToString()); } catch (Exception e) { Console.WriteLine(e.Message); } } if (metadatastr.StartsWith("Invalid")) { return; } var traitJson = JObject.Parse(DiscordKeyGetter.GetFileData("app/create-traits-nosvg.json")); var metadataJson = JObject.Parse(metadatastr); ava.id = id; ava.Gender = (string)metadataJson["attributes"][0]["value"]; ava.Score = (int)metadataJson["attributes"][5]["value"]; ava.traits = new Dictionary <string, string>(); for (int i = 7; i < 19; i++) { ava.traits.Add((string)metadataJson["attributes"][i]["trait_type"], (string)metadataJson["attributes"][i]["value"]); } var disp = AvastarCommands.ReturnTraitDisparity(metadataJson, traitJson); ava.Owner = ""; ava.RarityDistribution = new Dictionary <string, int>(); ava.RarityDistribution.Add("Common", disp[0]); ava.RarityDistribution.Add("Uncommon", disp[1]); ava.RarityDistribution.Add("Rare", disp[2]); ava.RarityDistribution.Add("Epic", disp[3]); ava.RarityDistribution.Add("Legendary", disp[4]); ava.FillTraitDictionary(traitJson, metadataJson); var collec = DatabaseConnection.GetDb().GetCollection <AvastarObject>("AvastarCollection"); await collec.InsertOneAsync(ava); var ub2List = await UB2Object.UpdateUb2List(ava); var ub3List = await UB3Object.UpdateUb3List(ava); await AvaUBObject.UpdateAvaUbList(ava, ub2List, ub3List); }
public static async Task MigrateAva(int id) { var oldAva = await AvastarObject.GetAva(id); var ava = new AvastarObject(); ava.id = oldAva.id; ava.Gender = oldAva.Gender; ava.Score = oldAva.Score; ava.traits = oldAva.traits; ava.Owner = "";// await Blockchain.ChainWatcher.GetOwnerOf(id); ava.TraitsRarity = new Dictionary <string, string>(); var traitJson = JObject.Parse(DiscordKeyGetter.GetFileData("app/create-traits-nosvg.json")); foreach (var pair in ava.traits) { var traitType = pair.Key; var traitName = pair.Value; var traitRarity = ""; var traitTypeName = AvastarCommands.Capitalise(traitType.Replace('_', ' ')); foreach (var trait in traitJson[traitTypeName]) { if (trait.Type == JTokenType.Null) { continue; } if ((string)trait["name"] == traitName) { traitRarity = (string)trait["rarity"]; break; } } ava.TraitsRarity.Add(traitType, traitRarity); } ava.RarityDistribution = new Dictionary <string, int>(); ava.RarityDistribution.Add("Common", 0); ava.RarityDistribution.Add("Uncommon", 0); ava.RarityDistribution.Add("Rare", 0); ava.RarityDistribution.Add("Epic", 0); ava.RarityDistribution.Add("Legendary", 0); foreach (var pair in ava.TraitsRarity) { switch (pair.Value) { case "Common": ava.RarityDistribution["Common"]++; break; case "Uncommon": ava.RarityDistribution["Uncommon"]++; break; case "Rare": ava.RarityDistribution["Rare"]++; break; case "Epic": ava.RarityDistribution["Epic"]++; break; case "Legendary": ava.RarityDistribution["Legendary"]++; break; } } var collec = DatabaseConnection.GetDb().GetCollection <AvastarObject>("AvastarCollection"); await collec.ReplaceOneAsync(a => a.id == id, ava); }