Exemple #1
0
        public static void Main(string[] args)
        {
            Session.Initialize();
            Session.Login();


            Session.followed   = Futil.LoadFollowers("following.log");
            Session.unfollowed = Futil.LoadFollowers("unfollowed.log");

            if (Session.followed == null)
            {
                Cutil.Line("<Main> - Initializing");
                Cutil.Line("<Main> - If are following 0 users, then this bot will not work.");
                try
                {
                    Futil.FirstRun();
                }
                catch (Exception ex)
                {
                    Cutil.Error("<Main> - " + ex.Message);
                }
            }
            else
            {
                Thread botMatrix = new Thread(BotMatrix);
                botMatrix.Start();
                Thread unfollow = new Thread(Unfollow);
                unfollow.Start();
                Thread prompts = new Thread(Prompts);
                prompts.Start();
                Thread followFriday = new Thread(FollowFriday);
                followFriday.Start();
            }
            Console.ReadLine();
        }
Exemple #2
0
        private static void Unfollow()
        {
            Cutil.Line("<Unfollow> - Start");
            while (isRunning)
            {
                int             count    = 0;
                int             interval = 60;     //60 minutes per interval
                List <Follower> tempList = new List <Follower>(Session.followed);


                foreach (Follower f in tempList)
                {
                    DateTime now = DateTime.Now;
                    double   age = (now - f.Time).TotalSeconds;
                    if (age > Session.waitTime * 86400)
                    {
                        Cutil.Line("<Unfollow> - " + f.ScreenName + " is of age." + " (" + age + ")", ConsoleColor.Cyan);
                        try
                        {
                            var friendships = Util.FindFriendship(Session.screenname, f.ScreenName);
                            count++;
                            if (count > 30)
                            {
                                Cutil.Line("<Unfollow> - Internal limit reached", ConsoleColor.DarkCyan);
                                break;
                            }
                            if (friendships != null)
                            {
                                foreach (Friendship friend in friendships.Result)
                                {
                                    if (friend.SourceRelationship.FollowedBy)
                                    {
                                        Cutil.Line("<Unfollow> - " + f.ScreenName + " follows me.", ConsoleColor.DarkCyan);
                                        Session.followed.Remove(Session.followed.SingleOrDefault(x => x.ScreenName == f.ScreenName));
                                        Futil.SaveFollowers(Session.followed, "following.log");
                                    }
                                    else
                                    {
                                        Cutil.Line("<Unfollow> - User, " + f.ScreenName + ", not followed back", ConsoleColor.DarkCyan);
                                        Futil.LogUnfollow(f.ScreenName);
                                        Util.UnfollowUserByScreenname(f.ScreenName);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Cutil.Error("<Unfollow> - " + ex.Message);
                        }
                    }
                    else
                    {
                        Cutil.Line("<Unfollow> - " + f.ScreenName + " is not of age.".PadRight(20), ConsoleColor.Cyan);
                    }
                }

                Cutil.Line("<Unfollow> - Waiting " + interval + " minutes");
                Thread.Sleep(interval * 60000);
            }
        }
Exemple #3
0
        public async static void FirstRun()
        {
            try
            {
                long cursor = -1;

                Session.followed   = new List <Follower>();
                Session.unfollowed = new List <Follower>();

                var userResponse = (from user in Session.service.User where user.Type == UserType.Lookup && user.ScreenNameList == Session.screenname select user).ToList();
                int following    = 0;
                if (userResponse != null)
                {
                    foreach (User user in userResponse)
                    {
                        following = user.FriendsCount;
                    }

                    Cutil.Line("<First Run> - Following: " + following);

                    var friendship = await(from friend in Session.service.Friendship
                                           where friend.Type == FriendshipType.FriendsList && friend.ScreenName == Session.screenname && friend.Cursor == cursor && friend.Count == following
                                           select friend).SingleOrDefaultAsync();

                    if (friendship != null && friendship.Users != null && friendship.CursorMovement != null)
                    {
                        foreach (User user in friendship.Users)
                        {
                            Cutil.Line("<First Run> - New User Discovered: " + user.ScreenNameResponse);
                            Follower f = new Follower(user.ScreenNameResponse, DateTime.Now);
                            Session.followed.Add(f);
                        }
                    }

                    SaveFollowers(Session.followed, "following.log");

                    Session.unfollowed.Add(new Follower(Session.screenname, DateTime.Now));
                    SaveFollowers(Session.unfollowed, "unfollowed.log");
                }
                else
                {
                    Cutil.Error("<First Run> - Failed, please try again");
                }
            }
            catch (Exception ex)
            {
                Cutil.Error("<First Run> - " + ex.Message);
            }
            Cutil.Line("<First Run> - Please restart");
        }
Exemple #4
0
        public static void LogUnfollow(string screenname)
        {
            try
            {
                using (StreamWriter w = File.AppendText(Session.path + "ulog.log"))
                {
                    w.WriteLine("Unfollowed: " + screenname.PadLeft(20) + " at" + DateTime.Now);
                }
            }

            catch (Exception ex)
            {
                Cutil.Error(ex.Message);
            }
        }
Exemple #5
0
        public async static void FollowUserByStatus(Status status)
        {
            try
            {
                //check if we have unfollowed them before, then abort if needed
                if (CheckUnfollowed(status))
                {
                    string screenname = status.User.ScreenNameResponse;

                    Cutil.Line("<Followe user by status> - Screenname: " + screenname + " Attempting follow.", ConsoleColor.Yellow);

                    if (FollowFilter(status))
                    {
                        //Followe user:

                        var user = await Session.service.CreateFriendshipAsync(screenname, true, default(CancellationToken));                         // <- Thats the bastard!


                        if (user != null && Session.followed.Any(x => x.ScreenName == screenname) == false)
                        {
                            Cutil.Line("<Follow user by status> - " + screenname + "success", ConsoleColor.Yellow);

                            Session.followed.Add(new Follower(screenname, DateTime.Now));
                            Futil.SaveFollowers(Session.followed, "following.log");
                        }
                        else
                        {
                            Cutil.Line("<Followuser by status> - User is null, or already followed.", ConsoleColor.Yellow);
                        }
                    }
                    else
                    {
                        Cutil.Line("<Follow user by status> - Rejected user, " + screenname + ", did not meet criteria.", ConsoleColor.DarkYellow);
                    }
                }
                else
                {
                    Cutil.Line("<Follow user by status> - Already followed and unfollowed this user: "******"<Follow user by status> - " + ex.Message);
            }
        }
Exemple #6
0
        /// <summary>
        /// Retweets the random hashtag, and returns the list of candidates as a generic list.
        /// </summary>
        public static List <Status> RetweetRandomHashtag()
        {
            Random        rnd = new Random();
            int           randomNumberHashtag = rnd.Next(0, Session.hashtags.Count);
            List <Status> tweets = Search(Session.hashtags[randomNumberHashtag]).ToList();


            if (tweets != null)
            {
                Retweet(tweets[rnd.Next(0, tweets.Count)]);
            }
            else
            {
                Cutil.Error("<Retweet random hashtag> - Tweet failed, search retruned null.");
            }

            return(tweets);
        }
Exemple #7
0
        public async static void Retweet(Status status)
        {
            Cutil.Line("<Retweet> - Retweeting: " + status.StatusID);
            try
            {
                var retweet = await Session.service.RetweetAsync(status.StatusID);

                if (retweet != null && retweet.RetweetedStatus != null && retweet.RetweetedStatus.User != null)
                {
                    Cutil.Line("<Retweet> - Retweeted:", ConsoleColor.Green);
                    Cutil.Line("<Retweet> - User: "******"<Retweet> - Tweet Id: " + retweet.RetweetedStatus.StatusID, ConsoleColor.Green);
                }
            }
            catch (Exception ex)
            {
                Cutil.Error("<Retweet> -" + ex.Message);
                RetweetRandomHashtag();                 //this line isnt really generic enough to go here
            }
        }
Exemple #8
0
 public async static Task <List <Friendship> > FindFriendship(string source, string target)
 {
     try
     {
         var friendships = await(from friendship in Session.service.Friendship
                                 where friendship.Type == FriendshipType.Show && friendship.SourceScreenName == source && friendship.TargetScreenName == target
                                 select friendship).ToListAsync();
         if (friendships != null)
         {
             return(friendships);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         Cutil.Error("<Find Friendship> - " + ex.Message);
         return(null);
     }
 }
Exemple #9
0
        public async static void UnfollowUserByScreenname(string screenname)
        {
            try
            {
                Cutil.Line("<Unfollow user by ScreenName> - Screenname: " + screenname, ConsoleColor.DarkCyan);

                var user = await Session.service.DestroyFriendshipAsync(screenname, default(CancellationToken));

                if (user != null)
                {
                    Cutil.Line("<Unfollow user by ScreenName> - user unfollowed.", ConsoleColor.DarkCyan);

                    Session.followed.Remove(Session.followed.SingleOrDefault(x => x.ScreenName == screenname));
                    Session.unfollowed.Add(new Follower(screenname, DateTime.Now));
                    Futil.SaveFollowers(Session.unfollowed, "unfollowed.log");
                    Futil.SaveFollowers(Session.followed, "following.log");
                }
            }
            catch (Exception ex)
            {
                Cutil.Error("Unfollow user by ScreenName> " + ex);
            }
        }
Exemple #10
0
        private static async void FollowFriday()
        {
            List <Follower> ffl = null;

            while (isRunning)
            {
                Random rnd      = new Random();
                int    interval = rnd.Next(30, 45);

                if (DateTime.Now.DayOfWeek == DayOfWeek.Friday && ffl != null)
                {
                    if (ffl.Count > 7)
                    {
                        string a, b, c, d, e, f, g;
                        a = " @" + ffl.Last().ScreenName;
                        ffl.RemoveAt(ffl.Count - 1);
                        b = " @" + ffl.Last().ScreenName;
                        ffl.RemoveAt(ffl.Count - 1);
                        c = " @" + ffl.Last().ScreenName;
                        ffl.RemoveAt(ffl.Count - 1);
                        d = " @" + ffl.Last().ScreenName;
                        ffl.RemoveAt(ffl.Count - 1);
                        e = " @" + ffl.Last().ScreenName;
                        ffl.RemoveAt(ffl.Count - 1);
                        f = " @" + ffl.Last().ScreenName;
                        ffl.RemoveAt(ffl.Count - 1);
                        g = " @" + ffl.Last().ScreenName;
                        ffl.RemoveAt(ffl.Count - 1);
                        try {
                            Util.SendTweet("#FF " + a + b + c + d + e + f + g);
                        } catch (Exception ex) {
                            Cutil.Error("<Follow Friday> - " + ex.Message);
                        }
                    }
                }
                else
                {
                    try {
                        ffl = new List <Follower> ();

                        var followers = await Util.ReturnFriends(Session.screenname);

                        foreach (User u in followers)
                        {
                            ffl.Add(new Follower(u.ScreenNameResponse, DateTime.Now));
                        }

                        switch (DateTime.Now.DayOfWeek)
                        {
                        case DayOfWeek.Monday:
                            interval = 4320;
                            break;

                        case DayOfWeek.Tuesday:
                            interval = 2880;
                            break;

                        case DayOfWeek.Wednesday:
                            interval = 1440;
                            break;

                        case DayOfWeek.Thursday:
                            interval = 60;
                            break;

                        case DayOfWeek.Friday:
                            interval = 0;
                            break;

                        case DayOfWeek.Saturday:
                            interval = 4320;
                            break;

                        case DayOfWeek.Sunday:
                            interval = 4320;
                            break;
                        }
                    } catch (Exception ex) {
                        Cutil.Error("<Follow Friday> - " + ex.Message);
                        interval = 60;
                    }
                }

                Cutil.Line("<Follow Friday> - Waiting " + interval + " minutes");
                Thread.Sleep(interval * 60000);
            }
        }
Exemple #11
0
        public static void Initialize()
        {
            bool   fileEnded = false;
            string loc       = System.Reflection.Assembly.GetEntryAssembly().Location;
            string name      = System.AppDomain.CurrentDomain.FriendlyName;

            path = loc.Substring(0, loc.Length - name.Length);

            //followed = new List<Follower>();
            //unfollowed = new List<Follower>();

            using (StreamReader r = new StreamReader(path + "bot.config")) {
                while (fileEnded == false)
                {
                    string line = r.ReadLine();
                    if (line != null && !line.StartsWith("#") && line != "")
                    {
                        customer_key = line;
                        fileEnded    = true;
                    }
                }
                fileEnded = false;

                while (fileEnded == false)
                {
                    string line = r.ReadLine();
                    if (line != null && !line.StartsWith("#") && line != "")
                    {
                        customer_key_secret = line;
                        fileEnded           = true;
                    }
                }
                fileEnded = false;

                while (fileEnded == false)
                {
                    string line = r.ReadLine();
                    if (line != null && !line.StartsWith("#") && line != "")
                    {
                        access_token = line;
                        fileEnded    = true;
                    }
                }
                fileEnded = false;

                while (fileEnded == false)
                {
                    string line = r.ReadLine();
                    if (line != null && !line.StartsWith("#") && line != "")
                    {
                        access_token_secret = line;
                        fileEnded           = true;
                    }
                }
                fileEnded = false;

                while (fileEnded == false)
                {
                    string line = r.ReadLine();
                    if (line != null && !line.StartsWith("#") && line != "")
                    {
                        screenname = line;
                        fileEnded  = true;
                    }
                }
                fileEnded = false;

                while (fileEnded == false)
                {
                    string line = r.ReadLine();
                    if (line != null && !line.StartsWith("#") && line != "")
                    {
                        try
                        {
                            desiredRatio = double.Parse(line);
                        }
                        catch (Exception ex)
                        {
                            Cutil.Error("<Initialize> - Please enter valid desiredratio in config file");
                            Cutil.Error("<Initialize) - " + ex.Message);
                        }
                        fileEnded = true;
                    }
                }
                fileEnded = false;

                //Wait time
                while (fileEnded == false)
                {
                    string line = r.ReadLine();
                    if (line != null && !line.StartsWith("#") && line != "")
                    {
                        try
                        {
                            waitTime = double.Parse(line);
                        }
                        catch (Exception ex)
                        {
                            Cutil.Error("<Initialize> - Please enter valid wait time in config file");
                            Cutil.Error("<Initialize) - " + ex.Message);
                        }
                        fileEnded = true;
                    }
                }
                fileEnded = false;

                while (fileEnded == false)
                {
                    string line = r.ReadLine();

                    if (line == null || line.StartsWith("#") || line == "")
                    {
                        //do nothing
                    }
                    else if (line.Contains("<end>"))
                    {
                        fileEnded = true;
                    }
                    else
                    {
                        hashtags.Add(line);
                    }
                }
                fileEnded = false;

                while (fileEnded == false)
                {
                    string line = r.ReadLine();

                    if (line == null || line.StartsWith("#") || line == "")
                    {
                        //do nothing
                    }
                    else if (line.Contains("<end>"))
                    {
                        fileEnded = true;
                    }
                    else
                    {
                        followwords.Add(line);
                    }
                }
                fileEnded = false;

                while (fileEnded == false)
                {
                    string line = r.ReadLine();

                    if (line == null || line.StartsWith("#") || line == "")
                    {
                        //do nothing
                    }
                    else if (line.Contains("<end>"))
                    {
                        fileEnded = true;
                    }
                    else
                    {
                        filterwords.Add(line);
                    }
                }
                fileEnded = false;
                Cutil.Line("<Initialize> - Session initialization complete");

                Console.Title = "BotMatrix4 - " + screenname;
            }
        }