public void ExecuteIfValidTime(NicoNicoCommentEntry target) { if (ShouldExecuteTime(target.Vpos)) { Execute(target); } }
private void StoreEntry(HtmlDocument doc, List <NicoNicoCommentEntry> list) { var nodes = doc.DocumentNode.SelectNodes("/packet/chat"); if (nodes == null) { return; } foreach (var node in nodes) { var attr = node.Attributes; //削除されていたら登録しない もったいないしね if (attr.Contains("deleted")) { continue; } var entry = new NicoNicoCommentEntry(); entry.No = attr["no"].Value; entry.Vpos = attr["vpos"].Value; entry.Date = long.Parse(attr["date"].Value); entry.UserId = attr.Contains("user_id") ? attr["user_id"].Value : "contributor"; entry.Mail = attr.Contains("mail") ? attr["mail"].Value : ""; entry.Content = HttpUtility.HtmlDecode(node.InnerText); entry.Score = attr.Contains("score") ? int.Parse(attr["score"].Value) : 0; list.Add(entry); } }
public static NicoScriptBase GetScriptInstance(VideoCommentViewModel vm, NicoNicoCommentEntry entry) { var match = ScriptPattern.Match(entry.Content); if (match.Success) { switch (match.Groups[1].Value) { case "@デフォルト": return(new NicoScriptDefault(vm, entry)); case "@逆": return(new NicoScriptReverse(vm, entry)); case "@ジャンプ": return(new NicoScriptJump(vm, entry)); case "@置換": //return new NicoScriptReplace(entry); default: return(null); } } else { return(null); } }
private void StoreEntry(string response, List <NicoNicoCommentEntry> list) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml2(response); var nodes = doc.DocumentNode.SelectNodes("/packet/chat"); if (nodes == null) { return; } foreach (HtmlNode node in nodes) { var attr = node.Attributes; //削除されていたら登録しない もったいないしね if (attr.Contains("deleted")) { continue; } NicoNicoCommentEntry entry = new NicoNicoCommentEntry(); entry.No = int.Parse(attr["no"].Value); entry.Vpos = int.Parse(attr["vpos"].Value); entry.Date = long.Parse(attr["date"].Value); entry.UserId = attr.Contains("user_id") ? attr["user_id"].Value : "contributor"; entry.Mail = attr.Contains("mail") ? attr["mail"].Value : ""; entry.Content = System.Web.HttpUtility.HtmlDecode(node.InnerText); list.Add(entry); } }
//コメントをフィルタリングする アウトならtrue、セーフならfalse public static bool Filter(NicoNicoCommentEntry entry) { foreach (NGCommentEntry ng in Settings.Instance.NGList) { if (!ng.IsEnabled) { continue; } switch (ng.Type) { case NGType.RegEx: if (Regex.Match(entry.Content, ng.Content).Success) { return(true); } break; case NGType.Command: if (entry.Mail.Contains(ng.Content)) { return(true); } break; case NGType.UserId: if (entry.UserId == ng.Content) { return(true); } break; case NGType.Word: if (entry.Content == ng.Content) { return(true); } break; case NGType.WordContains: if (entry.Content.Contains(ng.Content)) { return(true); } break; } } return(false); }
public NicoScriptReverse(VideoCommentViewModel vm, NicoNicoCommentEntry entry) : base(vm, entry, true) { foreach (var str in entry.Content.Split(' ')) { if (str == "コメ" || str == "投コメ") { Condition = str; } } }
private void OnReceive(object sender, XmlSocketReceivedEventArgs e) { var xml = new XmlDocument(); try { xml.LoadXml(e.Xml); Console.WriteLine(e.Xml); var thread = xml.SelectSingleNode("/thread"); if (thread != null) { Ticket = thread.Attributes["ticket"].Value; if (thread.Attributes["last_res"] != null) { LastRes = int.Parse(thread.Attributes["last_res"].Value); } ResFrom = LastRes + 1; return; } var chat = xml.SelectSingleNode("/chat"); if (chat != null) { var comment = new NicoNicoCommentEntry(); comment.No = (++CommentNum).ToString(); comment.Vpos = chat.Attributes["vpos"].Value; comment.Mail = chat.Attributes["mail"] != null ? chat.Attributes["mail"].Value : ""; comment.Score = chat.Attributes["score"] != null?int.Parse(chat.Attributes["score"].Value) : 0; comment.UserId = chat.Attributes["user_id"].Value; comment.Date = NicoNicoUtil.GetTimeFromVpos(Status, comment.Vpos); comment.Content = chat.InnerText; Owner.CommentList.Add(comment); //コマンドは弾く if (chat.InnerText.StartsWith("/")) { return; } Handler.InvokeScript("AsInjectOneComment", comment.ToJson()); } } catch (XmlException) { return; } }
public NicoScriptReplace(NicoNicoCommentEntry entry) : base(entry) { try { var splited = entry.Content.Split(' '); Compare = splited[1]; for (int i = 2; i < splited.Length; i++) { var str = splited[i]; if (str == "全") { Range = "全"; } } } catch (Exception) { Ready = false; } }
public override void Execute(NicoNicoCommentEntry target) { if (!Settings.Instance.DisableJumpCommand) { var seek = SeekPattern.Match(Entry.Content); if (seek.Success) { Owner.Owner.Handler.Seek(NicoNicoUtil.ConvertTime(seek.Groups[1].Value)); return; } var split = Entry.Content.Split(' '); if (Regex.IsMatch(split[1], "\\d")) { Owner.Owner.VideoUrl = "http://www.nicovideo.jp/watch/" + split[1]; Owner.Owner.Initialize(); } } }
private void StoreEntry(HtmlDocument doc, List <NicoNicoCommentEntry> list) { var nodes = doc.DocumentNode.SelectNodes("/packet/chat"); if (nodes == null) { return; } foreach (var node in nodes) { var attr = node.Attributes; //削除されていたら登録しない もったいないしね if (attr.Contains("deleted")) { continue; } var entry = new NicoNicoCommentEntry(); entry.No = attr["no"].Value; entry.Vpos = attr["vpos"].Value; entry.RenderTime = NicoNicoUtil.GetTimeFromVpos(entry.Vpos); var unix = UnixTime.FromUnixTime(long.Parse(attr["date"].Value)); entry.Date = unix.ToLongDateString() + " " + unix.ToLongTimeString(); entry.UserId = attr.Contains("user_id") ? attr["user_id"].Value : "contributor"; entry.Mail = attr.Contains("mail") ? attr["mail"].Value : ""; entry.Content = HttpUtility.HtmlDecode(node.InnerText); entry.Score = attr.Contains("score") ? int.Parse(attr["score"].Value) : 0; if (!NicoNicoNGComment.Filter(entry)) { list.Add(entry); } } }
public override void Execute(NicoNicoCommentEntry target) { switch (Condition) { case "全": target.Reverse = true; break; case "コメ": if (!target.IsUploader) { target.Reverse = true; } break; case "投コメ": if (target.IsUploader) { target.Reverse = true; } break; } }
public NicoScriptJump(VideoCommentViewModel vm, NicoNicoCommentEntry entry) : base(vm, entry, false) { }
public NicoScriptDefault(VideoCommentViewModel vm, NicoNicoCommentEntry entry) : base(vm, entry, true) { }
public override void Execute(NicoNicoCommentEntry target) { if (Ready) { } }
public override void Execute(NicoNicoCommentEntry target) { //適用するコメントのMailにコマンドが指定してなかったら@デフォルトコマンドの値を入れる if (!Regex.IsMatch(target.Mail, @"ue|shita|naka")) { if (Entry.Mail.Contains("ue")) { target.Position = "ue"; } else if (Entry.Mail.Contains("shita")) { target.Position = "shita"; } else { target.Position = "naka"; } } //適用するコメントのMailに色関連のコマンドがなければデフォルトコマンドの値を if (!Regex.IsMatch(target.Mail, CommentColorPattern) && !NicoNicoCommentEntry.TripletColor.IsMatch(target.Mail)) { //色を反映させる foreach (var key in NicoNicoCommentEntry.NicoNicoOfficialCommentColor.Keys) { if (Entry.Mail.Contains(key)) { target.CommentColor = NicoNicoCommentEntry.NicoNicoOfficialCommentColor[key]; break; } } //#xxxxxxで指定された色を取得する var result = NicoNicoCommentEntry.TripletColor.Match(Entry.Mail); if (result.Success) { target.CommentColor = result.Value; } } //適用するコメントのMail(ry if (!Regex.IsMatch(target.Mail, "big|small|medium")) { //コメントサイズ if (Entry.Mail.Contains("big")) { target.CommentSize = "big"; } else if (Entry.Mail.Contains("small")) { target.CommentSize = "small"; } else { target.CommentSize = "regular"; } } //適(ry if (!Regex.IsMatch(target.Mail, "defont|gothic|mincho")) { //フォントを設定 if (Entry.Mail.Contains("gothic")) { target.Font = "gothic"; } else if (Entry.Mail.Contains("mincho")) { target.Font = "mincho"; } else { target.Font = "defont"; } } }
//実行されたとき public abstract void Execute(NicoNicoCommentEntry target);
public NicoScriptBase(VideoCommentViewModel vm, NicoNicoCommentEntry entry, bool aoc) { Owner = vm; Entry = entry; AffectOtherComments = aoc; }
public async Task <List <NicoNicoCommentList> > RefreshCommentAsync(List <NicoNicoCommentList> targetList) { var jsonarray = new List <object>(); PacketId = PacketCount; //rs jsonarray.Add(new { ping = new { content = "rs:" + RequestId % IdLimit } }); foreach (var target in targetList) { if (target.ListName == "通常コメント") { //ps jsonarray.Add(new { ping = new { content = "ps:" + PacketId % IdLimit } }); var normalThread = new { thread = Owner.ApiData.Thread.ThreadIds.Default, version = "20061206", language = 0, user_id = int.Parse(Owner.ApiData.Viewer.Id), res_from = target.LastRes + 1, with_global = 1, scores = 1, nicoru = 0, userkey = Owner.ApiData.Context.UserKey }; jsonarray.Add(new { thread = normalThread }); target.PacketId = PacketId; //pf jsonarray.Add(new { ping = new { content = "pf:" + PacketId++ % IdLimit } }); } else if (target.ListName == "チャンネルコメント") { //ps jsonarray.Add(new { ping = new { content = "ps:" + PacketId % IdLimit } }); var channelThread = new { thread = Owner.ApiData.Thread.ThreadIds.Community, version = "20061206", language = 0, user_id = int.Parse(Owner.ApiData.Viewer.Id), res_from = target.LastRes + 1, force_184 = target.Force184, with_global = 1, scores = 0, nicoru = 0, threadkey = target.ThreadKey }; jsonarray.Add(new { thread = channelThread }); target.PacketId = PacketId; //pf jsonarray.Add(new { ping = new { content = "pf:" + PacketId++ % IdLimit } }); } } //rf jsonarray.Add(new { ping = new { content = "rf:" + RequestId++ % IdLimit } }); var request = new HttpRequestMessage(HttpMethod.Post, Owner.ApiData.Thread.ServerUrl) { Content = new StringContent(DynamicJson.Serialize(jsonarray), Encoding.UTF8, "text/plain") }; var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync(request); long currentPacketId = 0; foreach (var entry in DynamicJson.Parse(a)) { //コメントタイプを確認 if (entry.ping()) { var content = entry.ping.content as string; if (content.Contains("ps")) { currentPacketId = long.Parse(content.Split(':')[1]); } continue; } foreach (var target in targetList) { if (target.PacketId == currentPacketId) { if (entry.thread()) { var thread = entry.thread; target.ThreadId = thread.thread; target.Ticket = thread.ticket() ? thread.ticket : ""; target.LastRes = thread.last_res() ? (int)thread.last_res : 0; continue; } if (entry.chat()) { var chat = entry.chat; if (target.ListName == "通常コメント") { if (chat.deleted()) { continue; } var item = new NicoNicoCommentEntry() { Number = (int)chat.no, Vpos = (int)chat.vpos, PostedAt = (long)chat.date, Anonymity = chat.anonymity(), UserId = chat.user_id, Mail = chat.mail() ? chat.mail : "", Content = chat.content, Score = chat.score() ? (int)chat.score : 0 }; item.DisassembleMail(); target.Add(item); break; } if (target.ListName == "投稿者コメント") { if (chat.deleted()) { continue; } var item = new NicoNicoCommentEntry() { Number = (int)chat.no, Vpos = (int)chat.vpos, PostedAt = (long)chat.date, Content = chat.content, Mail = chat.mail() ? chat.mail : "" }; item.Mail = new string(item.Mail.Select(n => (ConvMap.ContainsKey(n) ? ConvMap[n] : n)).ToArray()); item.IsUploader = true; item.DisassembleMail(); target.Add(item); } if (target.ListName == "チャンネルコメント") { if (chat.deleted()) { continue; } var item = new NicoNicoCommentEntry() { Number = (int)chat.no, Vpos = (int)chat.vpos, PostedAt = (long)chat.date, Anonymity = chat.anonymity(), UserId = chat.user_id, Mail = chat.mail() ? chat.mail : "", Content = chat.content, Score = chat.score() ? (int)chat.score : 0 }; item.DisassembleMail(); target.Add(item); } } } } } return(targetList); }
public void Add(NicoNicoCommentEntry entry) { CommentList.Add(entry); }
public async Task <List <NicoNicoCommentList> > GetAllCommentAsync() { var normalList = new NicoNicoCommentList("通常コメント"); var uploaderList = new NicoNicoCommentList("投稿者コメント"); var communityList = new NicoNicoCommentList("コミュニティコメント"); var channelList = new NicoNicoCommentList("チャンネルコメント"); var officialList = new NicoNicoCommentList("公式コメント"); try { var ret = new List <NicoNicoCommentList>(); //通常コメントを取得 //ret.Add(new NicoNicoCommentList() { ListName = "通常コメント", CommentList = await GetNormalCommentAsync() }); //パケットIDとコメントタイプを紐付ける var dic = new Dictionary <long, CommentType>(); var jsonarray = new List <object>(); { PacketId = PacketCount; //rs jsonarray.Add(new { ping = new { content = "rs:" + RequestId % IdLimit } }); //ps 通常コメント jsonarray.Add(new { ping = new { content = "ps:" + PacketId % IdLimit } }); var normalThread = new { thread = Owner.ApiData.Thread.ThreadIds.Default, version = "20090904", language = 0, user_id = int.Parse(Owner.ApiData.Viewer.Id), with_global = 1, scores = 1, nicoru = 0, userkey = Owner.ApiData.Context.UserKey }; dic[PacketId] = CommentType.Normal; jsonarray.Add(new { thread = normalThread }); //pf jsonarray.Add(new { ping = new { content = "pf:" + PacketId++ % IdLimit } }); //------ //ps 通常コメント leaves jsonarray.Add(new { ping = new { content = "ps:" + PacketId % IdLimit } }); var normalLeaves = new { thread = Owner.ApiData.Thread.ThreadIds.Default, language = 0, user_id = int.Parse(Owner.ApiData.Viewer.Id), content = "0-" + ((Owner.ApiData.Video.Duration / 60) + 1) + ":100," + GetReadCommentCount(Owner.ApiData.Video.Duration).ToString(), scores = 1, nicoru = 0, userkey = Owner.ApiData.Context.UserKey }; dic[PacketId] = CommentType.NormalLeaves; jsonarray.Add(new { thread_leaves = normalLeaves }); //pf leaves jsonarray.Add(new { ping = new { content = "pf:" + PacketId++ % IdLimit } }); //------ //投稿者コメント有りフラグ if (Owner.ApiData.Thread.HasOwnerThread == "1") { //ps 投稿者コメント jsonarray.Add(new { ping = new { content = "ps:" + PacketId % IdLimit } }); var forkThread = new { thread = Owner.ApiData.Thread.ThreadIds.Default, version = "20061206", fork = 1, user_id = int.Parse(Owner.ApiData.Viewer.Id), res_from = -1000, with_global = 1, scores = 1, nicoru = 0, userkey = Owner.ApiData.Context.UserKey }; dic[PacketId] = CommentType.Uploader; jsonarray.Add(new { thread = forkThread }); //pf fork jsonarray.Add(new { ping = new { content = "pf:" + PacketId++ % IdLimit } }); } if (Owner.ApiData.IsChannelVideo) { //ps チャンネルコメント jsonarray.Add(new { ping = new { content = "ps:" + PacketId % IdLimit } }); var query = new GetRequestQuery(ThreadKeyApiUrl); query.AddQuery("thread", Owner.ApiData.Thread.ThreadIds.Community); var threadkey = await App.ViewModelRoot.CurrentUser.Session.GetAsync(query.TargetUrl); var threadKeyDic = HttpUtility.ParseQueryString(threadkey); channelList.ThreadKey = threadKeyDic["threadkey"]; channelList.Force184 = threadKeyDic["force_184"]; var channelThread = new { thread = Owner.ApiData.Thread.ThreadIds.Community, version = "20090904", language = 0, user_id = int.Parse(Owner.ApiData.Viewer.Id), force_184 = channelList.Force184, with_global = 1, scores = 1, nicoru = 0, threadkey = channelList.ThreadKey }; dic[PacketId] = CommentType.Channel; jsonarray.Add(new { thread = channelThread }); //pf channel jsonarray.Add(new { ping = new { content = "pf:" + PacketId++ % IdLimit } }); jsonarray.Add(new { ping = new { content = "ps:" + PacketId % IdLimit } }); var channelLeaves = new { thread = Owner.ApiData.Thread.ThreadIds.Community, language = 0, user_id = int.Parse(Owner.ApiData.Viewer.Id), content = "0-" + ((Owner.ApiData.Video.Duration / 60) + 1) + ":100," + GetReadCommentCount(Owner.ApiData.Video.Duration).ToString(), scores = 1, nicoru = 0, force_184 = threadKeyDic["force_184"], threadkey = threadKeyDic["threadkey"] }; dic[PacketId] = CommentType.ChannelLeaves; jsonarray.Add(new { thread_leaves = channelLeaves }); //pf channel jsonarray.Add(new { ping = new { content = "pf:" + PacketId++ % IdLimit } }); } //rf jsonarray.Add(new { ping = new { content = "rf:" + RequestId++ % IdLimit } }); PacketCount += jsonarray.Count; } var request = new HttpRequestMessage(HttpMethod.Post, Owner.ApiData.Thread.ServerUrl) { Content = new StringContent(DynamicJson.Serialize(jsonarray), Encoding.UTF8, "text/plain") }; var a = await App.ViewModelRoot.CurrentUser.Session.GetAsync(request); //結果 { var currentType = CommentType.Normal; foreach (var entry in DynamicJson.Parse(a)) { //コメントタイプを確認 if (entry.ping()) { var content = entry.ping.content as string; if (content.Contains("ps")) { currentType = dic[long.Parse(content.Split(':')[1])]; } continue; } if (entry.thread()) { var thread = entry.thread; switch (currentType) { case CommentType.NormalLeaves: { normalList.ThreadId = thread.thread; normalList.Ticket = thread.ticket() ? thread.ticket : ""; normalList.LastRes = thread.last_res() ? (int)thread.last_res : 0; break; } case CommentType.Uploader: { break; } case CommentType.Channel: { break; } case CommentType.ChannelLeaves: { channelList.ThreadId = thread.thread; channelList.Ticket = thread.ticket() ? thread.ticket : ""; channelList.LastRes = thread.last_res() ? (int)thread.last_res : 0; break; } } continue; } if (entry.chat()) { var chat = entry.chat; switch (currentType) { case CommentType.NormalLeaves: { if (chat.deleted()) { continue; } var item = new NicoNicoCommentEntry() { Number = (int)chat.no, Vpos = (int)chat.vpos, PostedAt = (long)chat.date, Anonymity = chat.anonymity(), UserId = chat.user_id, Mail = chat.mail() ? chat.mail : "", Content = chat.content, Score = chat.score() ? (int)chat.score : 0 }; item.DisassembleMail(); normalList.Add(item); break; } case CommentType.Uploader: { if (chat.deleted()) { continue; } var item = new NicoNicoCommentEntry() { Number = (int)chat.no, Vpos = (int)chat.vpos, PostedAt = (long)chat.date, Content = chat.content, Mail = chat.mail() ? chat.mail : "" }; item.Mail = new string(item.Mail.Select(n => (ConvMap.ContainsKey(n) ? ConvMap[n] : n)).ToArray()); item.IsUploader = true; item.DisassembleMail(); uploaderList.Add(item); break; } case CommentType.Channel: { break; } case CommentType.ChannelLeaves: { if (chat.deleted()) { continue; } var item = new NicoNicoCommentEntry() { Number = (int)chat.no, Vpos = (int)chat.vpos, PostedAt = (long)chat.date, Anonymity = chat.anonymity(), UserId = chat.user_id, Mail = chat.mail() ? chat.mail : "", Content = chat.content, Score = chat.score() ? (int)chat.score : 0 }; item.DisassembleMail(); channelList.Add(item); break; } } } } if (!normalList.IsEmpty()) { normalList.Sort(); ret.Add(normalList); } if (!communityList.IsEmpty()) { communityList.Sort(); ret.Add(communityList); } if (!channelList.IsEmpty()) { channelList.Sort(); ret.Add(channelList); } if (!officialList.IsEmpty()) { officialList.Sort(); ret.Add(officialList); } if (!uploaderList.IsEmpty()) { uploaderList.Sort(); ret.Add(uploaderList); } } return(ret); } catch (RequestFailed) { Owner.Status = "コメントの取得に失敗しました"; return(null); } }