Exemplo n.º 1
0
        public bool RunTask(ICharacter character)
        {
            string tweettext = text;

            foreach (string t in tag)
            {
                tweettext += " #" + t;
            }
            string   ret  = SendBirdTool.MakeReplyBird(character.auth, tweettext, target);
            JsonData json = JsonMapper.ToObject(ret);

            if (json.ContainsKey("id_str"))
            {
                LikeTask like = new LikeTask(new ITask.HALDLE_INFO {
                    type = ITask.HALDLE_TYPE.ALL
                }, json["id_str"].ToString());
                TaskQueueTool.AddImportantTask(like);

                RetweetTask retweet = new RetweetTask(new ITask.HALDLE_INFO {
                    type = ITask.HALDLE_TYPE.ALL_WITHOUT, without_id = new string[] { character.character_id }
                }, json["id_str"].ToString());
                TaskQueueTool.AddImportantTask(retweet);

                life--;
                if (life > 0)
                {
                    ReplyTweetTask reply = new ReplyTweetTask(new ITask.HALDLE_INFO {
                        type = ITask.HALDLE_TYPE.RANDOM_MUL_WITHOUT, count = life - random.Next(0, life), without_id = new string[] { character.character_id }
                    }, json["id_str"].ToString(), Bullet.GetBullet(text), tag, life - random.Next(0, life));
                    TaskQueueTool.AddImportantTask(reply);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        public List <ITask> GetTask(ICharacter character)
        {
            List <ITask> tasks = new List <ITask>();
            int          now   = GetTime();

            if (now - last_time < setting.time)
            {
                return(tasks);
            }
            string   result = SendBirdTool.GetNewTagTwitter(character.auth, setting.target, false);
            JsonData data   = JsonMapper.ToObject(result);

            if (!data.ContainsKey("globalObjects"))
            {
                last_time = GetTime();
                return(tasks);
            }
            JsonData tweets = data["globalObjects"]["tweets"];
            JsonData users  = data["globalObjects"]["users"];

            foreach (KeyValuePair <string, JsonData> tweet in tweets)
            {
                if (setting.isFavorite &&
                    !(bool)tweet.Value["favorited"] &&
                    (int)tweet.Value["favorite_count"] >= setting.favorite_r_favorited &&
                    (int)tweet.Value["retweet_count"] >= setting.favorite_r_retweeted &&
                    (int)tweet.Value["reply_count"] >= setting.favorite_r_reply &&
                    (int)tweet.Value["quote_count"] >= setting.favorite_r_quote)
                {
                    LikeTask likeTask = new LikeTask(new ITask.HALDLE_INFO {
                        type = ITask.HALDLE_TYPE.TARGET, id = character.character_id
                    }, tweet.Key);
                    tasks.Add(likeTask);
                    LikeTaskCount++;
                }

                if (setting.isRetweet &&
                    !(bool)tweet.Value["retweeted"] &&
                    (int)tweet.Value["favorite_count"] >= setting.retweet_r_favorited &&
                    (int)tweet.Value["retweet_count"] >= setting.retweet_r_retweeted &&
                    (int)tweet.Value["reply_count"] >= setting.retweet_r_reply &&
                    (int)tweet.Value["quote_count"] >= setting.retweet_r_quote)
                {
                    RetweetTask retweetTask = new RetweetTask(new ITask.HALDLE_INFO {
                        type = ITask.HALDLE_TYPE.TARGET, id = character.character_id
                    }, tweet.Key);
                    tasks.Add(retweetTask);
                    RetweetTaskCount++;
                }

                string user_id = tweet.Value["user_id_str"].ToString();
                if (setting.isFo &&
                    (!(bool)users[user_id]["following"]) &&
                    (!(bool)users[user_id]["follow_request_sent"]) &&
                    (int)tweet.Value["favorite_count"] >= setting.follow_r_favorited &&
                    (int)tweet.Value["retweet_count"] >= setting.follow_r_retweeted &&
                    (int)tweet.Value["reply_count"] >= setting.follow_r_reply &&
                    (int)tweet.Value["quote_count"] >= setting.follow_r_quote)
                {
                    FollowTask followTask = new FollowTask(new ITask.HALDLE_INFO {
                        type = ITask.HALDLE_TYPE.TARGET, id = character.character_id
                    }, user_id);
                    tasks.Add(followTask);
                    FollowTaskCount++;
                }

                if (setting.isCopy &&
                    !historytweet.Contains(tweet.Key) &&
                    tweet.Value["in_reply_to_status_id_str"] == null &&
                    (setting.copy_r_media || (!tweet.Value["entities"].ContainsKey("media"))) &&
                    (setting.copy_r_users || (!tweet.Value["entities"].ContainsKey("user_mentions"))) &&
                    (setting.copy_r_hashtag || (!tweet.Value["entities"].ContainsKey("hashtags"))) &&
                    (int)tweet.Value["favorite_count"] >= setting.copy_r_favorited &&
                    (int)tweet.Value["retweet_count"] >= setting.copy_r_retweeted &&
                    (int)tweet.Value["reply_count"] >= setting.copy_r_reply &&
                    (int)tweet.Value["quote_count"] >= setting.copy_r_quote)
                {
                    SimpletweetTask simpletweetTask = new SimpletweetTask(new ITask.HALDLE_INFO {
                        type = ITask.HALDLE_TYPE.TARGET, id = character.character_id
                    }, tweet.Value["full_text"].ToString(), new List <string>(), setting.tweetlife);
                    tasks.Add(simpletweetTask);
                    historytweet.Add(tweet.Key);
                    SendTaskCount++;
                }

                if (setting.isReply)
                {
                    string   ret     = SendBirdTool.GetTweet(character.auth, tweet.Key);
                    JsonData retdata = JsonMapper.ToObject(ret);
                    if (retdata.ContainsKey("globalObjects") && retdata["globalObjects"]["tweets"].Count > 0)
                    {
                        JsonData replytweets = retdata["globalObjects"]["tweets"];
                        string   f           = "";
                        int      max         = 0;
                        string   id          = "";
                        foreach (KeyValuePair <string, JsonData> replytweet in replytweets)
                        {
                            if (!historytweet.Contains(replytweet.Key) &&
                                (int)replytweet.Value["favorite_count"] > max &&
                                replytweet.Value.ContainsKey("in_reply_to_status_id_str") &&
                                replytweet.Value["in_reply_to_status_id_str"].ToString() == tweet.Key &&
                                (setting.reply_r_media || (!replytweet.Value["entities"].ContainsKey("media"))) &&
                                (setting.reply_r_users || (!replytweet.Value["entities"].ContainsKey("user_mentions"))) &&
                                (setting.reply_r_hashtag || (!replytweet.Value["entities"].ContainsKey("hashtags"))) &&
                                (int)replytweet.Value["favorite_count"] >= setting.reply_r_favorited &&
                                (int)replytweet.Value["retweet_count"] >= setting.reply_r_retweeted &&
                                (int)replytweet.Value["reply_count"] >= setting.reply_r_reply &&
                                (int)replytweet.Value["quote_count"] >= setting.reply_r_quote)
                            {
                                max = (int)replytweet.Value["favorite_count"];
                                f   = replytweet.Value["full_text"].ToString();
                                id  = replytweet.Key;
                            }
                        }
                        if (f != "")
                        {
                            ReplyTweetTask replyTweetTask = new ReplyTweetTask(new ITask.HALDLE_INFO {
                                type = ITask.HALDLE_TYPE.TARGET, id = character.character_id
                            }, tweet.Key, f, new List <string>(), setting.tweetlife);
                            tasks.Add(replyTweetTask);
                            historytweet.Add(id);
                            ReplyTaskCount++;
                        }
                    }
                }
            }
            last_time = GetTime();
            return(tasks);
        }