コード例 #1
0
 private void ShowTweet(object sender, TweetReceivedEventArgs e)
 {
     ColorConsole.Write(ConsoleColor.DarkYellow, "@{0} \"{1}\" [",
         Clean(e.Tweet.Creator.ScreenName),
         Clean(e.Tweet.Creator.Name)
     );
     ColorConsole.Write(ConsoleColor.Yellow, "{0}", e.Tweet.CreatedAt.ToString());
     ColorConsole.WriteLine(ConsoleColor.DarkYellow, "]");
     PrintTweet(e.Tweet.Text);
 }
コード例 #2
0
ファイル: AlertWindow.xaml.cs プロジェクト: JKarlam/Nottifier
        public AlertWindow(TweetReceivedEventArgs e)
        {
            if (!SearchForFilters(e))
            {
                this.Close();
            }
            else
            {
                InitializeComponent();
                tea = e;
                Debug.WriteLine(DateTime.Now + ": " + e.Json);

                BitmapImage biUserIcon = new BitmapImage(new Uri(e.Tweet.CreatedBy.ProfileImageUrl));
                userIcon.Source  = biUserIcon;
                userName.Content = e.Tweet.CreatedBy.Name;

                //string m = e.Tweet.DisplayTextRange==null? e.Tweet.Text:e.Tweet.Text.Substring(e.Tweet.DisplayTextRange[0], e.Tweet.DisplayTextRange[1] - e.Tweet.DisplayTextRange[0]);
                //messageTextBlock.Text = m;
                messageTextBlock.Text = e.Tweet.Text;
                //double messageLines = Math.Ceiling((double)m.Length / 50);
                double messageLines = Math.Ceiling((double)e.Tweet.Text.Length / 50);
                messageTextBlock.Height = messageLines * 20;

                List <IMediaEntity> medias;
                if (e.Tweet.ExtendedTweet == null)
                {
                    medias = e.Tweet.Entities.Medias;
                }
                else
                {
                    medias = e.Tweet.ExtendedTweet.ExtendedEntities.Medias;
                }

                if (medias.Count != 0)
                {
                    if (medias[0].MediaType.Contains("animated_gif")) // Video
                    {
                        Debug.WriteLine("El tweet contiene un vídeo");
                        MediaElement me = new MediaElement()
                        {
                            Source         = new Uri("http" + medias[0].VideoDetails.Variants[0].URL.Substring(5), UriKind.Absolute),
                            LoadedBehavior = MediaState.Play,
                            Width          = xtraGrid.Width
                        };
                        xtraGrid.Children.Add(me);
                        xtraGrid.Margin = new Thickness(10, 50 + messageTextBlock.Height, 0, 10);
                        float imageHeightWidthRelation = (float)medias[0].Sizes["medium"].Height / (float)medias[0].Sizes["medium"].Width;
                        xtraGrid.Height = xtraGrid.Width * imageHeightWidthRelation;

                        SetWindowParams();
                    }
                    else if (medias[0].MediaType.Contains("photo")) // Una imagen
                    {
                        Debug.WriteLine("El tweet contiene una imagen");
                        BitmapImage biExtraImage = new BitmapImage(new Uri(medias[0].MediaURL));
                        Image       i            = new Image()
                        {
                            Width = xtraGrid.Width
                        };
                        xtraGrid.Children.Add(i);
                        xtraGrid.Margin = new Thickness(10, 50 + messageTextBlock.Height, 0, 10);
                        float imageHeightWidthRelation = (float)medias[0].Sizes["medium"].Height / (float)medias[0].Sizes["medium"].Width;
                        xtraGrid.Height = xtraGrid.Width * imageHeightWidthRelation;

                        biExtraImage.DownloadCompleted += (sender, args) =>
                        {
                            i.Source = biExtraImage;
                            SetWindowParams();
                        };
                    }
                }
                else // Nada (solo texto)
                {
                    Debug.WriteLine("El tweet NO contiene imagen ni vídeo");
                    SetWindowParams();
                }
            }
        }
コード例 #3
0
 private void TweetCreated(object sender, TweetReceivedEventArgs tweetReceivedEventArgs)
 {
     Discord.Instance.SendMessage(tweetReceivedEventArgs.Tweet.Url);
 }