Exemplo n.º 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;
 }
Exemplo n.º 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);
 }
Exemplo n.º 3
0
        public static void SaveNewResponse(AdventureContext adventureContext, Tweet tweet, Challenge challenge)
        {
            var user = adventureContext.Users
                .First(u => u.TwitterId == tweet.TwitterUserIdentifier);

            var response = new Response
                           {
                               UserId = user.UserId,
                               Tweet = tweet.Text,
                               TweetId = tweet.TweetId,
                               ChallengeId = challenge.ChallengeId
                           };
            adventureContext.Responses.Add(response);
            adventureContext.SaveChanges();
        }
        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);
            }
        }
Exemplo n.º 5
0
 public static void SendMoreInfo( string twitterUser, Challenge challenge, ulong replyId )
 {
     var twitterContext = new TwitterContext( TwitterHashtagMonitor.Authorizer );
     var tweet = string.Format( "@{0} Congratulations! You earned {1} points, find out more about today's challenge at http://adventure-1.apphb.com/#/day/{2}/more", twitterUser, challenge.Value, challenge.ChallengeNumber );
     Task.FromResult( twitterContext.ReplyAsync( replyId, tweet ) );
 }