Пример #1
0
 private static bool CheckChallengeComplete(AdventureContext adventureContext, Challenge challenge, User user)
 {
     return adventureContext
         .UserChallenges
         .Count(u =>
             u.ChallengeId == challenge.ChallengeId &&
             u.UserId == user.UserId &&
             u.IsComplete) >= 1;
 }
Пример #2
0
 public static void CompleteChallenge(Challenge challenge, User user, Tweet tweet, AdventureContext adventureContext)
 {
     var userChallenge = new UserChallenge
     {
         ChallengeId = challenge.ChallengeId,
         UserId = user.UserId,
         IsComplete = true
     };
     adventureContext.UserChallenges.Add(userChallenge);
     adventureContext.SaveChanges();
     TwitterResponder.SendMoreInfo( user.ScreenName, challenge, tweet.TweetId_num);
     new BadgeFinder(adventureContext).VerifyBadges(user.UserId);
 }
        public static void DetermineContent(Tweet tweet, Challenge challenge, User user, AdventureContext adventureContext)
        {
            // Is image?
            if (tweet.Media.FirstOrDefault() != null && challenge.Type.ToLower() == "image")
            {
                TweetParser.CompleteChallenge(challenge, user, tweet, adventureContext);
            }
            // Is URL?
            else if (tweet.Urls.Any())
            {
                var youtubeTest = new Regex("(https?://)?(www\\.)?(yotu\\.be/|youtube\\.com/)?((.+/)?(watch(\\?v=|.+&v=))?(v=)?)([\\w_-]{11})(&.+)?");
                var instagramTest = new Regex(@"http://instagr\.?am(?:\.com)?/\S*");
                var vineTest = new Regex(@"https://vine.co/v/\w*$@i");
                var soundcloudTest = new Regex(@"(https?://)?(www\\.)?( soundcloud.com | snd.sc )(.)");

                if (youtubeTest.IsMatch(tweet.Urls.Any().ToString()) && (challenge.Type.ToLower() == "video" | challenge.Type.ToLower() == "audio"))
                {
                    TweetParser.CompleteChallenge(challenge, user, tweet, adventureContext);
                }
                if (instagramTest.IsMatch(tweet.Urls.Any().ToString()) && challenge.Type.ToLower() == "image")
                {
                    TweetParser.CompleteChallenge(challenge, user, tweet, adventureContext);

                }
                if (vineTest.IsMatch(tweet.Urls.Any().ToString()) && challenge.Type.ToLower() == "video")
                {
                    TweetParser.CompleteChallenge(challenge, user, tweet, adventureContext);
                }

            }
            // Is text response
            else if (challenge.Type != null && challenge.Type.ToLower() == "text")
            {
                tweet.Text = StripContent(tweet);

                TweetParser.CompleteChallenge(challenge, user, tweet, adventureContext);
            }
        }
Пример #4
0
 private static User NewUser(Tweet twitterMessage)
 {
     var newUser = new User
     {
         TwitterId = twitterMessage.TwitterUserIdentifier,
         UserName = twitterMessage.UserName,
         ScreenName = twitterMessage.ScreenName
     };
     var adventureContext = new AdventureContext();
     adventureContext.Users.Add(newUser);
     adventureContext.SaveChanges();
     return newUser;
 }