public void OnLoad()
        {
            lastCheckTime = DateSync.GetLastCheckDate();

            var mentionOptions = new ListTweetsMentioningMeOptions
            {
                Count = 20,
            };

            var dmOption = new ListDirectMessagesReceivedOptions
            {
                Count = 20,
            };
            
            foreach (var account in Config.Accounts)
            {
                if (account.Preferences.MentionsPreferences != Library.Notifications.NotificationType.None)
                {
                    IsLoading = true;
                    Interlocked.Increment(ref requestsPending);
                    ServiceDispatcher.GetService(account).ListTweetsMentioningMe(mentionOptions, (t, r) => FilterAndAddStatuses(t.Cast<ITweetable>(), r)); // Ugh.
                }
                if (account.Preferences.MessagesPreferences != Library.Notifications.NotificationType.None)
                {
                    IsLoading = true;
                    Interlocked.Increment(ref requestsPending);
                    ServiceDispatcher.GetService(account).ListDirectMessagesReceived(dmOption, (t, r) => FilterAndAddStatuses(t.Cast<ITweetable>(), r));
                }
            }
#if WP8
            this.LoadFinished += (s, e) => SpeakNotifications();
#endif
        }
        static void Main()
        {
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());

            string tConsumerKey = "";
            string tConsumerSecret = "";
            string tAccessToken = "";
            string tAccessSecret = "";

            try
            {
                tConsumerKey = ConfigurationManager.AppSettings["TwitterConsumerKey"];
                tConsumerSecret = ConfigurationManager.AppSettings["TwitterConsumerSecret"];
                tAccessToken = ConfigurationManager.AppSettings["TwitterAccessToken"];
                tAccessSecret = ConfigurationManager.AppSettings["TwitterAccessSecret"];
            }
            catch (Exception)
            {
                throw new System.ArgumentException("Error with Twitter keys", "twitter");
            }

            //build twitter connection
            var twitService = new TweetSharp.TwitterService(tConsumerKey, tConsumerSecret, tAccessToken, tAccessSecret);

            //build options to check for mentions
            var mentionsOptions = new TweetSharp.ListTweetsMentioningMeOptions();
            mentionsOptions.Count = 20;
            mentionsOptions.SinceId = 300328033800306680;

            //get the mentions
            IEnumerable<TwitterStatus> mentions = twitService.ListTweetsMentioningMe(mentionsOptions);

            List<TwitterStatus> listOfStuff = mentions.ToList();
            listOfStuff.ForEach(
                x =>
                {
                    Console.WriteLine("Now gathering info about tweet #{0}.", x.Id);
                    Console.WriteLine("It is in response to tweet #{0}.", x.InReplyToStatusId);

                    var thatTweet = twitService.GetTweet(new GetTweetOptions { Id = (long)x.InReplyToStatusId });

                    Console.WriteLine("That tweet's text was {0}", thatTweet.Text);
                    Console.WriteLine("More importantly, heres the url it was referencing {0}", thatTweet.Entities.Urls[0].ExpandedValue);

                    string moveString = "not found";

                    if (x.Text.Contains("*"))
                    {
                        int startIndex = x.Text.IndexOf("*");
                        int endIndex = x.Text.LastIndexOf("*");
                        moveString = x.Text.Substring(startIndex, endIndex - startIndex + 1);
                    }
                    Console.WriteLine("The move attached to this tweet was {0}.", moveString);
                }
            );
            Console.WriteLine("End of new API stuff");
        }
Exemple #3
0
        static public List <TwitterItem> getMentions(TwitterService service, AccountTwitter account, DoWorkEventArgs e, decimal minimumId)
        {
            IEnumerable <TwitterStatus> mentions;
            List <TwitterItem>          allTweets = new List <TwitterItem>();

            try
            {
                ListTweetsMentioningMeOptions options = new TweetSharp.ListTweetsMentioningMeOptions();
                options.Count = Properties.Settings.Default.TwitterItemsFetchInPast;
                if (minimumId >= 0)
                {
                    options.SinceId = Convert.ToInt64(minimumId);
                }

                IAsyncResult result = service.BeginListTweetsMentioningMe(options);
                mentions = service.EndListTweetsMentioningMe(result);


                foreach (TwitterStatus status in mentions)
                {
                    if (e != null)
                    {
                        if (e.Cancel)
                        {
                            AppController.Current.Logger.writeToLogfile("Cancel received for Mentions");
                            break;
                        }
                    }
                    allTweets.Add(API.TweetSharpConverter.getItemFromStatus(status, account));
                    foreach (TwitterItem item in allTweets)
                    {
                        item.isMention = true;
                    }
                }
            }
            catch
            {
                // xxx
            }
            return(allTweets);
        }
        //Returns the oldest tweet id after the minimum lookup. Returns 0 if none
        public static long areNewTweets(long minimumLookup)
        {
            long newTweet = 0;
            TwitterService ts = buildService();

            //build options to check for mentions
            var mentionsOptions = new TweetSharp.ListTweetsMentioningMeOptions();
            mentionsOptions.Count = 1;
            mentionsOptions.SinceId = minimumLookup;

            //get the mentions
            IEnumerable<TwitterStatus> mentions = ts.ListTweetsMentioningMe(mentionsOptions);
            List<TwitterStatus> listOfStuff = mentions.ToList();
            var theCount = listOfStuff.Count;
            listOfStuff.ForEach(                    //list only has 0-1 items in it, so forEach is ok
                x =>
                {
                    newTweet = x.Id;
                }
            );

            return newTweet;
        }
		public virtual void ListTweetsMentioningMe(ListTweetsMentioningMeOptions options, Action<IEnumerable<TwitterStatus>, TwitterResponse> action)
		{
			var count = options.Count;
			var since_id = options.SinceId;
			var max_id = options.MaxId;
			var trim_user = options.TrimUser;
			var contributor_details = options.ContributorDetails;
			var include_entities = options.IncludeEntities;
			
			WithHammock(action, "statuses/mentions_timeline", FormatAsString, "?count=", count, "&since_id=", since_id, "&max_id=", max_id, "&trim_user="******"&contributor_details=", contributor_details, "&include_entities=", include_entities);
		}
		public virtual IAsyncResult BeginListTweetsMentioningMe(ListTweetsMentioningMeOptions options)
		{
			var count = options.Count;
			var since_id = options.SinceId;
			var max_id = options.MaxId;
			var trim_user = options.TrimUser;
			var contributor_details = options.ContributorDetails;
			var include_entities = options.IncludeEntities;
				

			return BeginWithHammock<IEnumerable<TwitterStatus>>(WebMethod.Get, "statuses/mentions_timeline", FormatAsString, "?count=", count, "&since_id=", since_id, "&max_id=", max_id, "&trim_user="******"&contributor_details=", contributor_details, "&include_entities=", include_entities);
		}
		public virtual Task<TwitterResponse<IEnumerable<TwitterStatus>>> ListTweetsMentioningMeAsync(ListTweetsMentioningMeOptions options)
		{
			var count = options.Count;
			var since_id = options.SinceId;
			var max_id = options.MaxId;
			var trim_user = options.TrimUser;
			var contributor_details = options.ContributorDetails;
			var include_entities = options.IncludeEntities;
				
			
			return ExecuteRequest<IEnumerable<TwitterStatus>>("statuses/mentions_timeline", FormatAsString, "?count=", count, "&since_id=", since_id, "&max_id=", max_id, "&trim_user="******"&contributor_details=", contributor_details, "&include_entities=", include_entities);
		}
 public TwitterStatus[] GetMentions(long sinceId)
 {
     var options = new ListTweetsMentioningMeOptions {SinceId = sinceId};
     return Twitter.ListTweetsMentioningMe(options).ToArray();
 }
Exemple #9
0
        private static TwitterStatus GetNextResponseDue()
        {
            long lastTweetId = Helper.GetLastKnownTweetId();

            TwitterService service =
                new TwitterService(Helper.GetPublicKey(), Helper.GetSecretKey());

            service.AuthenticateWith(Helper.GetPublicToken(), Helper.GetSecretToken());

            ListTweetsMentioningMeOptions options = new ListTweetsMentioningMeOptions()
            {
                SinceId = lastTweetId
            };

            IEnumerable<TwitterStatus> myTweets =
                service.ListTweetsMentioningMe(options);

            return myTweets.OrderBy(o=>o.Id).FirstOrDefault();
        }
Exemple #10
0
        //get a list of all the tweets that have yet to be replied to
        public static List<TwitterStatus> getUnrepliedTweets()
        {
            List<TwitterStatus> unrepliedTweetIds = new List<TwitterStatus>();
            ListTweetsMentioningMeOptions mentionOpts = new ListTweetsMentioningMeOptions();

            IEnumerable<TwitterStatus> mentions;
            mentions = twitterService.ListTweetsMentioningMe(new ListTweetsMentioningMeOptions());

            if (mentions != null)
            {
                foreach (var mention in mentions)
                {
                    //check if the tweet has already been replied to
                    bool isReplied = isTweetRepliedTo(mention);
                    //if the tweet hasn't been replied to, add to list of long ids to reply to
                    if (isReplied == false && mention.Id > lastknownTwitterID) { unrepliedTweetIds.Add(mention); }
                }

                Console.WriteLine("Finished with getUnrepliedTweets");
                return unrepliedTweetIds;
            }

            else return null;
        }
Exemple #11
0
        //get most recent tweet at you through mentionTweet to set the lastKnownTweetID
        public static void getLastTweetAtSeattleEntMoot()
        {
            List<long> mentionTweetIds = new List<long>();
            ListTweetsMentioningMeOptions mentionOpts = new ListTweetsMentioningMeOptions();
            IEnumerable<TwitterStatus> mentions;
            mentions = twitterService.ListTweetsMentioningMe(new ListTweetsMentioningMeOptions());
            if(mentions != null & (mentions.Count() > 0))
            {
                foreach (var tweet in mentions)
                {
                    mentionTweetIds.Add(tweet.Id);
                }

                mentionTweetIds.Sort();
                lastknownTwitterID = mentionTweetIds.ElementAt(0);
            }

            else { lastknownTwitterID = 0; }
        }
Exemple #12
0
        public List<TwitterStatusLight> ListReplyTimeline(Int64 LastID)
        {
            ListTweetsMentioningMeOptions option = new ListTweetsMentioningMeOptions();
            option.SinceId = LastID;

            IEnumerable<TwitterStatus> response = _TwitterService.ListTweetsMentioningMe(option);

            List<TwitterStatusLight> convertResponse = new List<TwitterStatusLight>();

            foreach (TwitterStatus row in response)
            {
                TwitterStatusLight res = ConvertResult(row);
                convertResponse.Add(res);
            }

            return convertResponse;
        }
        /// <summary>
        /// Gets the list of Mention Objects from twitter
        /// </summary>
        /// <param name="twitter"></param>
        /// <returns></returns>
        public void GetMentions()
        {
            ListTweetsMentioningMeOptions mentionOpts = new ListTweetsMentioningMeOptions();
            mentionOpts.IncludeEntities = true;

            List<TwitterStatus> mentions = User.Account.ListTweetsMentioningMe(mentionOpts).ToList();
            for (int index = 0; index < mentions.Count; index++)
            {
                InteractiveTweet tempTweet = ConvertTweet(mentions[index], true);
                if (localTweetList.Contains(tempTweet) == false)
                {
                    localTweetList.Add(tempTweet);
                }
            }
        }
Exemple #14
0
        public AskModule(IDocumentSession documentSession, IHubContext hubContext)
        {
            Get["/ask"] = _ =>
            {
                try
                {
                    // RavenDb
                    var storedQuestions = documentSession.Query<Question>().OrderByDescending(x => x.DateAsked).ToList();

                    // Twitter
                    var twitterService = new TwitterService(TwitterConsumerKey, TwitterConsumerSecret);
                    twitterService.AuthenticateWith(TwitterAccessToken, TwitterAccessTokenSecret);

                    var twitterOptions = new ListTweetsMentioningMeOptions();
                    if (storedQuestions.Any())
                    {
                        var sinceId = storedQuestions.First().MessageId;
                        twitterOptions.SinceId = sinceId;
                    }

                    var tweets = twitterService.ListTweetsMentioningMe(twitterOptions).ToList();
                    if (!tweets.Any()) return null;

                    var nextQuestion = tweets.First(t => !string.IsNullOrEmpty(t.Text) && t.Text.Contains("#drsharp"));

                    //var model = this.Bind<AskViewModel>();

                    var pathToAiml = System.Web.HttpContext.Current.Server.MapPath(@"~/aiml");
                    var drSharp = new DoctorSharp(pathToAiml);
                    var answer = drSharp.Ask(nextQuestion.Author.ScreenName, nextQuestion.Text);

                    // Note: tweet working, but not in reply to sender. Also need to add some hashtag to the answer.
                    //twitterService.SendTweet(new SendTweetOptions
                    //{
                    //    DisplayCoordinates = false,
                    //    InReplyToStatusId = nextQuestion.Id,
                    //    Status = answer
                    //});

                    var question = new Question
                    {
                        From = nextQuestion.Author.ScreenName,
                        DateAsked = nextQuestion.CreatedDate,
                        Content = nextQuestion.Text,
                        MessageId = nextQuestion.Id,
                        Answer = answer
                    };

                    documentSession.Store(question);
                    documentSession.SaveChanges();

                    // SignalR
                    hubContext.Clients.All.broadcastAnswer(question.Content, question.Answer, question.From);
                    return null;
                }
                catch (Exception ex)
                {
                    return string.Format("Message: {0}\r\nDetail {1}", ex.Message, ex.StackTrace);
                }

            };
        }