Пример #1
0
		/// <summary>
		/// NGフィルターを構築する
		/// </summary>
		private void BuildRegex(NgClient[] clients)
		{
			ClearFilter();
			_clients.AddRange(clients);
			foreach (NgClient client in _clients) {
				switch (client.Type) {
					case NGType.Word:

						// NGの属性に沿って該当する正規表現を生成する
						if (client.UseCaseUnify) {
							AddPattern(_unityFilterPattern, normaliza(client.Source));
						} else if (client.IsRegex) {
							AddPattern(_normalFilterPattern, string.Format("({0})", client.Source));
						} else {
							AddPattern(_normalFilterPattern, Regex.Escape(client.Source));
						}

						break;
					case NGType.Id:
						_idCollections.Add(client.Source);
						break;
					case NGType.Command:
						_commandCollections.Add(client.Source);
						break;
				}

			}

			if (_normalFilterPattern.Length != 0) {
				_normalFilter = new Regex(_normalFilterPattern.ToString(), System.Text.RegularExpressions.RegexOptions.Compiled);
			} else {
				_normalFilter = null;
			}

			if (_unityFilterPattern.Length != 0) {
				_unifyFilter = new Regex(_unityFilterPattern.ToString(), System.Text.RegularExpressions.RegexOptions.Compiled);
			} else {
				_unifyFilter = null;
			}

		}
Пример #2
0
		/// <summary>
		/// NGを追加する
		/// </summary>
		/// <param name="ng"></param>
		private void AddNg(NgClient client)
		{
			_clients.Add(client);

			switch (client.Type) {
				case NGType.Word:

					// NGの属性に沿って該当する正規表現を生成する
					if (client.UseCaseUnify) {
						AddPattern(_unityFilterPattern, normaliza(client.Source));
						_unifyFilter = new Regex(_unityFilterPattern.ToString());
					} else{
						if (client.IsRegex) {
							AddPattern(_normalFilterPattern, string.Format("({0})", client.Source));
						} else {
							AddPattern(_normalFilterPattern, Regex.Escape(client.Source));
						}
						_normalFilter = new Regex(_normalFilterPattern.ToString());
					}

					break;
				case NGType.Id:
					_idCollections.Add(client.Source);
					break;
				case NGType.Command:
					_commandCollections.Add(client.Source);
					break;
			}

		}
Пример #3
0
		/// <summary>
		/// NGを削除する
		/// </summary>
		/// <param name="ng"></param>
		private void DelNg(NgClient ng)
		{
			if (_clients.Contains(ng)) {
				_clients.Remove(ng);
			}

			BuildRegex(_clients.ToArray());

		}
Пример #4
0
		/// <summary>
		/// NG一覧を取得する。失敗したときはnullを返す
		/// </summary>
		/// <param name="liveId"></param>
		/// <param name="cookies"></param>
		/// <returns>NG一覧 失敗時はnull</returns>
		public static NgClient[] GetNgClients(string liveId, System.Net.CookieContainer cookies)
		{
			string res = SendNgCommand(liveId, "get", "", "", cookies);

			if (res == null) {
				Logger.Default.LogMessage("NG一覧を取得できませんでした。");
				return null;
			}

			XmlDocument xdoc = new XmlDocument();

			try {
				xdoc.LoadXml(res);
			} catch (Exception) {
				Logger.Default.LogMessage("XMLの解析に失敗しました。");
				return null;
			}

			XmlNode root = xdoc["response_ngword"];

			if (root == null || root.Attributes["status"].Value != "ok") {
				Logger.Default.LogMessage("サーバーの問題によりNG一覧を取得できませんでした。");
				return null;
			}

			int count = 0;
			int.TryParse(xdoc.SelectSingleNode("response_ngword/count").InnerText, out count);
			List<NgClient> clients = new List<NgClient>(count);
			foreach (XmlNode node in xdoc.SelectNodes("response_ngword/ngclient")) {
				try {
					NgClient n = new NgClient(node);
					clients.Add(n);
				} catch(Exception ex) {
					Logger.Default.LogException(ex);
				}
			}

			return clients.ToArray();

		}