Exemplo n.º 1
0
        public async Task <ITweet> PostReplyAsync(ITweet inReplyTo, string message, string videoAttachmentUri, bool adult)
        {
            ITweet reply = null;

            try
            {
                var publishParameters = new PublishTweetParameters(message)
                {
                    InReplyToTweet    = inReplyTo,
                    PossiblySensitive = adult
                };
                if (videoAttachmentUri != null)
                {
                    var video = await videoAttachmentUri.GetBytesAsync();

                    var upload = await _client.Upload.UploadTweetVideoAsync(video);

                    await _client.Upload.WaitForMediaProcessingToGetAllMetadataAsync(upload);

                    publishParameters.Medias = new List <IMedia> {
                        upload
                    };
                }
                reply = await _client.Tweets.PublishTweetAsync(publishParameters);

                Log.Information("Reply sent to {Author}", inReplyTo.CreatedBy.ScreenName);
            }
            catch (Exception e)
            {
                Log.Error(e, "Error submitting reply");
            }
            try
            {
                var entry = new MentionEntry()
                {
                    TweetId   = inReplyTo.Id,
                    Status    = reply == null ? MentionStatus.Error : MentionStatus.Replied,
                    Timestamp = reply?.CreatedAt.DateTime ?? DateTime.Now
                };
                _repository.Save(entry);
            }
            catch (Exception e)
            {
                Log.Error(e, "Failed to persist MentionEntry");
            }

            return(reply);
        }
Exemplo n.º 2
0
 public void Save(MentionEntry mention)
 {
     Log.Information("Tweet {Id} replied", mention.TweetId);
     _db.Add(mention);
     _db.SaveChanges();
 }