void _host_ReceiveChat(object sender, ankoPlugin2.ReceiveChatEventArgs e) { // コメントを受信したときに起きる Non Thread Safeのとき有 if (this.InvokeRequired) { Action <object, ankoPlugin2.ReceiveChatEventArgs> myDelegate; myDelegate = new Action <object, ankoPlugin2.ReceiveChatEventArgs>(_host_ReceiveChat); Invoke(myDelegate, new Object[] { sender, e }); return; } CommentOn(sender, e); }
private void CommentOn(object sender, ankoPlugin2.ReceiveChatEventArgs e) { try { if (!isAlive) { return; } // 天気予報 string weatherPattern = string.Format("^{0}「(?<city>.*?)」{1}「(?<day>.*?)」{2}$", weatherPrefixTextBox.Text, weatherMiddleComboBox.Text, weatherSuffixTextBox.Text); Match wmatch = Regex.Match(e.Chat.Message, weatherPattern); if (wmatch.Success) { if (e.Chat != null && !string.IsNullOrEmpty(e.Chat.UserId)) { int waitTime = Convert.ToInt32(timeLeftNumericUpDown.Text); long timeLeft = timeKeeper.Confirm(e.Chat.UserId, waitTime); if (timeLeft == 0) { string city = wmatch.Groups["city"].Value; string day = wmatch.Groups["day"].Value; Utility.PostMessage(_host, string.Format(">>{0} {1}", e.Chat.No, GetWeatherMsg(city, day, weatherNotCityTextBox.Text, weatherNotDayTextBox.Text, successSuffixTextBox.Text))); } else { Utility.PostMessage(_host, string.Format(">>{0}番さんが次に検索できるのは、あと{1}秒後です(同一IDでの検索は{2}秒間空けてください)", e.Chat.No, timeLeft, waitTime)); } } return; } // キーワード検索 string keywordPattern = string.Format("^{0}「(?<keyword>.*?)」{1}$", keywordPrefixTextBox.Text, keywordSuffixTextBox.Text); //Match kmatch = Regex.Match(chat.Message, @"みっくりさん「(?<keyword>.*?)」ってなに?"); Match kmatch = Regex.Match(e.Chat.Message, keywordPattern); if (kmatch.Success) { if (e.Chat != null && !string.IsNullOrEmpty(e.Chat.UserId)) { int waitTime = Convert.ToInt32(timeLeftNumericUpDown.Text); long timeLeft = timeKeeper.Confirm(e.Chat.UserId, waitTime); if (timeLeft == 0) { string keyword = kmatch.Groups["keyword"].Value; Utility.PostMessage(_host, string.Format(">>{0} {1}", e.Chat.No, Utility.InsertBr( GetKeywordSearchMsg(keyword, keywordNotFoundTextBox.Text, successSuffixTextBox.Text)))); } else { Utility.PostMessage(_host, string.Format(">>{0}番さんが次に検索できるのは、あと{1}秒後です(同一IDでの検索は{2}秒間空けてください)", e.Chat.No, timeLeft, waitTime)); } } return; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { } }