Exemple #1
0
 IEnumerable <TwitterUser> GetUserNamesFromMessage(string message, ITwitterNotifierSprocketRepository _database)
 {
     return(_usernameMatchRegex.Matches(message)
            .Cast <Match>()
            .Select(g =>
                    new TwitterUser()
     {
         ScreenName = _database.FetchOrCreateUser(g.Value.Replace("@", "")).TwitterUserName
     })
            .Where(v => !String.IsNullOrEmpty(v.ScreenName)));
 }
 private void InviteUserIfNeccessary(string forUser, IBot bot, ITwitterNotifierSprocketRepository _database)
 {
     var user = _database.FetchOrCreateUser(forUser);
     if (String.IsNullOrWhiteSpace(user.TwitterUserName) &&
         !user.DisableInvites
         && (DateTime.Now - user.LastInviteDate).TotalDays > 1)
     {
         bot.PrivateReply(forUser, "If you're using Twitter, I can notify you when you're mentioned and away.");
         bot.PrivateReply(forUser, "-- to tell me your Twitter user name use: @twitterbot? twittername [your-twitter-username]");
         bot.PrivateReply(forUser, "-- to prevent me from reminding you about this: @twitterbot? disableinvite");
         user.LastInviteDate = DateTime.Now;
         _database.SaveChanges();
     }
 }
Exemple #3
0
        private void InviteUserIfNeccessary(string forUser, IBot bot, ITwitterNotifierSprocketRepository _database)
        {
            var user = _database.FetchOrCreateUser(forUser);

            if (String.IsNullOrWhiteSpace(user.TwitterUserName) &&
                !user.DisableInvites &&
                (DateTime.Now - user.LastInviteDate).TotalDays > 1)
            {
                bot.PrivateReply(forUser, "If you're using Twitter, I can notify you when you're mentioned and away.");
                bot.PrivateReply(forUser, "-- to tell me your Twitter user name use: @twitterbot? twittername [your-twitter-username]");
                bot.PrivateReply(forUser, "-- to prevent me from reminding you about this: @twitterbot? disableinvite");
                user.LastInviteDate = DateTime.Now;
                _database.SaveChanges();
            }
        }
Exemple #4
0
        private bool ShouldNotifyUser(string UserName, ITwitterNotifierSprocketRepository _database)
        {
            //TODO: once we figure out why notifications seem low, refactor this debug code out
            Console.Write("Should Notify User {0}? ", UserName);
            var user = _database.FetchOrCreateUser(UserName);

            if (user.EnableNotifications)
            {
                if ((DateTime.Now - user.LastNotification).TotalMinutes > 60)
                {
                    Console.Write("1 hour check passed, ");
                    if ((DateTime.Now - user.LastActivity).TotalMinutes > 5)
                    {
                        Console.WriteLine("5 minute activity check passed, all passed.");
                        return(true);
                    }
                    else
                    {
                        Console.WriteLine("5 minute activity check failed, ");
                    }
                }
                else
                {
                    Console.Write("1 hour check failed, ");
                }
            }
            else
            {
                Console.Write("Notifications are disabled, ");
            }
            Console.WriteLine("Not notifying");
            return(false);

            return(user.EnableNotifications &&
                   (
                       (DateTime.Now - user.LastNotification).TotalMinutes >= 60 &&
                       (DateTime.Now - user.LastActivity).TotalMinutes > 5));
        }
 IEnumerable<TwitterUser> GetUserNamesFromMessage(string message, ITwitterNotifierSprocketRepository _database)
 {
     return _usernameMatchRegex.Matches(message)
                         .Cast<Match>()
                         .Select(g =>
                             new TwitterUser()
                             {
                                 ScreenName = _database.FetchOrCreateUser(g.Value.Replace("@", "")).TwitterUserName
                             })
                         .Where(v => !String.IsNullOrEmpty(v.ScreenName));
 }
 private bool ShouldNotifyUser(string UserName, ITwitterNotifierSprocketRepository _database)
 {
     //TODO: once we figure out why notifications seem low, refactor this debug code out
     Console.Write("Should Notify User {0}? ", UserName);
     var user = _database.FetchOrCreateUser(UserName);
     if (user.EnableNotifications)
     {
         if ((DateTime.Now - user.LastNotification).TotalMinutes > 60)
         {
             Console.Write("1 hour check passed, ");
             if ((DateTime.Now - user.LastActivity).TotalMinutes > 5)
             {
                 Console.WriteLine("5 minute activity check passed, all passed.");
                 return true;
             }
             else
             {
                 Console.WriteLine("5 minute activity check failed, ");
             }
         }
         else
         {
             Console.Write("1 hour check failed, ");
         }
     }
     else
     {
         Console.Write("Notifications are disabled, ");
     }
     Console.WriteLine("Not notifying");
     return false;
     return (user.EnableNotifications &&
         (
             (DateTime.Now - user.LastNotification).TotalMinutes >= 60 &&
         (DateTime.Now - user.LastActivity).TotalMinutes > 5));
 }