Exemple #1
0
        private async void TweetButton_Click(object sender, EventArgs e)
        {
            if (Tokens == null)
            {
                ToolStripStatusLabel.Text = @"まだにんしょうしていません(X3)";
                return;
            }
            string text = TweetTextBox.Text;

            TweetTextBox.Clear();
            TweetTextBox.Focus();

            await ApplyCommandAndTweet(text);
        }
Exemple #2
0
        //ここまで

        private void TweetButton_Click(object sender, EventArgs e)
        {
            if (Tokens == null)
            {
                StatusLabel.Text = "まだにんしょうしていません(X3)";
                return;
            }

            var text = TweetTextBox.Text.TrimEnd('\r', '\n');

            if (string.IsNullOrEmpty(text))
            {
                TweetTextBox.Clear();
                StatusLabel.Text = "しっぱいしました(X3)";
                TweetTextBox.Focus();
                return;
            }

            if (寿司モードToolStripMenuItem.Checked)
            {
                var sushiText = string.Empty;

                for (int i = 0; i < text.Length; i++)
                {
                    sushiText += "🍣";
                }

                text = sushiText;
            }
            else if (モールス信号ToolStripMenuItem.Checked)
            {
                MorseCode mc = new MorseCode();
                text = mc.ConvertToMorse(text);
                if (text == "error")
                {
                    StatusLabel.Text = "もーるすしんごうにできませんでした(X3)";
                    return;
                }
            }

            if (text == "!poker")
            {
                text = string.Empty;

                if (ポーカーのリプライ化ToolStripMenuItem.Checked)
                {
                    text = $"@KIBOUDIED \r\n";
                }

                text += CommandPoker();
            }
            else if (text == "!bill")
            {
                // IPアドレスを使ってるから心配ならいじるといいかも
                string ipAddress = string.Empty;

                IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
                foreach (IPAddress ip in ipEntry.AddressList)
                {
                    if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        ipAddress = ip.ToString();
                        break;
                    }
                }

                int IntegerIP = (int)(long.Parse(ipAddress.Replace(".", "")) / 1000);
                int bill      = (IntegerIP + int.Parse(DateTime.Now.ToString("yyyyMMdd"))) % 10000;

                text = $"本日のTwitter利用料 {bill:#,0}円";
            }

            // !nowをテキスト中に入れるとそこを時間に置き換える
            // 例:「なう(!now)」→「なう(2016/09/07 01:00:00)」
            int startIndex;

            if (0 <= (startIndex = text.IndexOf("!now")))
            {
                text = text.Remove(startIndex, 4).Insert(startIndex, DateTime.Now.ToString());
            }

            Tweet(text, 1);
        }
Exemple #3
0
        public void Tweet(string text, int count)
        {
            const string completeText = "ついーとしました(:3)";
            const string failureText  = "しっぱいしました(X3)";

            string textWithCount = text;

            try
            {
                if (count != 1)
                {
                    textWithCount += $"({count}回目)";

                    if (textWithCount.Length > 140)
                    {
                        StatusLabel.Text = failureText;
                        TweetTextBox.Focus();
                        return;
                    }
                }

                ToolStripMenuItem a1 = (ToolStripMenuItem)menuStrip1.Items[1];
                try
                {
                    if (picturecounts - 1 == 0)
                    {
                        Tokens.Statuses.Update(status => textWithCount, in_reply_to_status_id => replyidstr.Text);
                        replyidstr.Text = "";
                    }
                    else if (picturecounts - 1 == 1)
                    {
                        MediaUploadResult first = Tokens.Media.Upload(media: new FileInfo(@a1.DropDownItems[1].Text));
                        Status            s     = Tokens.Statuses.Update(status: textWithCount, media_ids: new long[] { first.MediaId }, in_reply_to_status_id: long.Parse(replyidstr.Text));
                        addPictureToolStripMenuItem.DropDownItems.RemoveAt(1);
                        picturecounts--;
                        picturecount.Text = (picturecounts - 1).ToString();
                        replyidstr.Text   = "";
                    }
                    else if (picturecounts - 1 == 2)
                    {
                        MediaUploadResult first  = Tokens.Media.Upload(media: new FileInfo(@a1.DropDownItems[1].Text));
                        MediaUploadResult second = Tokens.Media.Upload(media: new FileInfo(@a1.DropDownItems[2].Text));
                        Status            s      = Tokens.Statuses.Update(status: textWithCount, media_ids: new long[] { first.MediaId, second.MediaId });
                        addPictureToolStripMenuItem.DropDownItems.RemoveAt(1);
                        addPictureToolStripMenuItem.DropDownItems.RemoveAt(1);
                        picturecounts     = picturecounts - 2;
                        picturecount.Text = (picturecounts - 1).ToString();
                        replyidstr.Text   = "";
                    }
                    else if (picturecounts - 1 == 3)
                    {
                        MediaUploadResult first  = Tokens.Media.Upload(media: new FileInfo(@a1.DropDownItems[1].Text));
                        MediaUploadResult second = Tokens.Media.Upload(media: new FileInfo(@a1.DropDownItems[2].Text));
                        MediaUploadResult third  = Tokens.Media.Upload(media: new FileInfo(@a1.DropDownItems[3].Text));
                        Status            s      = Tokens.Statuses.Update(status: textWithCount, media_ids: new long[] { first.MediaId, second.MediaId, third.MediaId });
                        addPictureToolStripMenuItem.DropDownItems.RemoveAt(1);
                        addPictureToolStripMenuItem.DropDownItems.RemoveAt(1);
                        addPictureToolStripMenuItem.DropDownItems.RemoveAt(1);
                        picturecounts     = picturecounts - 3;
                        picturecount.Text = (picturecounts - 1).ToString();
                        replyidstr.Text   = "";
                    }
                    else if (picturecounts - 1 == 4)
                    {
                        MediaUploadResult first  = Tokens.Media.Upload(media: new FileInfo(@a1.DropDownItems[1].Text));
                        MediaUploadResult second = Tokens.Media.Upload(media: new FileInfo(@a1.DropDownItems[2].Text));
                        MediaUploadResult third  = Tokens.Media.Upload(media: new FileInfo(@a1.DropDownItems[3].Text));
                        MediaUploadResult fourth = Tokens.Media.Upload(media: new FileInfo(@a1.DropDownItems[4].Text));
                        Status            s      = Tokens.Statuses.Update(status: textWithCount, media_ids: new long[] { first.MediaId, second.MediaId, third.MediaId, fourth.MediaId });
                        addPictureToolStripMenuItem.DropDownItems.RemoveAt(1);
                        addPictureToolStripMenuItem.DropDownItems.RemoveAt(1);
                        addPictureToolStripMenuItem.DropDownItems.RemoveAt(1);
                        addPictureToolStripMenuItem.DropDownItems.RemoveAt(1);
                        picturecounts     = picturecounts - 4;
                        picturecount.Text = (picturecounts - 1).ToString();
                        replyidstr.Text   = "";
                    }
                }
                catch (Exception ex)
                {
                    StatusLabel.Text = failureText;
                }

                TweetTextBox.Clear();
                var resultText = completeText;

                if (count != 1)
                {
                    resultText += $"({count}回目)";
                }

                StatusLabel.Text = resultText;
                TweetTextBox.Focus();
            }
            catch
            {
                count++;
                Tweet(text, count);
            }
        }