示例#1
0
        public async Task AddFavoriteHero(HeroDetails hero)
        {
            HeroFavorite tmpHero = new HeroFavorite
            {
                Id        = hero.Id,
                Name      = hero.Name,
                Thumbnail = hero.Thumbnail.FullPath
            };

            Db.Insert(tmpHero);
        }
        public async Task <string> ProcessAsync(DiscordMessage message)
        {
            string url        = $"players/{message.Author.SteamId()}/heroes?limit={_matchesLimit}&having={_havingAtleastMatches}";
            var    jsonString = await NetComm.GetResponseOfURL(url);

            var        heroDetails    = JsonToFrom.Deserialize <dynamic>(jsonString);
            List <int> randomedHeroId = GetRandomedHeroIds(heroDetails);

            string toReturn = string.Empty;

            toReturn += $"<@{message.Author.Id}> Here are some recent heroes which you have played:\n";
            for (int i = 0; i < randomedHeroId.Count; i += _delimiter)
            {
                toReturn += '`';
                for (int j = i; j < i + _delimiter && j < randomedHeroId.Count; j++)
                {
                    string currentHeroName = HeroDetails.GetHeroById(randomedHeroId[j]).localized_name;
                    toReturn += $"{currentHeroName}" + GetSpacesForHeroName(currentHeroName);
                }
                toReturn += "`\n";
            }

            return(toReturn);
        }
示例#3
0
        public static HeroDetails ParseDetails(string HTMLHero)
        {
            HeroDetails hd = new HeroDetails(temp);

            try
            {
                CQ   cq = CQ.Create(HTMLHero);
                bool state;

                string buff = cq.Find(Selectors.GetDataSelector(4)).Elements.First().InnerText.Replace("\n", "");
                hd.Date = DateTime.Parse(buff);

                buff     = cq.Find(Selectors.GetDataSelector(5)).Elements.First().InnerText.Replace("\n", "");
                hd.Price = Int32.Parse(buff);

                hd.Title = cq.Find(Selectors.GetDataSelector(6)).Elements.First().InnerText.Replace("\n", "");

                buff  = cq.Find(Selectors.GetDataSelector(8)).Elements.First().InnerText.Replace("\n", "");
                state = Enum.TryParse(buff, out Franchise Fresult);
                if (state == false)
                {
                    Fresult = Franchise.Unknown;
                }
                hd.Franchise = Fresult;

                hd.Info = cq.Find(Selectors.GetDataSelector(9)).Elements.First().InnerHTML.Replace("\n", "");

                hd.Lore = cq.Find(Selectors.GetDataSelector(10)).Elements.First().InnerText.Replace("\n", "");

                buff  = cq.Find(Selectors.GetDataSelector(11)).Elements.First().InnerText.Replace("\n", "");
                state = Enum.TryParse(buff, out Difficulty Dresult);
                if (state == false)
                {
                    Dresult = Difficulty.Unknown;
                }
                hd.Difficulty = Dresult;

                if (hd.Franchise == Franchise.Vikings)
                {
                    return(hd);
                }
                if (Heroes.Find(temp).Name == "Greymane")
                {
                    Hero GreyCustom = new Hero(-1, "Greymane_(Human)", 0, 0);
                    Caching(GreyCustom);
                    string HTMLCustom = File.ReadAllText($"./Cache/{GreyCustom.Name}.html", Encoding.Default);
                    cq = CQ.Create(HTMLCustom);
                }
                if (Heroes.Find(temp).Name == "D.Va")
                {
                    Hero GreyCustom = new Hero(-1, "D.Va_(Pilot)", 0, 0);
                    Caching(GreyCustom);
                    string HTMLCustom = File.ReadAllText($"./Cache/{GreyCustom.Name}.html", Encoding.Default);
                    cq = CQ.Create(HTMLCustom);
                }

                buff     = cq.Find(Selectors.GetDataSelector(12)).Elements.First().InnerText.Replace("\n", "");
                hd.Melee = Boolean.Parse(buff);

                buff      = cq.Find(Selectors.GetDataSelector(13)).Elements.First().InnerText.Replace("\n", "").Replace(",", "");
                hd.Health = Int32.Parse(buff);

                buff           = cq.Find(Selectors.GetDataSelector(14)).Elements.First().InnerText.Replace("\n", "");
                hd.HealthRegen = buff.DoubleParseAdvanced();

                buff        = cq.Find(Selectors.GetDataSelector(15)).Elements.First().InnerText.Replace("\n", "");
                hd.Resource = Int32.Parse(buff);

                buff  = cq.Find(Selectors.GetDataSelector(16)).Elements.First().InnerText.Replace("\n", "");
                state = Enum.TryParse(buff, out ResourceType RTresult);
                if (state == false)
                {
                    RTresult = ResourceType.Unknown;
                }
                hd.ResourceType = RTresult;


                buff = cq.Find(Selectors.GetDataSelector(17)).Elements.First().InnerText.Replace("\n", "");
                if (buff.Contains("Spell"))
                {
                    var buff2 = buff.Split(new string[] { "Spell" }, StringSplitOptions.RemoveEmptyEntries)[0];
                    hd.SpellArmor = Int32.Parse(buff2);
                }

                if (buff.Contains("Physical"))
                {
                    buff             = buff.Split(new string[] { "Physical" }, StringSplitOptions.RemoveEmptyEntries)[0];
                    hd.PhysicalArmor = Int32.Parse(buff);
                }


                buff           = cq.Find(Selectors.GetDataSelector(18)).Elements.First().InnerText.Replace("\n", "");
                hd.AttackSpeed = buff.DoubleParseAdvanced();

                buff           = cq.Find(Selectors.GetDataSelector(19)).Elements.First().InnerText.Replace("\n", "");
                hd.AttackRange = buff.DoubleParseAdvanced();

                buff            = cq.Find(Selectors.GetDataSelector(20)).Elements.First().InnerText.Replace("\n", "");
                hd.AttackDamage = Int32.Parse(buff);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(hd);
        }
示例#4
0
 public async Task RemoveFavoriteHero(HeroDetails hero)
 {
     Db.Delete <HeroFavorite>(hero.Id);
 }