| | 972 | foreach (Status status in statuses.Status) |
| | 973 | { |
| | 974 | ProcessTimelineStatus (status, ref friendsCheckRequired); |
| | 975 | } |
| | 976 | statuses = _twitter.GetReplies(); |
| | 977 | Array.Reverse(statuses.Status); |
| | 978 | bool dummy = false; |
| | 979 | foreach (Status status in statuses.Status) |
| | 980 | { |
| | 981 | if (status.CreatedAt < _lastAccessTimeline) |
| | 982 | continue; |
| | 983 | // Here I pass dummy, because no matter how the replier flags |
| | 984 | // friendsCheckRequired, we cannot receive his or her info |
| | 985 | // through get_friends. |
| | 986 | ProcessTimelineStatus (status, ref dummy); |
| | 987 | } |
| | 988 | |
| 976 | | foreach (Status status in statuses.Status) |
| 977 | | { |
| 978 | | // 差分チェック |
| 979 | | if (_server.EnableDropProtection) |
| 980 | | { |
| 981 | | if (_statusBuffer.Contains(status)) |
| 982 | | continue; |
| 983 | | |
| 984 | | _statusBuffer.AddLast(status); |
| 985 | | if (_statusBuffer.Count > 100) |
| | 993 | _isFirstTime = false; |
| | 994 | } |
| | 995 | catch (WebException ex) |
| | 996 | { |
| | 997 | if (ex.Response == null || !(ex.Response is HttpWebResponse) || ((HttpWebResponse)(ex.Response)).StatusCode != HttpStatusCode.NotModified) |
| | 998 | { |
| | 999 | // not-modified 以外 |
| | 1000 | SendServerErrorMessage(ex.Message); |
| | 1001 | } |
| | 1002 | return false; |
| | 1003 | } |
| | 1004 | catch (TwitterServiceException ex2) |
| | 1005 | { |
| | 1006 | SendServerErrorMessage(ex2.Message); |
| | 1007 | return false; |
| | 1008 | } |
| | 1009 | |
| | 1010 | return true; |
| | 1011 | } |
| | 1012 | |
| | 1013 | private void ProcessTimelineStatus (Status status, ref Boolean friendsCheckRequired) |
| | 1014 | { |
| | 1015 | // 差分チェック |
| | 1016 | if (_server.EnableDropProtection) |
| | 1017 | { |
| | 1018 | if (_statusBuffer.Contains(status)) |
| | 1019 | return; |
| | 1020 | |
| | 1021 | _statusBuffer.AddLast(status); |
| | 1022 | if (_statusBuffer.Count > 100) |
| | 1023 | { |
| | 1024 | // 一番古いのを消す |
| | 1025 | //Status oldStatus = null; |
| | 1026 | //foreach (Status statTmp in _statusBuffer) |
| | 1027 | //{ |
| | 1028 | // if (oldStatus == null || oldStatus.CreatedAt > statTmp.CreatedAt) |
| | 1029 | // { |
| | 1030 | // oldStatus = statTmp; |
| | 1031 | // } |
| | 1032 | //} |
| | 1033 | //_statusBuffer.Remove(oldStatus); |
| | 1034 | _statusBuffer.RemoveFirst(); |
| | 1035 | } |
| | 1036 | } |
| | 1037 | |
| | 1038 | // チェック |
| | 1039 | if (status.User == null || String.IsNullOrEmpty(status.User.ScreenName)) |
| | 1040 | { |
| | 1041 | return; |
| | 1042 | } |
| | 1043 | |
| | 1044 | // friends チェックが必要かどうかを確かめる |
| | 1045 | // まだないときは取ってくるフラグを立てる |
| | 1046 | friendsCheckRequired |= !(_nickNames.Contains(status.User.ScreenName)); |
| | 1047 | |
| | 1048 | // フィルタ |
| | 1049 | FilterArgs filterArgs = new FilterArgs(this, status.Text, status.User, "PRIVMSG", false); |
| | 1050 | if (!_filter.ExecuteFilters(filterArgs)) |
| | 1051 | { |
| | 1052 | // 捨てる |
| | 1053 | return; |
| | 1054 | } |
| | 1055 | |
| | 1056 | // 自分がゲートウェイを通して発言したものは捨てる |
| | 1057 | if (_lastStatusIdsFromGateway.Contains(status.Id)) |
| | 1058 | { |
| | 1059 | return; |
| | 1060 | } |
| | 1061 | |
| | 1062 | // TinyURL |
| | 1063 | String text = (_server.ResolveTinyUrl) ? Utility.ResolveTinyUrlInMessage(filterArgs.Content) : filterArgs.Content; |
| | 1064 | |
| | 1065 | String[] lines = text.Split(new Char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); |
| | 1066 | foreach (String line in lines) |
| | 1067 | { |
| | 1068 | // 初回はrecentろぐっぽく |
| | 1069 | if (_isFirstTime) |
| | 1070 | { |
| | 1071 | NoticeMessage noticeMsg = new NoticeMessage(); |
| | 1072 | noticeMsg.SenderNick = status.User.ScreenName; |
| | 1073 | noticeMsg.SenderHost = "twitter@" + Server.ServerName; |
| | 1074 | noticeMsg.Receiver = _server.ChannelName; |
| | 1075 | noticeMsg.Content = String.Format("{0}: {1}", status.CreatedAt.ToString("HH:mm"), line); |
| | 1076 | Send(noticeMsg); |
| | 1077 | } |
| | 1078 | else |
| | 1079 | { |
| | 1080 | IRCMessage msg; |
| | 1081 | switch (filterArgs.IRCMessageType.ToUpperInvariant()) |
| | 1082 | { |
| | 1083 | case "NOTICE": |
| | 1084 | msg = new NoticeMessage(_server.ChannelName, line); |
| | 1085 | break; |
| | 1086 | case "PRIVMSG": |
| | 1087 | default: |
| | 1088 | msg = new PrivMsgMessage(_server.ChannelName, line); |
| | 1089 | break; |
| | 1090 | } |
| | 1091 | msg.SenderNick = status.User.ScreenName; |
| | 1092 | msg.SenderHost = "twitter@" + Server.ServerName; |
| | 1093 | Send(msg); |
| | 1094 | |
| | 1095 | // グループにも投げる |
| | 1096 | foreach (Group group in _groups.Values) |
| | 1097 | { |
| | 1098 | if (group.IsJoined && group.Exists(status.User.ScreenName)) |
| 987 | | // 一番古いのを消す |
| 988 | | //Status oldStatus = null; |
| 989 | | //foreach (Status statTmp in _statusBuffer) |
| 990 | | //{ |
| 991 | | // if (oldStatus == null || oldStatus.CreatedAt > statTmp.CreatedAt) |
| 992 | | // { |
| 993 | | // oldStatus = statTmp; |
| 994 | | // } |
| 995 | | //} |
| 996 | | //_statusBuffer.Remove(oldStatus); |
| 997 | | _statusBuffer.RemoveFirst(); |
| 998 | | } |
| 999 | | } |
| 1000 | | |
| 1001 | | // チェック |
| 1002 | | if (status.User == null || String.IsNullOrEmpty(status.User.ScreenName)) |
| 1003 | | { |
| 1004 | | continue; |
| 1005 | | } |
| 1006 | | |
| 1007 | | // friends チェックが必要かどうかを確かめる |
| 1008 | | // まだないときは取ってくるフラグを立てる |
| 1009 | | friendsCheckRequired |= !(_nickNames.Contains(status.User.ScreenName)); |
| 1010 | | |
| 1011 | | // フィルタ |
| 1012 | | FilterArgs filterArgs = new FilterArgs(this, status.Text, status.User, "PRIVMSG", false); |
| 1013 | | if (!_filter.ExecuteFilters(filterArgs)) |
| 1014 | | { |
| 1015 | | // 捨てる |
| 1016 | | continue; |
| 1017 | | } |
| 1018 | | |
| 1019 | | // 自分がゲートウェイを通して発言したものは捨てる |
| 1020 | | if (_lastStatusIdsFromGateway.Contains(status.Id)) |
| 1021 | | { |
| 1022 | | continue; |
| 1023 | | } |
| 1024 | | |
| 1025 | | // TinyURL |
| 1026 | | String text = (_server.ResolveTinyUrl) ? Utility.ResolveTinyUrlInMessage(filterArgs.Content) : filterArgs.Content; |
| 1027 | | |
| 1028 | | String[] lines = text.Split(new Char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); |
| 1029 | | foreach (String line in lines) |
| 1030 | | { |
| 1031 | | // 初回はrecentろぐっぽく |
| 1032 | | if (_isFirstTime) |
| 1033 | | { |
| 1034 | | NoticeMessage noticeMsg = new NoticeMessage(); |
| 1035 | | noticeMsg.SenderNick = status.User.ScreenName; |
| 1036 | | noticeMsg.SenderHost = "twitter@" + Server.ServerName; |
| 1037 | | noticeMsg.Receiver = _server.ChannelName; |
| 1038 | | noticeMsg.Content = String.Format("{0}: {1}", status.CreatedAt.ToString("HH:mm"), line); |
| 1039 | | Send(noticeMsg); |
| 1040 | | } |
| 1041 | | else |
| 1042 | | { |
| 1043 | | IRCMessage msg; |
| 1080 | | |
| 1081 | | // 最終更新時刻 |
| 1082 | | if (_server.EnableDropProtection) |
| 1083 | | { |
| 1084 | | // 取りこぼし防止しているときは一番古い日付 |
| 1085 | | if (status.CreatedAt < _lastAccessTimeline) |
| 1086 | | { |
| 1087 | | _lastAccessTimeline = status.CreatedAt; |
| 1088 | | } |
| 1089 | | } |
| 1090 | | else |
| 1091 | | { |
| 1092 | | if (status.CreatedAt > _lastAccessTimeline) |
| 1093 | | { |
| 1094 | | _lastAccessTimeline = status.CreatedAt; |
| 1095 | | } |
| 1096 | | } |
| 1097 | | } |
| 1098 | | _isFirstTime = false; |
| 1099 | | } |
| 1100 | | catch (WebException ex) |
| 1101 | | { |
| 1102 | | if (ex.Response == null || !(ex.Response is HttpWebResponse) || ((HttpWebResponse)(ex.Response)).StatusCode != HttpStatusCode.NotModified) |
| 1103 | | { |
| 1104 | | // not-modified 以外 |
| 1105 | | SendServerErrorMessage(ex.Message); |
| 1106 | | } |
| 1107 | | return false; |
| 1108 | | } |
| 1109 | | catch (TwitterServiceException ex2) |
| 1110 | | { |
| 1111 | | SendServerErrorMessage(ex2.Message); |
| 1112 | | return false; |
| 1113 | | } |
| 1114 | | |
| 1115 | | return true; |
| | 1115 | } |
| | 1116 | } |
| | 1117 | |
| | 1118 | // 最終更新時刻 |
| | 1119 | if (_server.EnableDropProtection) |
| | 1120 | { |
| | 1121 | // 取りこぼし防止しているときは一番古い日付 |
| | 1122 | if (status.CreatedAt < _lastAccessTimeline) |
| | 1123 | { |
| | 1124 | _lastAccessTimeline = status.CreatedAt; |
| | 1125 | } |
| | 1126 | } |
| | 1127 | else |
| | 1128 | { |
| | 1129 | if (status.CreatedAt > _lastAccessTimeline) |
| | 1130 | { |
| | 1131 | _lastAccessTimeline = status.CreatedAt; |
| | 1132 | } |
| | 1133 | } |