public override bool Execute()
        {
            var tweeter = new Tweeter(ConsumerKey, TokenKey, ConsumerSecret, TokenSecret);

            try {
                var result = tweeter.GetHomeTimelineAsync().GetAwaiter().GetResult();
                var tweets = result.Unwrap();

                foreach (var tweet in tweets)
                {
                    var date      = DateTime.ParseExact(tweet.CreatedAt, "ddd MMM dd HH:mm:ss zzzz yyyy", CultureInfo.CurrentCulture);
                    var humanTime = date.Humanize();
                    Log.LogMessage(MessageImportance.High, $"@{tweet.User.ScreenName}, {humanTime}: {tweet.Text}.");
                }

                return(true);
            } catch (Exception e) {
                Log.LogErrorFromException(e, true, true, null);
                return(false);
            }
        }
Esempio n. 2
0
        public override bool Execute()
        {
            if (TweetText.Length > 140)
            {
                Log.LogError("Tweet is too long, tweet must be <140 charaters.");
                return(false);
            }

            var tweeter = new Tweeter(ConsumerKey, TokenKey, ConsumerSecret, TokenSecret);

            try {
                var tweetResult = tweeter.PostTweetAsync(TweetText).ConfigureAwait(false).GetAwaiter().GetResult();
                var tweet       = tweetResult.Unwrap();
                Log.LogMessage(
                    MessageImportance.High,
                    $"Posted tweet at https://twitter.com/{tweet.User.ScreenName}/status/{tweet.Id}"
                    );
                return(true);
            } catch (Exception e) {
                Log.LogErrorFromException(e, true, true, null);
                return(false);
            }
        }