Changeset 70
- Timestamp:
- 05/12/07 20:44:55 (19 months ago)
- Location:
- TwitterIrcGateway/TwitterIrcGatewayCore
- Files:
-
- 4 modified
-
Filter.cs (modified) (1 diff)
-
Session.cs (modified) (50 diffs)
-
TwitterService.cs (modified) (13 diffs)
-
Utility.cs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
TwitterIrcGateway/TwitterIrcGatewayCore/Filter.cs
r59 r70 50 50 51 51 /// <summary> 52 /// ���b�Z�[�W��B���^���܂�52 /// メッセージをフィルタします 53 53 /// </summary> 54 54 /// <param name="user"></param> 55 55 /// <param name="message"></param> 56 /// <returns> ���b�Z�[�W��Ă邩�ǂ���</returns>56 /// <returns>メッセージを捨てるかどうか</returns> 57 57 public Boolean ExecuteFilters(FilterArgs args) 58 58 { -
TwitterIrcGateway/TwitterIrcGatewayCore/Session.cs
r69 r70 112 112 private void OnTimerCallback(Object stateObject) 113 113 { 114 // ���܂��������x���Ɠ�ɂȂ��\�������� lock (_timer) 114 // あまりに処理が遅れると二重になる可能性がある 115 lock (_timer) 115 116 { 116 117 if (_isCallbackRunning) … … 133 134 134 135 /// <summary> 135 /// �Z�b�V������n���܂��B136 /// セッションを開始します。 136 137 /// </summary> 137 138 public void Start() … … 152 153 { 153 154 //Console.WriteLine(line); 155 line = line.Replace('〜', '~'); 154 156 IRCMessage msg = IRCMessage.CreateMessage(line); 155 157 OnMessageRecieved(msg); … … 174 176 } 175 177 176 #region �C�x���g��s���\�b�h178 #region イベント実行メソッド 177 179 178 180 protected virtual void OnMessageRecieved(IRCMessage msg) … … 201 203 private void LoadFilters() 202 204 { 203 // filters �ǂݎ�205 // filters 読み取り 204 206 String path = Path.Combine(ConfigBasePath, Path.Combine(_nick, "Filters.xml")); 205 207 if (File.Exists(path)) … … 228 230 catch (IOException ie) 229 231 { 230 SendTwitterGatewayServerMessage(" �G���[: " + ie.Message);232 SendTwitterGatewayServerMessage("エラー: " + ie.Message); 231 233 Trace.WriteLine(ie.Message); 232 234 } … … 239 241 private void LoadGroups() 240 242 { 241 // group �ǂݎ�243 // group 読み取り 242 244 String path = Path.Combine(ConfigBasePath, Path.Combine(_nick, "Groups.xml")); 243 245 if (File.Exists(path)) … … 259 261 catch (IOException ie) 260 262 { 261 SendTwitterGatewayServerMessage(" �G���[: " + ie.Message);263 SendTwitterGatewayServerMessage("エラー: " + ie.Message); 262 264 Trace.WriteLine(ie.Message); 263 265 } … … 269 271 private void SaveGroups() 270 272 { 271 // group �ǂݎ�273 // group 読み取り 272 274 lock (_groups) 273 275 { … … 290 292 catch (IOException ie) 291 293 { 292 SendTwitterGatewayServerMessage(" �G���[: " + ie.Message);294 SendTwitterGatewayServerMessage("エラー: " + ie.Message); 293 295 Trace.WriteLine(ie.Message); 294 296 } … … 308 310 private Group GetGroupByChannelName(String channelName) 309 311 { 310 // �O���[�v���/�쐬312 // グループを取得/作成 311 313 Group group; 312 314 if (!_groups.TryGetValue(channelName, out group)) … … 318 320 } 319 321 320 #region ���b�Z�[�W�����C�x���g322 #region メッセージ処理イベント 321 323 private void MessageRecieved_JOIN(object sender, MessageRecievedEventArgs e) 322 324 { … … 339 341 } 340 342 341 // �O���[�v���/�쐬343 // グループを取得/作成 342 344 Group group = GetGroupByChannelName(channelName); 343 345 if (!group.Exists(_nick)) … … 376 378 } 377 379 378 // �O���[�v���/�쐬380 // グループを取得/作成 379 381 Group group; 380 382 if (_groups.TryGetValue(channelName, out group)) … … 393 395 group.Remove(_nick); 394 396 395 // ���̂ĂĂ���?397 // もう捨てていい? 396 398 if (group.Members.Count == 0) 397 399 { 398 400 _groups.Remove(group.Name); 399 SendTwitterGatewayServerMessage(" �O���[�v \""+group.Name+"\" ������܂����B");401 SendTwitterGatewayServerMessage("グループ \""+group.Name+"\" を削除しました。"); 400 402 } 401 403 } … … 415 417 if (channels.Length == 1) 416 418 { 417 // �������l�����畡�����肾��419 // 一チャンネルから複数けりだす 418 420 Group group; 419 421 if (!_groups.TryGetValue(channels[0], out group)) … … 444 446 else 445 447 { 446 // �����`�����l�����炻�ꂼ�� for (Int32 i = 0; i < channels.Length; i++) 448 // 複数チャンネルからそれぞれ 449 for (Int32 i = 0; i < channels.Length; i++) 447 450 { 448 451 String channelName = channels[i]; … … 501 504 } 502 505 503 // �O���[�v����A���[�U�lj�506 // グループを取得、ユーザ追加 504 507 Group group = GetGroupByChannelName(channelName); 505 508 if (!group.Exists(userName)) … … 533 536 } 534 537 535 _username = e.Message.CommandParams[0]; // username��twitter��D�ƂȂ� _twitter = new TwitterService(_username, _password); 538 _username = e.Message.CommandParams[0]; // usernameがtwitterのIDとなる 539 _twitter = new TwitterService(_username, _password); 536 540 537 541 Type t = typeof(Server); … … 605 609 try 606 610 { 607 // �`�����l�����͎����̃��b�Z�[�W�������611 // チャンネル宛は自分のメッセージを書き換え 608 612 if (message.Receiver == Server.ChannelName || message.Receiver.StartsWith("#")) 609 613 { … … 611 615 _lastStatusFromGateway = message.Content; 612 616 613 // topic �ɂ��� if (_server.SetTopicOnStatusChanged) 617 // topic にする 618 if (_server.SetTopicOnStatusChanged) 614 619 { 615 620 TopicMessage topicMsg = new TopicMessage(Server.ChannelName, message.Content); … … 619 624 620 625 #if FALSE 621 // ���̃`�����l���ɂ����� foreach (Group group in _groups.Values) 626 // 他のチャンネルにも投げる 627 foreach (Group group in _groups.Values) 622 628 { 623 629 if (group.IsJoined && String.Compare(message.Receiver, group.Name, true) != 0) … … 634 640 else 635 641 { 636 // �l�ɑ�������irect Message642 // 人に対する場合はDirect Message 637 643 _twitter.SendDirectMessage(message.Receiver, message.Content); 638 644 } … … 643 649 noticeMsg.SenderHost = Server.ServerName; 644 650 noticeMsg.Receiver = message.Receiver; 645 noticeMsg.Content = " ���b�Z�[�W���M�̃��g���C�ɐ���܂����B";651 noticeMsg.Content = "メッセージ送信のリトライに成功しました。"; 646 652 Send(noticeMsg); 647 653 } … … 653 659 noticeMsg.SenderHost = Server.ServerName; 654 660 noticeMsg.Receiver = message.Receiver; 655 noticeMsg.Content = String.Format(" ���b�Z�[�W���M�Ɏ��s���܂���({0})" + (!isRetry ? "/���g���C���܂��B" : ""), ex.Message.Replace("\n", " "));661 noticeMsg.Content = String.Format("メッセージ送信に失敗しました({0})" + (!isRetry ? "/リトライします。" : ""), ex.Message.Replace("\n", " ")); 656 662 Send(noticeMsg); 657 663 658 // ���������g���C����664 // 一回だけリトライするよ 659 665 if (!isRetry) 660 666 { … … 687 693 catch (WebException we) 688 694 { 689 SendTwitterGatewayServerMessage(" �G���[: " + we.Message);695 SendTwitterGatewayServerMessage("エラー: " + we.Message); 690 696 } 691 697 catch (TwitterServiceException tse) 692 698 { 693 SendTwitterGatewayServerMessage(" �G���[: " + tse.Message);699 SendTwitterGatewayServerMessage("エラー: " + tse.Message); 694 700 } 695 701 … … 697 703 return; 698 704 699 // �X�e�[�^�X��IS reply�Ƃ��ĕԂ�705 // ステータスをWHOIS replyとして返す 700 706 SendNumericReply(NumericReply.RPL_WHOISUSER, user.ScreenName, user.Id.ToString(), "localhost", "*", user.Name + " - " + user.Description); 701 707 SendNumericReply(NumericReply.RPL_WHOISSERVER, user.ScreenName, "WebSite", user.Url); … … 730 736 731 737 /// <summary> 732 /// JOIN �Ƃ��N���C�A���g�ɕԂ���738 /// JOIN とかクライアントに返すやつ 733 739 /// </summary> 734 740 /// <param name="msg"></param> … … 740 746 741 747 /// <summary> 742 /// IRC �T�[�o���b�Z�[�W�n748 /// IRCサーバメッセージ系 743 749 /// </summary> 744 750 /// <param name="msg"></param> … … 750 756 751 757 /// <summary> 752 /// �T�[�o���b�Z�[�W�n758 /// サーバメッセージ系 753 759 /// </summary> 754 760 /// <param name="msg"></param> … … 763 769 764 770 /// <summary> 765 /// �T�[�o�G���[���b�Z�[�W�n771 /// サーバエラーメッセージ系 766 772 /// </summary> 767 773 /// <param name="message"></param> … … 770 776 if (!_server.IgnoreWatchError) 771 777 { 772 SendTwitterGatewayServerMessage(" �G���[: " + message);773 } 774 } 775 776 /// <summary> 777 /// �T�[�o�������C�A���g�ɃG���[���v���C����܂��B778 /// </summary> 779 /// <param name="errorNum"> �G���[���v���C�ԍ�</param>780 /// <param name="commandParams"> ���v���C�R�}���h�p�����[�^</param>778 SendTwitterGatewayServerMessage("エラー: " + message); 779 } 780 } 781 782 /// <summary> 783 /// サーバからクライアントにエラーリプライを返します。 784 /// </summary> 785 /// <param name="errorNum">エラーリプライ番号</param> 786 /// <param name="commandParams">リプライコマンドパラメータ</param> 781 787 public void SendErrorReply(ErrorReply errorNum, params String[] commandParams) 782 788 { … … 785 791 786 792 /// <summary> 787 /// �T�[�o�������C�A���g�Ƀj�������b�N���v���C����܂��B788 /// </summary> 789 /// <param name="numReply"> ���v���C�ԍ�</param>790 /// <param name="commandParams"> ���v���C�R�}���h�p�����[�^</param>793 /// サーバからクライアントにニュメリックリプライを返します。 794 /// </summary> 795 /// <param name="numReply">リプライ番号</param> 796 /// <param name="commandParams">リプライコマンドパラメータ</param> 791 797 public void SendNumericReply(NumericReply numReply, params String[] commandParams) 792 798 { … … 821 827 if (ex.Response == null || (ex.Response is HttpWebResponse) && ((HttpWebResponse)(ex.Response)).StatusCode != HttpStatusCode.NotModified) 822 828 { 823 // not-modified �ȊO829 // not-modified 以外 824 830 SendTwitterGatewayServerMessage(ex.Message); 825 831 } … … 858 864 })); 859 865 860 // �Ă��Ƃ��ɁB861 // ��������866 // てきとうに。 867 // 増えた分 862 868 foreach (String screenName in screenNames) 863 869 { … … 870 876 } 871 877 } 872 // �������878 // 減った分 873 879 foreach (String screenName in _nickNames) 874 880 { … … 889 895 if (ex.Response == null || !(ex.Response is HttpWebResponse) || ((HttpWebResponse)(ex.Response)).StatusCode != HttpStatusCode.NotModified) 890 896 { 891 // not-modified �ȊO897 // not-modified 以外 892 898 SendServerErrorMessage(ex.Message); 893 899 } … … 911 917 foreach (Status status in statuses.Status) 912 918 { 913 // �����`�F�b�N919 // 差分チェック 914 920 if (_server.EnableDropProtection) 915 921 { … … 920 926 if (_statusBuffer.Count > 50) 921 927 { 922 // ���Â��̂��928 // 一番古いのを消す 923 929 Status oldStatus = null; 924 930 foreach (Status statTmp in _statusBuffer) … … 933 939 } 934 940 935 // �`�F�b�N941 // チェック 936 942 if (status.User == null || String.IsNullOrEmpty(status.User.ScreenName)) 937 943 { … … 939 945 } 940 946 941 // �t�B���^947 // フィルタ 942 948 FilterArgs filterArgs = new FilterArgs(this, status.Text, status.User, "PRIVMSG", false); 943 949 if (!_filter.ExecuteFilters(filterArgs)) 944 950 { 945 // �̂Ă� continue; 951 // 捨てる 952 continue; 946 953 } 947 954 … … 952 959 foreach (String line in lines) 953 960 { 954 // ����ecent�낮��ۂ�961 // 初回はrecentろぐっぽく 955 962 if (_isFirstTime) 956 963 { … … 964 971 else if (_lastStatusFromGateway != line || String.Compare(status.User.ScreenName, _nick, true) != 0) 965 972 { 966 // �Q�[�g�E�F�C����đ��M���ꂽ�����̃��b�Z�[�W�͏���973 // ゲートウェイを通して送信された自分のメッセージは除く 967 974 IRCMessage msg; 968 975 switch (filterArgs.IRCMessageType.ToUpperInvariant()) … … 1002 1009 } 1003 1010 1004 // �ŏI�X�V����1011 // 最終更新時刻 1005 1012 if (_server.EnableDropProtection) 1006 1013 { 1007 // �����ڂ��h�~���Ă������͈��Â��� if (status.CreatedAt < _lastAccessTimeline) 1014 // 取りこぼし防止しているときは一番古い日付 1015 if (status.CreatedAt < _lastAccessTimeline) 1008 1016 { 1009 1017 _lastAccessTimeline = status.CreatedAt; … … 1024 1032 if (ex.Response == null || !(ex.Response is HttpWebResponse) || ((HttpWebResponse)(ex.Response)).StatusCode != HttpStatusCode.NotModified) 1025 1033 { 1026 // not-modified �ȊO1034 // not-modified 以外 1027 1035 SendServerErrorMessage(ex.Message); 1028 1036 } … … 1046 1054 foreach (DirectMessage message in directMessages.DirectMessage) 1047 1055 { 1048 // �`�F�b�N1056 // チェック 1049 1057 if (message == null || String.IsNullOrEmpty(message.SenderScreenName)) 1050 1058 { … … 1065 1073 Send(privMsg); 1066 1074 } 1067 // �ŏI�X�V����1075 // 最終更新時刻 1068 1076 if (message.CreatedAt > _lastAccessDirectMessage) 1069 1077 { … … 1076 1084 if (ex.Response == null || !(ex.Response is HttpWebResponse) || ((HttpWebResponse)(ex.Response)).StatusCode != HttpStatusCode.NotModified) 1077 1085 { 1078 // not-modified �ȊO1086 // not-modified 以外 1079 1087 SendServerErrorMessage(ex.Message); 1080 1088 } … … 1103 1111 } 1104 1112 1105 #region IDisposable �����o1113 #region IDisposable メンバ 1106 1114 private Boolean _isDisposed = false; 1107 1115 … … 1119 1127 _timer.Dispose(); 1120 1128 1121 // �ꉞ�҂�1129 // 一応待つ 1122 1130 while (_isCallbackRunning) 1123 1131 Thread.Sleep(100); -
TwitterIrcGateway/TwitterIrcGatewayCore/TwitterService.cs
r51 r70 45 45 { 46 46 String encodedMessage = TwitterService.EncodeMessage(message); 47 String responseBody = POST(String.Format("http://twitter.com/statuses/update.xml?status={0}", encodedMessage), Encoding.Default.GetBytes("1")); 47 try 48 { 49 String responseBody = POST(String.Format("http://twitter.com/statuses/update.xml?status={0}", encodedMessage), Encoding.Default.GetBytes("1")); 50 } 51 catch (IOException e) 52 { 53 throw new TwitterServiceException(e); 54 } 48 55 } 49 56 … … 56 63 { 57 64 String encodedMessage = TwitterService.EncodeMessage(message); 58 String responseBody = GET(String.Format("http://twitter.com/direct_messages/new.xml?user={0}&text={1}", targetId, encodedMessage)); 65 try 66 { 67 String responseBody = GET(String.Format("http://twitter.com/direct_messages/new.xml?user={0}&text={1}", targetId, encodedMessage)); 68 } 69 catch (IOException e) 70 { 71 throw new TwitterServiceException(e); 72 } 59 73 } 60 74 … … 66 80 public User[] GetFriends() 67 81 { 68 String responseBody = null;69 responseBody = GET(String.Format("http://twitter.com/statuses/friends.xml", _userName));70 71 82 try 72 83 { 84 String responseBody = GET(String.Format("http://twitter.com/statuses/friends.xml", _userName)); 73 85 if (NilClasses.CanDeserialize(responseBody)) 74 86 { … … 91 103 throw new TwitterServiceException(xe); 92 104 } 105 catch (IOException ie) 106 { 107 throw new TwitterServiceException(ie); 108 } 93 109 } 94 110 … … 100 116 public User GetUser(String id) 101 117 { 102 String responseBody = null;103 responseBody = GET(String.Format("http://twitter.com/users/show/{0}.xml", id));104 105 118 try 106 119 { 120 String responseBody = GET(String.Format("http://twitter.com/users/show/{0}.xml", id)); 107 121 if (NilClasses.CanDeserialize(responseBody)) 108 122 { … … 122 136 { 123 137 throw new TwitterServiceException(xe); 138 } 139 catch (IOException ie) 140 {
