Beispiel #1
0
        public async Task <List <TradeBait> > GetNewTradeBait()
        {
            // TODO: maybe instead of this process, just post a message saying there has been new trade bait and that you can message to see what it is

            var deserializer = new JsonResponseDeserializer();
            var info         = new ResponseDeserializerInfo();
            var res          = await _mfl.GetTradeBait();

            var jsonString = await res.Content.ReadAsStringAsync();

            try //Single
            {
                var tradeSingle = deserializer.Deserialize <TradeBaitParent>(jsonString, res, info).TradeBaits.tradeBait;
                return(new List <TradeBait> {
                    tradeSingle
                });
            }
            catch (Exception) { Console.WriteLine("not a single trade"); }

            try //multi
            {
                return(deserializer.Deserialize <TradeBaitsParent>(jsonString, res, info).tradeBaits.tradeBait);
            }
            catch (Exception) { return(null); }
        }
 public async Task <List <TradeBait> > GetNewTradeBait()
 {
     // TODO: maybe instead of this process, just post a message saying there has been new trade bait and that you can message to see what it is
     try //multi
     {
         return((await _mfl.GetTradeBait()).tradeBaits.tradeBait);
     }
     catch (Exception) { return(null); }
 }
        public async Task PostTradeRumor()
        {
            var deserializer = new JsonResponseDeserializer();
            var info         = new ResponseDeserializerInfo();
            var res          = await _mfl.GetTradeBait();

            var strForBot  = "";
            var jsonString = await res.Content.ReadAsStringAsync();

            try
            {
                var tradeBait = deserializer.Deserialize <TradeBaitParent>(jsonString, res, info).tradeBaits.tradeBait;
                strForBot += _rumor.GetSources();
                owners.TryGetValue(Int32.Parse(tradeBait.franchise_id), out var ownerName);
                strForBot += $"{ownerName} ";
                // check if this is a new post or not.
                var postDate = DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64(tradeBait.timestamp));
                if (postDate < DateTime.Now.AddMinutes(-11))
                {
                    return;
                }
                // add verbiage
                strForBot += _rumor.AddBaitAction();
                var hasEarlyPicks   = _rumor.CheckForFirstRounders(tradeBait.willGiveUp);
                var multiplePlayers = _rumor.CheckForMultiplePlayers(tradeBait.willGiveUp);
                if (multiplePlayers)
                {
                    var players = (await _mfl.GetPlayersDetails(tradeBait.willGiveUp)).players.player;
                    strForBot += _rumor.ListPlayers(players, hasEarlyPicks);
                }
                else
                {
                    var player = (await _mfl.GetPlayerDetails(tradeBait.willGiveUp)).players.player;
                    strForBot += _rumor.ListPlayer(player, hasEarlyPicks);
                }
                await BotPost(strForBot);

                return;
            }
            catch (Exception e) { Console.WriteLine("not a single trade"); }
            try
            {
                var tradeBaits = deserializer.Deserialize <TradeBaitsParent>(jsonString, res, info).tradeBaits.tradeBait;
                foreach (var post in tradeBaits)
                {
                    var postDate = DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64(post.timestamp));
                    if (postDate > DateTime.Now.AddDays(-1))
                    {
                        strForBot += _rumor.GetSources();
                        owners.TryGetValue(Int32.Parse(post.franchise_id), out var ownerName);
                        strForBot += $"{ownerName} ";
                        strForBot += _rumor.AddBaitAction();  // add verbage
                        var hasEarlyPicks = _rumor.CheckForFirstRounders(post.willGiveUp);
                        if (_rumor.CheckForMultiplePlayers(post.willGiveUp))
                        {
                            var players = (await _mfl.GetPlayersDetails(post.willGiveUp)).players.player;
                            strForBot += _rumor.ListPlayers(players, hasEarlyPicks);
                        }
                        else
                        {
                            var player = (await _mfl.GetPlayerDetails(post.willGiveUp)).players.player;
                            strForBot += _rumor.ListPlayer(player, hasEarlyPicks);
                        }
                        await BotPost(strForBot);
                    }
                }
            }
            catch (Exception e) { Console.WriteLine("not a multi trade"); }
        }