//获取弹幕 private async void GetDanmuData() { _DanmuData = new DanmuData(); _DanmuData.DanmaKuId = _selecVideo.DanmakuId; var url = AcFunAPI.GetDanmuUrl(_selecVideo.DanmakuId); await _DanmuData.GetData(url); _DanmuData.ListOfDanmu.Sort((x, y) => { return(x.RealTime.CompareTo(y.RealTime)); }); this.copyDanmuList = _DanmuData.ListOfDanmu; }
private void ReplyDanmu(object data) { DanmuData danmuData = (DanmuData)data; // 调教弹幕 if (isAllowPubTeach || bili_cookie.Contains(danmuData.userId)) { if (danmuData.danmuText.IndexOf("?") == 0 || danmuData.danmuText.IndexOf("?") == 0) { if ((danmuData.danmuText.Contains(":") || danmuData.danmuText.Contains(":"))) { string danmu = danmuData.danmuText.Substring(1).Replace(":", ":"); if (danmu.IndexOf(":") > 0 && danmu.IndexOf(":") < danmu.Length - 1) { string[] qa = danmu.Split(new char[] { ':' }); string question = qa[0], answer = qa[1]; string result = AddNLP(question, answer); if (result != null) { SendDanmuSplited(result); } return; } } } } // 普通弹幕 if (!bili_cookie.Contains(danmuData.userId)) { // 自定义回复 string[] rows = customReplyData.Split('\n'); foreach (string row in rows) { string[] columns = row.Split('\t'); if (columns.Length == 4) { if (columns[0] == "true") { string[] contains = columns[1].Split(','); string[] filters = columns[2].Split(','); string replyStr = columns[3]; bool isContains = false; foreach (string contain in contains) { if (contain.Length <= 0) { continue; } if (danmuData.danmuText.Contains(contain)) { isContains = true; break; } } if (isContains) { bool hasFilter = false; foreach (string filter in filters) { if (filter.Length <= 0) { continue; } if (danmuData.danmuText.Contains(filter)) { hasFilter = true; break; } } if (!hasFilter) { SendDanmuSplited(replyStr); return; } } } } } if (isUseRobot) { // 获取用户名和地理位置 WebClient client = new WebClient(); byte[] response = client.DownloadData("http://api.bilibili.cn/userinfo?mid=" + danmuData.userId); string responseJson = Encoding.UTF8.GetString(response); JObject json = (JObject)JsonConvert.DeserializeObject(responseJson); danmuData.userName = json["name"].ToString(); danmuData.location = json["place"].ToString().Replace(" ", ""); string text = SendToTulin(danmuData.danmuText, danmuData.userId, danmuData.location); SendDanmuSplited(text); } } }
private void MainClass_ReceivedDanmaku(object sender, BilibiliDM_PluginFramework.ReceivedDanmakuArgs e) { if (e.Danmaku.MsgType == BilibiliDM_PluginFramework.MsgTypeEnum.Comment) { //弹幕过滤 if (isFilterDanmu) { foreach (string filter in filterStrs) { if (e.Danmaku.CommentText.Contains(filter)) { return; } } } if (isReplyOnly) { bool isContain = false; foreach (string str in containStrs) { if (e.Danmaku.CommentText.Contains(str)) { isContain = true; break; } } if (!isContain) { return; } } // 需要从info中解析uid,用于判断发送此弹幕的用户 if (!e.Danmaku.RawData.Contains("info")) { Stop(); throw new Exception("抱歉,B站弹幕信息发生了变化(没有info),无法解析相应属性,请反馈给我[email protected]"); } else { JObject jsonResponse = (JObject)JsonConvert.DeserializeObject(e.Danmaku.RawData); string uid = jsonResponse["info"][2][0].ToString(); DanmuData danmuData = new DanmuData(); danmuData.danmuText = e.Danmaku.CommentText; danmuData.userId = uid; new Thread(new ParameterizedThreadStart(ReplyDanmu)).Start(danmuData); } } else if (e.Danmaku.MsgType == BilibiliDM_PluginFramework.MsgTypeEnum.GiftSend && isReGift) { if (reGiftMutex.WaitOne(1000)) { //double nowTime = DateTime.Now.Subtract(DateTime.Parse("1970-1-1")).TotalMilliseconds; // 打断,重新开始 thankGiftDelay_timer.Enabled = false; if (isDelayReGift) { thankGiftDelay_timer.Interval = reGiftDelay_int * 1000; } else { thankGiftDelay_timer.Interval = 100; } thankGiftDelay_timer.Enabled = true; string userGiftstr = e.Danmaku.GiftUser + "\t" + e.Danmaku.GiftName; bool isContain = false; for (int i = 0; i < user_gift_List.Count; ++i) { if (((string)user_gift_List[i]) == userGiftstr) { isContain = true; break; } } if (!isContain) { user_gift_List.Add(userGiftstr); } //new Thread(new ParameterizedThreadStart(thankGiftDelay)).Start(thankStr); //if (nowTime - lastReGiftTime > Int64.Parse(reGiftDelay) * 1000) //{ // string thankStr = ""; // for (int i = 0; i < userGiftList.Count; ++i) // { // userGiftstr = (string)userGiftList[i]; // string[] unameAndgname = userGiftstr.Split('\t'); // if (unameAndgname.Length > 1) // { // Random num = new Random(); // int point = num.Next(0, reGiftStrs.Length); // thankStr = reGiftStrs[point]; // string uname = unameAndgname[0]; // string gname = unameAndgname[1]; // thankStr = thankStr.Replace("%name%", uname).Replace("%gift%", gname); // thankGift(thankStr); // } // } // userGiftList.Clear(); // lastReGiftTime = nowTime; //} reGiftMutex.ReleaseMutex(); } } }