Exemplo n.º 1
0
        public override void OpenSettings(INIParser parser)
        {
            stringsetname = parser.GetValue("Module", "ReactorStringset");
            var duration_val  = parser.GetValue("Cycle", "Duration");
            var variation_val = parser.GetValue("Cycle", "Variation");

            stringset = StringSetsManager.GetStrings(stringsetname);

            if (!string.IsNullOrEmpty(duration_val))
            {
                duration = int.Parse(duration_val);
            }
            else
            {
                duration = 10;
            }

            if (!string.IsNullOrEmpty(variation_val))
            {
                variation = int.Parse(variation_val);
            }
            else
            {
                variation = 5;
            }
        }
Exemplo n.º 2
0
        void ITimeTask.Run( )
        {
            while (!Disposed)
            {
                if (IsRunning)
                {
                    foreach (var item in pair)
                    {
                        if (DateTime.Now.Hour == item.Item1.Hour &&
                            DateTime.Now.Minute == item.Item1.Minute &&
                            DateTime.Now.Second == 0)
                        {
                            var inputset = new List <string>();

                            var output = item.Item2;
                            inputset.Add(output);

                            if (item.Item2.StartsWith("__") && item.Item2.EndsWith("__"))
                            {
                                inputset = new List <string>(StringSetsManager.GetStrings(item.Item2.Substring(2, item.Item2.Length - 4)));
                            }

                            while (true)
                            {
                                if (inputset.Count == 0)
                                {
                                    break;
                                }
                                output = inputset[_selector.Next(inputset.Count)];
                                var result = Globals.Instance.User.PublishTweet(output);
                                if (result != null)
                                {
                                    Log.Print(this.Name, "Tweeted [{0} : {1:yyyy-MM-dd HH:mm:ss}]", result.Text, result.CreatedAt);
                                    break;
                                }
                                else
                                {
                                    Log.Print(this.Name, "트윗하지 못했습니다 - [{0}]", output);
                                    inputset.Remove(output);
                                    if (inputset.Count > 0)
                                    {
                                        Log.Print(this.Name, "재시도. 남은 case 수 : {0}", inputset.Count);
                                    }
                                    else
                                    {
                                        Log.Print(this.Name, "모든 트윗이 중복으로 처리되어 시보를 트윗하지 못했습니다.");
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                Thread.Sleep(500);
            }
        }
Exemplo n.º 3
0
        public override Module CreateModule(object[] @params)
        {
            var module = new RegularTweet((string)@params[0]);

            module.stringsetname = ( string )@params[1];
            module.stringset     = StringSetsManager.GetStrings(module.stringsetname);
            module.duration      = ( int )@params[2];
            module.variation     = ( int )@params[3];
            module.IsRunning     = false;
            return(module);
        }
Exemplo n.º 4
0
        public void LoadStringsets(string stringSet)
        {
            var scheduler = StringSetsManager.GetStrings(stringSet);

            for (int i = 0; i < scheduler.Length; i++)
            {
                var tags = scheduler[i].Split('∥');
                if (tags.Length != 3)
                {
                    Log.Error(this.Name, "Not correct scheduler stringset {0}", scheduler[i]);
                    continue;
                }
                pair.Add(new Tuple <TimeSet, string>(new TimeSet(int.Parse(tags[0]), int.Parse(tags[1])), tags[2]));
            }
        }
Exemplo n.º 5
0
        public void LoadStringsets(string stringSet)
        {
            var reactor = StringSetsManager.GetStrings(stringSet);

            for (int i = 0; i < reactor.Length; i++)
            {
                var tags = reactor[i].Split('∥');
                if (tags.Length != 3)
                {
                    Log.Error(this.Name, "Not correct reactor stringset '{0}'", reactor[i]);
                    continue;
                }
                reactor_category.Add(tags[0]);
                reactor_input.Add(tags[1]);
                reactor_output.Add(tags[2]);
            }
        }
Exemplo n.º 6
0
        void IStreamListener.TweetCreateByAnyone(object sender, TweetReceivedEventArgs args)
        {
            if (!IsRunning)
            {
                return;
            }
            var tweet = args.Tweet;

            if (!Verification( ))
            {
                return;
            }
            if (tweet.CreatedBy.Id == Globals.Instance.User.Id)
            {
                return;
            }
            if (tweet.IsRetweet == true)
            {
                return;
            }

            var cases = new List <int>();

            for (int i = 0; i < reactor_category.Count; i++)
            {
                var category = reactor_category[i];
                var input    = reactor_input[i];

                // TODO: StringSetManager에서 Stringset간 참조에 대한 처리를 해주어야 합니다.
                if (input.StartsWith("__") && input.EndsWith("__"))
                {
                    var inputset  = StringSetsManager.GetStrings(input.Substring(2, input.Length - 4));
                    var loopbreak = false;
                    for (int j = 0; j < inputset.Length; j++)
                    {
                        var matchResult = IsMatch(category, inputset[j], tweet);
                        if (matchResult == TweetMatchResult.Match)
                        {
                            cases.Add(i);
                        }
                        else if (matchResult == TweetMatchResult.Expire)
                        {
                            loopbreak = true;
                            break;
                        }
                    }
                    if (loopbreak)
                    {
                        break;
                    }
                }
                else if (input.StartsWith("-__") && input.EndsWith("__"))
                {
                    var inputset = StringSetsManager.GetStrings(input.Substring(3, input.Length - 5));
                    for (int j = 0; j < inputset.Length; j++)
                    {
                        if (inputset[j].StartsWith("__") && inputset[j].EndsWith("__"))
                        {
                            var inputset_inner = StringSetsManager.GetStrings(inputset[j].Substring(2, inputset[j].Length - 4));
                            for (int k = 0; k < inputset_inner.Length; k++)
                            {
                                var matchResult = IsMatch(category, inputset_inner[k], tweet);
                                if (matchResult == TweetMatchResult.Match)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            var matchResult = IsMatch(category, inputset[j], tweet);
                            if (matchResult == TweetMatchResult.Match)
                            {
                                break;
                            }
                        }
                    }
                    if (IsCategoryMatch(category, tweet))
                    {
                        cases.Add(i);
                    }
                }
                else
                {
                    var matchResult = IsMatch(category, input, tweet);
                    if (matchResult == TweetMatchResult.Match)
                    {
                        cases.Add(i);
                    }
                    else if (matchResult == TweetMatchResult.Expire)
                    {
                        break;
                    }
                }
            }
            if (cases.Count > 0)
            {
                var    i    = _selector.Next(cases.Count);
                string @out = string.Empty;
                if (reactor_output[cases[i]].StartsWith("__") && reactor_output[cases[i]].EndsWith("__"))
                {
                    @out = StringSetsManager.GetRandomString(reactor_output[cases[i]].Substring(2, reactor_output[cases[i]].Length - 4));
                }
                else
                {
                    @out = reactor_output[cases[i]];
                }
                if (string.IsNullOrEmpty(@out))
                {
                    return;
                }
                var pString = ParseEscapeString(@out, tweet);
                if (pString.Flag)
                {
                    const int MaxDelay = 50;
                    System.Threading.Tasks.Task.Factory.StartNew(delegate
                    {
                        Thread.Sleep(_selector.Next(MaxDelay));                             // 나름의 랜덤 출력을 위한 결과물
                        var rjdcode = string.Format("rjd-{0}", tweet.Id);
                        var @var    = ModuleLibrary.GetValue(rjdcode);
                        if (@var == null || !( bool )@var)
                        {
                            ModuleLibrary.SetValue(rjdcode, true);
                            System.Threading.Tasks.Task.Factory.StartNew(delegate
                            {
                                Thread.Sleep(MaxDelay * 10);
                                ModuleLibrary.RemoveValue(rjdcode);
                            });

                            var result = Globals.Instance.User.PublishTweet(pString.String, new PublishTweetOptionalParameters()
                            {
                                InReplyToTweetId = pString.Id
                            });
                            Log.Print(this.Name, "Send tweet [{0}]", result.Text);

                            if (ExpireUsers.ContainsKey(tweet.CreatedBy.Id))
                            {
                                ExpireUsers[tweet.CreatedBy.Id] = new TimeSet(DateTime.Now);
                            }
                            else
                            {
                                ExpireUsers.Add(tweet.CreatedBy.Id, new TimeSet(DateTime.Now));
                            }
                        }
                    });
                }
            }
        }