예제 #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();
        }
예제 #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);
            }
        }
예제 #3
0
        /// <summary>
        /// Check bot owners follower vs following ratio. Returns true if ratio is less than desiredRatio
        /// </summary>
        /// <returns>The ratio.</returns>
        /// <param name="desiredRatio">Desired ratio.</param>
        public static bool Ratio(double desiredRatio)
        {
            var userResponse = (from user in Session.service.User where user.Type == UserType.Lookup && user.ScreenNameList == Session.screenname select user).ToList();

            double following   = 0;
            double followers   = 0;
            double actualRatio = 0;

            foreach (User user in userResponse)
            {
                following   = user.FriendsCount;
                followers   = user.FollowersCount;
                actualRatio = following / followers;
            }

            if (actualRatio <= desiredRatio)
            {
                Cutil.Line("<Ratio> - Ratio: " + actualRatio + ". Acceptable", ConsoleColor.Magenta);
                return(true);
            }
            else
            {
                Cutil.Line("<Ratio> - Ratio: " + actualRatio + ". Unacceptable", ConsoleColor.DarkMagenta);
                return(false);
            }
        }
예제 #4
0
        private static void Prompts()
        {
            while (isRunning)
            {
                Random rnd      = new Random();
                int    interval = rnd.Next(60, 180);

                Util.SendTweet(ThreeCharacters.ReturnThreeCharacters() + "#WritingPrompt #ThreeRandomCharacters");

                Cutil.Line("<Prompts> - Waiting " + interval + " minutes");
                Thread.Sleep(interval * 60000);
            }
        }
예제 #5
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");
        }
예제 #6
0
        public static void Record(Status status)
        {
            using (Stream stream = File.Open(Session.path + "following.log", FileMode.Append))
            {
                var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();



                Session.followed.Add(new Follower(status.ScreenName, DateTime.Now));

                bformatter.Serialize(stream, Session.followed);

                Cutil.Line("<Record follower> - Recorded", ConsoleColor.Cyan);
            }
        }
예제 #7
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);
            }
        }
예제 #8
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
            }
        }
예제 #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);
            }
        }
예제 #10
0
        private static void BotMatrix()
        {
            Cutil.Line("<BotMatrix> - Start");
            while (isRunning)
            {
                Random rnd      = new Random();
                int    interval = rnd.Next(4, 11);


                List <Status> statuses = Util.RetweetRandomHashtag();


                statuses = Util.FilterMeOut(statuses);


                if (Util.Ratio(Session.desiredRatio))
                {
                    foreach (Status status in statuses)
                    {
                        if (Util.FollowFilter(status))
                        {
                            Util.FollowUserByStatus(status);
                        }
                        else
                        {
                            Cutil.Line("<Follow Filter> - Rejected" + status.User.ScreenNameResponse, ConsoleColor.DarkYellow);
                        }
                    }
                }



                Cutil.Line("<BotMatrix> - Waiting " + interval + " minutes");
                Thread.Sleep(interval * 60000);
            }
        }
예제 #11
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);
            }
        }
예제 #12
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;
            }
        }
예제 #13
0
 public static void SendTweet(string text)
 {
     Session.service.TweetAsync(text);
     Cutil.Line("<Send tweet> - Tweeted: " + text);
 }