public void Init(string screenname, TextWriter log)
        {
            this.log = log;

            PrimaryTweep = new Tweep(UsersCollection.Single(screenname), Tweep.TweepType.None);

            settingsRepo = CachedRepository<LanguageAnalyticsResults>.Instance(screenname);

            LanguageAnalyticsResults = (settingsRepo.Query(RuntimeRepoKey)
                ?? new List<LanguageAnalyticsResults> { new LanguageAnalyticsResults() }).FirstOrDefault()
                ?? new LanguageAnalyticsResults();

            NoTweetList.Add(screenname);
        }
        public void Init(string screenname, TextWriter log)
        {
            this.log = log;

            PrimaryTweep = new Tweep(UsersCollection.Single(screenname), Tweep.TweepType.None);

            settingsRepo = CachedRepository <LanguageAnalyticsResults> .Instance(screenname);

            LanguageAnalyticsResults = (settingsRepo.Query(RuntimeRepoKey)
                                        ?? new List <LanguageAnalyticsResults> {
                new LanguageAnalyticsResults()
            }).FirstOrDefault()
                                       ?? new LanguageAnalyticsResults();

            NoTweetList.Add(screenname);
        }
Exemplo n.º 3
0
        private void LoadFromRepository()
        {
            var me = new Tweep(User, Tweep.TweepType.None);
            Repository<TweetBotRuntimeSettings> settingsRepo = Repository<TweetBotRuntimeSettings>.Instance;
            Repository<BotCommand> commandRepo = Repository<BotCommand>.Instance;

            //var runtimeSettings = Newtonsoft.Json.JsonConvert.DeserializeObject<TweetBotRuntimeSettings>(System.IO.File.OpenText("c:\\temp\\runtimesettings.demo.json.txt").ReadToEnd());

            var runtimeSettings = (settingsRepo.Query(RuntimeRepoKey) ?? new List<TweetBotRuntimeSettings> { new TweetBotRuntimeSettings() }).FirstOrDefault();

            if (runtimeSettings != null)
            {
                IsSimulationMode = runtimeSettings.IsSimulationMode;
                BotStartupTime = runtimeSettings.BotFirstStart;
                LastTweetTime = runtimeSettings.LastTweetTime;
                TweetsSentSinceLastFriendRequest = runtimeSettings.TweetsSentSinceLastFriendRequest;
                TweetsPerHour = runtimeSettings.Tweeted.Count() > 1 ? runtimeSettings.Tweeted
                    .GroupBy(x => x.CreatedAt.ToShortDateString())
                    .SelectMany(y => y.GroupBy(z => z.CreatedAt.Hour))
                    .Select(x => x.Count())
                    .Average() : 0;
                TweetsPerHourMax = runtimeSettings.Tweeted.Count() > 2 ? runtimeSettings.Tweeted
                    .GroupBy(x => x.CreatedAt.ToShortDateString())
                    .SelectMany(y => y.GroupBy(z => z.CreatedAt.Hour))
                    .Select(x => x.Count())
                    .Max() : 0;
                MinimumRetweetLevel = (int)Math.Ceiling(runtimeSettings.MinimumRetweetLevel);
                CurrentClout = me.User.FollowersCount;
                FollowerCount = me.User.FollowersCount;
                FollowingCount = me.User.FriendsCount;
                TwitterStreamVolume = runtimeSettings.TotalTweetsProcessed / (1.0 * Runtime.TotalMinutes);

                TwitterFollowSuggestions = runtimeSettings.TwitterFollowSuggestions;
                PotentialTweets = runtimeSettings.PotentialTweets;
                PotentialReTweets = runtimeSettings.PotentialReTweets;
                Tweeted = runtimeSettings.Tweeted;
                PotentialFriendRequests = runtimeSettings.PotentialFriendRequests
                    .Select(x => new KeyValuePair<Tweep, int>(x.Key, x.Count)).ToList();
                KeywordSuggestions = runtimeSettings.KeywordSuggestions
                    .Select(x => new KeyValuePair<string, int>(x.Key, x.Count)).ToList();
                runtimeSettings.Tweeted
                    .Where(t => t.CreatedAt.AddDays(30) >= DateTime.Now)
                    .GroupBy(t => t.CreatedAt.Day)
                    .Select(g => new { i = g.FirstOrDefault().CreatedAt.Day - 1, date = g.FirstOrDefault().CreatedAt, count = g.Count() })
                    .ToList()
                    .ForEach(x => TweetsLastThirtyDays[x.i] = x.count);
                TopFriendTweetCounts = runtimeSettings.Tweeted
                    .Where(t => me.Followers().Select(f => f.ID).Contains(t.User.UserID))
                    .GroupBy(t => t.User.UserID)
                    .Select(g => new KeyValuePair<Tweep, int>(new Tweep(g.FirstOrDefault().User, Tweep.TweepType.None), g.Count()))
                    .ToList();
                SeededKeywords = runtimeSettings.KeywordsToIgnore;
                KeywordsWithOccurrenceCount = runtimeSettings.Keywords
                    //.Concat(runtimeSettings.KeywordSuggestions.Where(x => x.Count >= TweetBotProcessingStep.MINIMUM_KEYWORD_COUNT))
                    .OrderByDescending(x => x.Count)
                    .ThenByDescending(x => x.Key)
                    .Select(x => new KeyValuePair<string, int>(x.Key, x.Count))
                    .ToList();
                PotentialKeywordsWithOccurrenceCount = runtimeSettings.KeywordSuggestions
                    //.Where(x => x.Count < TweetBotProcessingStep.MINIMUM_KEYWORD_COUNT)
                    .Select(x => new KeyValuePair<string, int>(x.Key, x.Count)).ToList();
            }

            var commands = commandRepo.Query(CommandRepoKey, Repository<BotCommand>.Limit.Limit100, x => !x.HasBeenExecuted);

            if (commands != null)
            {
                PendingKeywordAdd = commands.Where(c => c.Command == BotCommand.CommandType.AddKeyword && !c.HasBeenExecuted).Select(c => c.Value).Distinct().ToList();
                PendingKeywordIgnore = commands.Where(c => c.Command == BotCommand.CommandType.IgnoreKeyword && !c.HasBeenExecuted).Select(c => c.Value).Distinct().ToList();
                PendingTweetRemoval = commands.Where(c => (c.Command == BotCommand.CommandType.RemovePotentialTweet || c.Command == BotCommand.CommandType.RemovePotentialRetweet) && !c.HasBeenExecuted).Select(c => c.Value).Distinct().ToList();
            }
        }
Exemplo n.º 4
0
        private void LoadFromRepository()
        {
            var me = new Tweep(User, Tweep.TweepType.None);
            CachedRepository <TweetBotRuntimeSettings> settingsRepo = CachedRepository <TweetBotRuntimeSettings> .Instance(User.TwitterScreenName);

            SimpleRepository <BotCommand> commandRepo = new SimpleRepository <BotCommand>(User.TwitterScreenName);

            //var runtimeSettings = Newtonsoft.Json.JsonConvert.DeserializeObject<TweetBotRuntimeSettings>(System.IO.File.OpenText("c:\\temp\\runtimesettings.demo.json.txt").ReadToEnd());

            var runtimeSettings = (settingsRepo.Query(RuntimeRepoKey) ?? new List <TweetBotRuntimeSettings> {
                new TweetBotRuntimeSettings()
            }).FirstOrDefault();

            if (runtimeSettings != null)
            {
                IsSimulationMode = runtimeSettings.IsSimulationMode;
                BotStartupTime   = runtimeSettings.BotFirstStart;
                LastTweetTime    = runtimeSettings.LastTweetTime;
                TweetsSentSinceLastFriendRequest = runtimeSettings.TweetsSentSinceLastFriendRequest;
                TweetsPerHour = runtimeSettings.GetPastTweets().Count() > 1 ? runtimeSettings.GetPastTweets()
                                .GroupBy(x => x.CreatedAt.ToShortDateString())
                                .SelectMany(y => y.GroupBy(z => z.CreatedAt.Hour))
                                .Select(x => x.Count())
                                .Average() : 0;
                TweetsPerHourMax = runtimeSettings.GetPastTweets().Count() > 2 ? runtimeSettings.GetPastTweets()
                                   .GroupBy(x => x.CreatedAt.ToShortDateString())
                                   .SelectMany(y => y.GroupBy(z => z.CreatedAt.Hour))
                                   .Select(x => x.Count())
                                   .Max() : 0;
                MinimumRetweetLevel = (int)Math.Ceiling(runtimeSettings.MinimumRetweetLevel);
                CurrentClout        = me.User.FollowersCount;
                FollowerCount       = me.User.FollowersCount;
                FollowingCount      = me.User.FriendsCount;
                TwitterStreamVolume = runtimeSettings.TotalTweetsProcessed / (1.0 * Runtime.TotalMinutes);

                TwitterFollowSuggestions = runtimeSettings.TwitterFollowSuggestions;
                PotentialTweets          = runtimeSettings.GetPotentialTweets().OrderByDescending(t => t.TweetRank).ToList();
                PotentialReTweets        = runtimeSettings.GetPotentialTweets(true).OrderByDescending(t => t.TweetRank).ToList();
                Tweeted = runtimeSettings.GetPastTweets().ToList();
                PotentialFriendRequests = runtimeSettings.PotentialFriendRequests
                                          .Select(x => new KeyValuePair <Tweep, int>(x.Key, x.Count)).ToList();
                KeywordSuggestions = runtimeSettings.KeywordSuggestions
                                     .Select(x => new KeyValuePair <string, int>(x.Key, x.Count)).ToList();
                runtimeSettings.GetPastTweets()
                .Where(t => t.CreatedAt.AddDays(30) >= DateTime.Now)
                .GroupBy(t => t.CreatedAt.Day)
                .Select(g => new { i = g.FirstOrDefault().CreatedAt.Day - 1, date = g.FirstOrDefault().CreatedAt, count = g.Count() })
                .ToList()
                .ForEach(x => TweetsLastThirtyDays[x.i] = x.count);
                TopFriendTweetCounts = runtimeSettings.GetPastTweets()
                                       .Where(t => me.Followers().Select(f => f.ID).Contains(t.User.UserID))
                                       .GroupBy(t => t.User.UserID)
                                       .Select(g => new KeyValuePair <Tweep, int>(new Tweep(g.FirstOrDefault().User, Tweep.TweepType.None), g.Count()))
                                       .ToList();
                SeededKeywords = runtimeSettings.KeywordsToIgnore;
                KeywordsWithOccurrenceCount = runtimeSettings.Keywords
                                              //.Concat(runtimeSettings.KeywordSuggestions.Where(x => x.Count >= TweetBotProcessingStep.MINIMUM_KEYWORD_COUNT))
                                              .OrderByDescending(x => x.Count)
                                              .ThenByDescending(x => x.Key)
                                              .Select(x => new KeyValuePair <string, int>(x.Key, x.Count))
                                              .ToList();
                PotentialKeywordsWithOccurrenceCount = runtimeSettings.KeywordSuggestions
                                                       //.Where(x => x.Count < TweetBotProcessingStep.MINIMUM_KEYWORD_COUNT)
                                                       .Select(x => new KeyValuePair <string, int>(x.Key, x.Count)).ToList();
            }

            var commands = commandRepo.Query(CommandRepoKey, where : x => !x.HasBeenExecuted);

            if (commands != null)
            {
                PendingKeywordAdd    = commands.Where(c => c.Command == BotCommand.CommandType.AddKeyword && !c.HasBeenExecuted).Select(c => c.Value).Distinct().ToList();
                PendingKeywordIgnore = commands.Where(c => c.Command == BotCommand.CommandType.IgnoreKeyword && !c.HasBeenExecuted).Select(c => c.Value).Distinct().ToList();
                PendingTweetRemoval  = commands.Where(c => (c.Command == BotCommand.CommandType.RemovePotentialTweet || c.Command == BotCommand.CommandType.RemovePotentialRetweet) && !c.HasBeenExecuted).Select(c => c.Value).Distinct().ToList();
            }
        }
Exemplo n.º 5
0
        public LazyLoader<Tweep> GetLazyLoadedTweep(string userID, Tweep.TweepType tweepType = Tweep.TweepType.None)
        {
            var context = TwitterModel.Instance.GetAuthorizedTwitterContext(UsersCollection.PrimaryUser().TwitterScreenName);

            return new LazyLoader<Tweep>(
                userID,
                (() => new Tweep(context.User.Where(u => u.Type == UserType.Show && u.UserID == userID).First(), tweepType)));
        }
Exemplo n.º 6
0
        public Tweep CreateFriendship(Tweep follow, string screenname = null)
        {
            if (string.IsNullOrEmpty(screenname)) screenname = UsersCollection.PrimaryUser().TwitterScreenName;

            var user = GetAuthorizedTwitterContext(screenname).CreateFriendship(follow.User.Identifier.UserID, null, true);

            return new Tweep(user, user.Following ? Tweep.TweepType.Following : Tweep.TweepType.None);
        }
Exemplo n.º 7
0
        public Tweep CreateFriendship(Tweep follow, string screenname = null)
        {
            if (string.IsNullOrEmpty(screenname)) screenname = PrimaryUser.TwitterScreenName;

            var createFriendshipTask = GetAuthorizedTwitterContext(screenname).CreateFriendshipAsync(follow.User.UserID, true);

            createFriendshipTask.Wait();

            var user = createFriendshipTask.Result;

            return new Tweep(user, user.Following ? Tweep.TweepType.Following : Tweep.TweepType.None);
        }
        public void Init(string screenName, TextWriter log)
        {
            this.log = log;

            PrimaryTweep = new Tweep(UsersCollection.Single(screenName), Tweep.TweepType.None);

            settingsRepo = CachedRepository<TweetBotRuntimeSettings>.Instance(screenName);
            commandRepo = new SimpleRepository<BotCommand>(screenName);

            RuntimeSettings = (settingsRepo.Query(RuntimeRepoKey)
                ?? new List<TweetBotRuntimeSettings> { new TweetBotRuntimeSettings() }).FirstOrDefault()
                ?? new TweetBotRuntimeSettings();

            NoTweetList.Add(screenName.ToLower());
            Messages = TweetBotSettings.Get.Messages.Count == 0 ?
                null :
                Enumerable.Range(0, TweetBotSettings.Get.Messages.Count - 1)
                    .Select(i => TweetBotSettings.Get.Messages[i].Value).ToArray();
            OnlyWithMentions = TweetBotSettings.Get.Filters["OnlyWithMentions"] != null ?
                TweetBotSettings.Get.Filters["OnlyWithMentions"].Value :
                false;

            ForceSimulationMode = TweetBotSettings.Get.Settings["IsSimulationMode"] != null ?
                TweetBotSettings.Get.Settings["IsSimulationMode"].Value :
                false;

            if (ForceSimulationMode)
                log.WriteLine("{0}: Running in forced simulation mode. No actions will be taken.",
                    DateTime.Now);
            else if (SimulationMode)
                log.WriteLine("{0}: Running in automatic simulation mode to aquire a baseline. No actions will be taken for {1}hrs.",
                    DateTime.Now,
                    TweetBotRuntimeSettings.SIMULATION_MODE_HOURS);

            if (Messages == null)
                log.WriteLine("{0}: 'TweetBotSettings' configuration section is missing Messages. No responses will be sent.",
                    DateTime.Now);
            else
            {
                log.WriteLine("{0}: TweetBot will respond with: {1}",
                    DateTime.Now,
                    Environment.NewLine + string.Join(Environment.NewLine, Messages));
            }

            try
            {
                StopWords = File.OpenText("Resources/stopwords.txt")
                    .ReadToEnd()
                    .Split('\n').Select(x => x.Replace("\r", "").ToLower());
                if (StopWords.Count() > 0)
                    StopWordsRegex = new Regex("(" + string.Join("|", StopWords.Select(sw => "\\b" + sw + "\\b")) + ")", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                log.WriteLine("{0}: Stop Words: {1}",
                    DateTime.Now,
                    string.Join(",", StopWords));
            }
            catch { StopWords = new List<string>(); }
        }
Exemplo n.º 9
0
        public void Init(string screenName, TextWriter log)
        {
            this.log = log;

            PrimaryTweep = new Tweep(UsersCollection.Single(screenName), Tweep.TweepType.None);

            settingsRepo = CachedRepository <TweetBotRuntimeSettings> .Instance(screenName);

            commandRepo = new SimpleRepository <BotCommand>(screenName);

            RuntimeSettings = (settingsRepo.Query(RuntimeRepoKey)
                               ?? new List <TweetBotRuntimeSettings> {
                new TweetBotRuntimeSettings()
            }).FirstOrDefault()
                              ?? new TweetBotRuntimeSettings();

            NoTweetList.Add(screenName.ToLower());
            Messages = TweetBotSettings.Get.Messages.Count == 0 ?
                       null :
                       Enumerable.Range(0, TweetBotSettings.Get.Messages.Count - 1)
                       .Select(i => TweetBotSettings.Get.Messages[i].Value).ToArray();
            OnlyWithMentions = TweetBotSettings.Get.Filters["OnlyWithMentions"] != null ?
                               TweetBotSettings.Get.Filters["OnlyWithMentions"].Value :
                               false;

            ForceSimulationMode = TweetBotSettings.Get.Settings["IsSimulationMode"] != null ?
                                  TweetBotSettings.Get.Settings["IsSimulationMode"].Value :
                                  false;

            if (ForceSimulationMode)
            {
                log.WriteLine("{0}: Running in forced simulation mode. No actions will be taken.",
                              DateTime.Now);
            }
            else if (SimulationMode)
            {
                log.WriteLine("{0}: Running in automatic simulation mode to aquire a baseline. No actions will be taken for {1}hrs.",
                              DateTime.Now,
                              TweetBotRuntimeSettings.SIMULATION_MODE_HOURS);
            }

            if (Messages == null)
            {
                log.WriteLine("{0}: 'TweetBotSettings' configuration section is missing Messages. No responses will be sent.",
                              DateTime.Now);
            }
            else
            {
                log.WriteLine("{0}: TweetBot will respond with: {1}",
                              DateTime.Now,
                              Environment.NewLine + string.Join(Environment.NewLine, Messages));
            }

            try
            {
                StopWords = File.OpenText("Resources/stopwords.txt")
                            .ReadToEnd()
                            .Split('\n').Select(x => x.Replace("\r", "").ToLower());
                if (StopWords.Count() > 0)
                {
                    StopWordsRegex = new Regex("(" + string.Join("|", StopWords.Select(sw => "\\b" + sw + "\\b")) + ")", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                }
                log.WriteLine("{0}: Stop Words: {1}",
                              DateTime.Now,
                              string.Join(",", StopWords));
            }
            catch { StopWords = new List <string>(); }
        }