private async void SendMessage() { Status res = null; if (InputBox.Text != "") { switch (mode) { case Mode.DirectMessage: TwitterTools.SendDirectMessage(InputBox.Text, targetScreenName); break; case Mode.Reply: res = await TwitterTools.UpdateStatus(InputBox.Text, status.Id); break; default: break; } } if (res != null) { AddNewStatus(res); this.InputBox.Clear(); } else { MessageBox.Show("奏神失敗"); } }
//マイアイコンクリックでプロフィール表示 private async void myIcon_Click(object sender, EventArgs e) { User user = await TwitterTools.ShowUser(Properties.Settings.Default.UserId); ProfileFrame profileFrame = new ProfileFrame(user); profileFrame.Show(); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // 認証 TwitterTools.Authentication(); // メインフレームを開く Application.Run(new MainFrame()); }
private async void RetweetIcon_MouseClick(object sender, MouseEventArgs e) { DialogResult result = MessageBox.Show("Retweet?", "RETWEET", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { bool res = await TwitterTools.RetweetStatus(status); if (res) { RetweetIcon.Image = Properties.Resources.retweet_b; } } }
private async void GetHomeTimeline(long?max_id = null) { if (!isLoading) { isLoading = true; var statuses = await TwitterTools.GetHomeTimeline(max_id); foreach (Status status in statuses) { AddStatusToTimeline(status, -1); } isLoading = false; } }
private void onStatus(StatusMessage m) { var status = m.Status; Invoke((MethodInvoker) delegate { AddStatusToTimeline(status); if (status.InReplyToStatusId != null || status.InReplyToUserId != null) { if (TwitterTools.IsReplyToMe(status)) { // すでに出ているMentionFrameが無いか検索 MentionFrame existFrame = null; foreach (var mFrame in TwitterTools.mentionFrameList) { var replies = mFrame.GetStatus(); foreach (var reply in replies) { if (status.Equals(reply)) { existFrame = mFrame; } else if (status.InReplyToStatusId == reply.Id) { existFrame = mFrame; } } } // 無かったら新規に表示 if (existFrame == null) { MentionFrame mFrame = new MentionFrame(status); TwitterTools.mentionFrameList.Add(mFrame); mFrame.Show(); } else { existFrame.AddNewStatus(status); existFrame.Activate(); } existFrame = null; } } }); }
private void StartUserstream() { var stream = TwitterTools.GetUserStream().Publish(); stream.OfType <StatusMessage>().Subscribe(m => onStatus(m)); stream.OfType <EventMessage>().Subscribe(m => onEventMessage(m)); stream.OfType <DeleteMessage>().Subscribe(m => onDeleteMessage(m)); stream.OfType <DisconnectMessage>().Subscribe(m => onDisconnectMessage(m)); stream.Catch(stream.DelaySubscription(TimeSpan.FromSeconds(10)).Retry()) .Repeat() .Subscribe((StreamingMessage m) => Console.WriteLine(m)); stream.Connect(); }
//ユーザータイムライン取得 private async void GetUserTimeline() { if (listMode != ListMode.Tweet) { ItemList.Controls.Clear(); } if (!isLoading) { isLoading = true; var statuses = await TwitterTools.GetUserTimeline(userId : user.Id, maxId : timelineMaxId); if (statuses != null) { int index = 0; if (tweetList.Count != 0) { index = 1; } ItemList.SuspendLayout(); for (int i = index; i < statuses.Count; i++) { tweetList.Add(new TweetItem(statuses[i], this)); ItemList.Controls.Add(tweetList[i]); } ItemList.ResumeLayout(); timelineMaxId = statuses[statuses.Count - 1].Id; } isLoading = false; } if (tweetList.Count != 0) { ItemList.SuspendLayout(); foreach (var item in tweetList) { ItemList.Controls.Add(item); } ItemList.ResumeLayout(); } }
//ユーザーのお気に入り取得 private async void GetUserFavorite() { if (listMode != ListMode.Favorite) { ItemList.Controls.Clear(); } if (!isLoading) { isLoading = true; var favorites = await TwitterTools.FavoritesList(userId : user.Id, maxId : favoriteMaxId); if (favorites != null) { int index = 0; if (favoriteList.Count != 0) { index = 1; } ItemList.SuspendLayout(); for (int i = index; i < favorites.Count; i++) { favoriteList.Add(new TweetItem(favorites[i], this)); ItemList.Controls.Add(favoriteList[i]); } ItemList.ResumeLayout(); favoriteMaxId = favorites[favorites.Count - 1].Id; } isLoading = false; } if (favoriteList.Count != 0) { ItemList.SuspendLayout(); foreach (var item in favoriteList) { ItemList.Controls.Add(item); } ItemList.ResumeLayout(); } }
private async void MainFrame_Load(object sender, EventArgs e) { //表示枠の諸々 ChangeTheme(Properties.Settings.Default.Theme); user = await TwitterTools.ShowUser(Properties.Settings.Default.UserId); TitleLabelA.Text = TitleLabelB.Text = "実況通神 - " + user.Name; myIcon.ImageLocation = user.ProfileImageUrl.Replace("_normal", ""); GetHomeTimeline(); StartUserstream(); sendMode = SendMode.Tweet; pictureBox[0] = pictureBox1; pictureBox[1] = pictureBox2; pictureBox[2] = pictureBox3; pictureBox[3] = pictureBox4; //labelTimer.Start(); }
// フォロワー取得 private async void GetUserFollower() { if (listMode != ListMode.Follower) { ItemList.Controls.Clear(); } if (!isLoading) { isLoading = true; var followers = await TwitterTools.FollowersList(userId : (long)user.Id, cursor : followerCursor); if (followers != null) { followerCursor = followers.NextCursor; ItemList.SuspendLayout(); for (int i = 0; i < followers.Count; i++) { followerList.Add(new UserItem(followers[i])); ItemList.Controls.Add(followerList[i]); } ItemList.ResumeLayout(); } isLoading = false; } if (followerList.Count != 0) { ItemList.SuspendLayout(); foreach (var follower in followerList) { ItemList.Controls.Add(follower); } ItemList.ResumeLayout(); } }
private async Task GetReply(Status status) { try { if (status.InReplyToStatusId != null) { Status replyStatus = await TwitterTools.ShowStatus(id : (long)status.InReplyToStatusId); replies.Add(replyStatus); MentionList.SuspendLayout(); MentionList.Controls.Add(new TweetItem(replyStatus, this)); MentionList.ResumeLayout(); await GetReply(replyStatus); } } catch (Exception e) { Console.WriteLine(e.Message); } }
private async void AsamaFrame_Load(object sender, EventArgs e) { user = await TwitterTools.ShowUser(Properties.Settings.Default.UserId); myIcon.ImageLocation = user.ProfileImageUrl.Replace("_normal", ""); }
private async void UpdateStatus() { Status res = null; if (TweetBox.TextLength <= 140) { try { switch (sendMode) { // 通常のツイート case SendMode.Tweet: res = await TwitterTools.UpdateStatus(TweetBox.Text); break; // リプライ case SendMode.Reply: if (fileLocation.Count == 0) { // ただのリプライ res = await TwitterTools.UpdateStatus(TweetBox.Text, replyStatusId); } else { // リプライ + 画像 res = await TwitterTools.UpdateStatus(TweetBox.Text, replyStatusId, fileLocation); } SendButton.Text = "送神" + (140 - TweetBox.TextLength).ToString(); break; // 画像付きツイート case SendMode.TweetWithMedia: res = await TwitterTools.UpdateStatus(text : TweetBox.Text, media_info : fileLocation); break; default: break; } sendMode = SendMode.Tweet; } catch (ArgumentException e) { Console.WriteLine(e.Message); } if (res == null) { MessageBox.Show("送神失敗"); } else { TweetBox.Clear(); // 画像リセット for (int i = 0; i < pictureBox.Length; i++) { pictureBox[i].ImageLocation = null; pictureBox[i].Visible = false; } fileLocation = new List <string>(); } } else { MessageBox.Show("文字数オーバー"); } }
private async void FavoriteIcon_MouseClick(object sender, MouseEventArgs e) { await TwitterTools.CreateFavotire(status.Id); FavoriteIcon.Image = Properties.Resources.favorite_b; }
private async void ActionMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { switch (e.ClickedItem.ToString()) { case "通神帯接続": ActionMenu.Close(); if (innerUrl != "") { Process.Start(innerUrl); } else { MessageBox.Show("リンクが無いよ"); } break; case "会話を表示": ActionMenu.Close(); if (status.InReplyToStatusId != null) { // すでに出ているMentionFrameが無いか検索 MentionFrame existFrame = null; foreach (var mentionFrame in TwitterTools.mentionFrameList) { var replies = mentionFrame.GetStatus(); foreach (var reply in replies) { if (status.Equals(reply)) { existFrame = mentionFrame; } } } // 無かったら新規に表示 if (existFrame == null) { MentionFrame mFrame = new MentionFrame(status); TwitterTools.mentionFrameList.Add(mFrame); mFrame.Show(); } else { existFrame.Activate(); } } else { MessageBox.Show("会話が無いよ"); } break; case "削除": MyActionMenu.Close(); bool res = await TwitterTools.DestroyStatus(status); if (res) { BackColor = Color.FromArgb(150, 150, 150); NameLabel.ForeColor = Color.FromArgb(1, 1, 1); } break; default: break; } }
private async void ShowProfileFrame(User user) { ProfileFrame profileFrame = new ProfileFrame(await TwitterTools.ShowUser(user_id: user.Id)); profileFrame.Show(); }
public TweetItem(Status status, Control control) { InitializeComponent(); parentFrame = control; this.status = status; this.user = status.User; innerUrl = ""; pictureBox[0] = pictureBox1; pictureBox[1] = pictureBox2; pictureBox[2] = pictureBox3; pictureBox[3] = pictureBox4; TabStop = false; if (status.Source.IndexOf("<a") >= 0) { Match m = TwitterTools.viaReg(status.Source); status.Source = m.Groups["via"].Value; } // 画像が含まれていたら表示する if (status.Entities.Media != null) { status.Text = status.Text.Replace(status.Entities.Media[0].Url, ""); innerUrl = status.Entities.Media[0].ExpandedUrl; if (status.ExtendedEntities.Media != null) { if (status.ExtendedEntities.Media[0].Type == "animated_gif") { StartButton.BackColor = Color.Transparent; StartButton.Parent = pictureBox1; StartButton.Visible = true; } for (int i = 0; i < status.ExtendedEntities.Media.Length; i++) { mediaEntity[i] = status.ExtendedEntities.Media[i]; pictureBox[i].ImageLocation = status.ExtendedEntities.Media[i].MediaUrl + ":small"; } } } // 画像のないPictureBoxを消す for (int i = 0; i < pictureBox.Length; i++) { if (string.IsNullOrEmpty(pictureBox[i].ImageLocation)) { Controls.Remove(pictureBox[i]); } } //URLを置換 foreach (var url in status.Entities.Urls) { if (!string.IsNullOrEmpty(url.Url)) { Match m = TwitterTools.urlReg(status.Entities.Urls.ToString()); status.Text = status.Text.Replace(url.Url, url.DisplayUrl); innerUrl = url.ExpandedUrl; } } //リツイート→赤、リプライ→緑、自分宛→青 if (status.RetweetedStatus != null) { BackColor = Color.FromArgb(50, 16, 16); IconFrame.ImageLocation = status.RetweetedStatus.User.ProfileImageUrl.Replace("_normal", ""); NameLabel.Text = status.RetweetedStatus.User.Name + " @" + status.RetweetedStatus.User.ScreenName; TweetTextLabel.Text = status.RetweetedStatus.Text; retweetUserIcon.ImageLocation = status.User.ProfileImageUrl.Replace("_normal", ""); retweetUserName.Text = "Retweeted by " + status.User.Name + " and " + status.RetweetCount.ToString() + " Users"; } else { IconFrame.ImageLocation = status.User.ProfileImageUrl.Replace("_normal", ""); NameLabel.Text = status.User.Name + " @" + status.User.ScreenName; TweetTextLabel.Text = WebUtility.HtmlDecode(status.Text); Controls.Remove(retweetUserIcon); Controls.Remove(retweetUserName); } if (TwitterTools.IsReply(status)) { if (TwitterTools.IsReplyToMe(status)) { BackColor = Color.FromArgb(16, 16, 60); } else { BackColor = Color.FromArgb(12, 55, 16); } } switch (parentFrame.Name) { case "MainFrame": mainFrame = (MainFrame)control.TopLevelControl; TimeLabel.Text = status.CreatedAt.LocalDateTime + " (via " + status.Source + ")"; TimeLabel.Location = new Point(59, TweetTextLabel.Location.Y + TweetTextLabel.Size.Height + 3); // 画像位置調整 for (int i = 0; i < pictureBox.Length; i++) { if (pictureBox[i] != null) { switch (i) { case 0: pictureBox1.Location = new Point(60, TimeLabel.Location.Y + TimeLabel.Size.Height + 3); break; case 1: pictureBox2.Location = new Point(216, TimeLabel.Location.Y + TimeLabel.Size.Height + 3); break; case 2: pictureBox3.Location = new Point(60, pictureBox1.Location.Y + pictureBox1.Size.Height + 3); break; case 3: pictureBox4.Location = new Point(216, pictureBox2.Location.Y + pictureBox2.Size.Height + 3); break; default: break; } StartButton.Location = new Point(50, 15); } } if (status.IsFavorited.Value) { FavoriteIcon.Image = Properties.Resources.favorite_b; } break; case "ProfileFrame": case "MentionFrame": MaximumSize = new Size(240, 5000); IconFrame.Size = new Size(30, 30); NameLabel.Location = new Point(35, 3); TweetTextLabel.Location = new Point(35, 18); TweetTextLabel.MinimumSize = new Size(205, 15); TweetTextLabel.MaximumSize = new Size(205, 4500); TimeLabel.Text = status.CreatedAt.LocalDateTime + "\n(via " + status.Source + ")"; TimeLabel.Location = new Point(35, TweetTextLabel.Location.Y + TweetTextLabel.Size.Height + 3); ReplyIcon.Location = new Point(170, TweetTextLabel.Location.Y + TweetTextLabel.Size.Height + 3); RetweetIcon.Location = new Point(193, TweetTextLabel.Location.Y + TweetTextLabel.Size.Height + 3); FavoriteIcon.Location = new Point(216, TweetTextLabel.Location.Y + TweetTextLabel.Size.Height + 3); // 画像位置調整 for (int i = 0; i < pictureBox.Length; i++) { if (pictureBox[i] != null) { pictureBox[i].Size = new Size(120, 64); switch (i) { case 0: pictureBox1.Location = new Point(IconFrame.Location.X, TimeLabel.Location.Y + TimeLabel.Size.Height + 3); break; case 1: pictureBox2.Location = new Point(pictureBox1.Location.X + pictureBox1.Size.Width + 4, TimeLabel.Location.Y + TimeLabel.Size.Height + 3); break; case 2: pictureBox3.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y + pictureBox1.Size.Height + 3); break; case 3: pictureBox4.Location = new Point(pictureBox3.Location.X + pictureBox3.Size.Width + 4, pictureBox1.Location.Y + pictureBox1.Size.Height + 3); break; default: break; } StartButton.Location = new Point(35, 7); } } break; default: break; } // リツイートユーザー情報の位置調整 if (status.Entities.Media != null && status.ExtendedEntities.Media != null) { switch (status.ExtendedEntities.Media.Length) { case 1: case 2: retweetUserIcon.Location = new Point(3, pictureBox1.Location.Y + pictureBox1.Size.Height + 3); retweetUserName.Location = new Point(40, pictureBox1.Location.Y + pictureBox1.Size.Height + 3); break; case 3: case 4: retweetUserIcon.Location = new Point(3, pictureBox3.Location.Y + pictureBox3.Size.Height + 3); retweetUserName.Location = new Point(40, pictureBox3.Location.Y + pictureBox3.Size.Height + 3); break; } } else { retweetUserIcon.Location = new Point(3, TimeLabel.Location.Y + TimeLabel.Size.Height + 3); retweetUserName.Location = new Point(40, TimeLabel.Location.Y + TimeLabel.Size.Height + 3); } }