Changeset 70

Show
Ignore:
Timestamp:
05/12/07 20:44:55 (19 months ago)
Author:
mayuki
Message:
 
Location:
TwitterIrcGateway/TwitterIrcGatewayCore
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • TwitterIrcGateway/TwitterIrcGatewayCore/Filter.cs

    r59 r70  
    5050 
    5151        /// <summary> 
    52         /// ���b�Z�[�W��B���^���܂� 
     52        /// メッセージをフィルタします 
    5353        /// </summary> 
    5454        /// <param name="user"></param> 
    5555        /// <param name="message"></param> 
    56         /// <returns>���b�Z�[�W��Ă邩�ǂ���</returns> 
     56        /// <returns>メッセージを捨てるかどうか</returns> 
    5757        public Boolean ExecuteFilters(FilterArgs args) 
    5858        { 
  • TwitterIrcGateway/TwitterIrcGatewayCore/Session.cs

    r69 r70  
    112112        private void OnTimerCallback(Object stateObject) 
    113113        { 
    114             // ���܂��������x���Ɠ�ɂȂ��\��������            lock (_timer) 
     114            // あまりに処理が遅れると二重になる可能性がある 
     115            lock (_timer) 
    115116            { 
    116117                if (_isCallbackRunning) 
     
    133134 
    134135        /// <summary> 
    135         /// �Z�b�V������n���܂��B 
     136        /// セッションを開始します。 
    136137        /// </summary> 
    137138        public void Start() 
     
    152153                        { 
    153154                            //Console.WriteLine(line); 
     155                            line = line.Replace('〜', '~'); 
    154156                            IRCMessage msg = IRCMessage.CreateMessage(line); 
    155157                            OnMessageRecieved(msg); 
     
    174176        } 
    175177 
    176         #region �C�x���g��s���\�b�h 
     178        #region イベント実行メソッド 
    177179 
    178180        protected virtual void OnMessageRecieved(IRCMessage msg) 
     
    201203        private void LoadFilters() 
    202204        { 
    203             // filters �ǂݎ� 
     205            // filters 読み取り 
    204206            String path = Path.Combine(ConfigBasePath, Path.Combine(_nick, "Filters.xml")); 
    205207            if (File.Exists(path)) 
     
    228230                catch (IOException ie) 
    229231                { 
    230                     SendTwitterGatewayServerMessage("�G���[: " + ie.Message); 
     232                    SendTwitterGatewayServerMessage("エラー: " + ie.Message); 
    231233                    Trace.WriteLine(ie.Message); 
    232234                } 
     
    239241        private void LoadGroups() 
    240242        { 
    241            // group �ǂݎ� 
     243           // group 読み取り 
    242244            String path = Path.Combine(ConfigBasePath, Path.Combine(_nick, "Groups.xml")); 
    243245            if (File.Exists(path)) 
     
    259261                catch (IOException ie) 
    260262                { 
    261                     SendTwitterGatewayServerMessage("�G���[: " + ie.Message); 
     263                    SendTwitterGatewayServerMessage("エラー: " + ie.Message); 
    262264                    Trace.WriteLine(ie.Message); 
    263265                } 
     
    269271        private void SaveGroups() 
    270272        { 
    271             // group �ǂݎ� 
     273            // group 読み取り 
    272274            lock (_groups) 
    273275            { 
     
    290292                catch (IOException ie) 
    291293                { 
    292                     SendTwitterGatewayServerMessage("�G���[: " + ie.Message); 
     294                    SendTwitterGatewayServerMessage("エラー: " + ie.Message); 
    293295                    Trace.WriteLine(ie.Message); 
    294296                } 
     
    308310        private Group GetGroupByChannelName(String channelName) 
    309311        { 
    310             // �O���[�v���/�쐬 
     312            // グループを取得/作成 
    311313            Group group; 
    312314            if (!_groups.TryGetValue(channelName, out group)) 
     
    318320        } 
    319321 
    320         #region ���b�Z�[�W�����C�x���g 
     322        #region メッセージ処理イベント 
    321323        private void MessageRecieved_JOIN(object sender, MessageRecievedEventArgs e) 
    322324        { 
     
    339341                } 
    340342 
    341                 // �O���[�v���/�쐬 
     343                // グループを取得/作成 
    342344                Group group = GetGroupByChannelName(channelName); 
    343345                if (!group.Exists(_nick)) 
     
    376378                } 
    377379 
    378                 // �O���[�v���/�쐬 
     380                // グループを取得/作成 
    379381                Group group; 
    380382                if (_groups.TryGetValue(channelName, out group)) 
     
    393395                    group.Remove(_nick); 
    394396 
    395                 // ���̂ĂĂ���? 
     397                // もう捨てていい? 
    396398                if (group.Members.Count == 0) 
    397399                { 
    398400                    _groups.Remove(group.Name); 
    399                     SendTwitterGatewayServerMessage("�O���[�v \""+group.Name+"\" ������܂����B"); 
     401                    SendTwitterGatewayServerMessage("グループ \""+group.Name+"\" を削除しました。"); 
    400402                } 
    401403            } 
     
    415417            if (channels.Length == 1) 
    416418            { 
    417                 // �������l�����畡�����肾�� 
     419                // 一チャンネルから複数けりだす 
    418420                Group group; 
    419421                if (!_groups.TryGetValue(channels[0], out group)) 
     
    444446            else 
    445447            { 
    446                 // �����`�����l�����炻�ꂼ��                for (Int32 i = 0; i < channels.Length; i++) 
     448                // 複数チャンネルからそれぞれ 
     449                for (Int32 i = 0; i < channels.Length; i++) 
    447450                { 
    448451                    String channelName = channels[i]; 
     
    501504            } 
    502505 
    503             // �O���[�v����A���[�U�lj� 
     506            // グループを取得、ユーザ追加 
    504507            Group group = GetGroupByChannelName(channelName); 
    505508            if (!group.Exists(userName)) 
     
    533536            } 
    534537 
    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); 
    536540 
    537541            Type t = typeof(Server); 
     
    605609            try 
    606610            { 
    607                 // �`�����l�����͎����̃��b�Z�[�W������� 
     611                // チャンネル宛は自分のメッセージを書き換え 
    608612                if (message.Receiver == Server.ChannelName || message.Receiver.StartsWith("#")) 
    609613                { 
     
    611615                    _lastStatusFromGateway = message.Content; 
    612616 
    613                     // topic �ɂ���                    if (_server.SetTopicOnStatusChanged) 
     617                    // topic にする 
     618                    if (_server.SetTopicOnStatusChanged) 
    614619                    { 
    615620                        TopicMessage topicMsg = new TopicMessage(Server.ChannelName, message.Content); 
     
    619624 
    620625#if FALSE 
    621                     // ���̃`�����l���ɂ�����                    foreach (Group group in _groups.Values) 
     626                    // 他のチャンネルにも投げる 
     627                    foreach (Group group in _groups.Values) 
    622628                    { 
    623629                        if (group.IsJoined && String.Compare(message.Receiver, group.Name, true) != 0) 
     
    634640                else 
    635641                { 
    636                     // �l�ɑ΂�������irect Message 
     642                    // 人に対する場合はDirect Message 
    637643                    _twitter.SendDirectMessage(message.Receiver, message.Content); 
    638644                } 
     
    643649                    noticeMsg.SenderHost = Server.ServerName; 
    644650                    noticeMsg.Receiver = message.Receiver; 
    645                     noticeMsg.Content = "���b�Z�[�W���M�̃��g���C�ɐ���܂����B"; 
     651                    noticeMsg.Content = "メッセージ送信のリトライに成功しました。"; 
    646652                    Send(noticeMsg); 
    647653                } 
     
    653659                noticeMsg.SenderHost = Server.ServerName; 
    654660                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", " ")); 
    656662                Send(noticeMsg); 
    657663 
    658                 // ���������g���C���� 
     664                // 一回だけリトライするよ 
    659665                if (!isRetry) 
    660666                { 
     
    687693            catch (WebException we) 
    688694            { 
    689                 SendTwitterGatewayServerMessage("�G���[: " + we.Message); 
     695                SendTwitterGatewayServerMessage("エラー: " + we.Message); 
    690696            } 
    691697            catch (TwitterServiceException tse) 
    692698            { 
    693                 SendTwitterGatewayServerMessage("�G���[: " + tse.Message); 
     699                SendTwitterGatewayServerMessage("エラー: " + tse.Message); 
    694700            } 
    695701 
     
    697703                return; 
    698704 
    699             // �X�e�[�^�X��IS reply�Ƃ��ĕԂ� 
     705            // ステータスをWHOIS replyとして返す 
    700706            SendNumericReply(NumericReply.RPL_WHOISUSER, user.ScreenName, user.Id.ToString(), "localhost", "*", user.Name + " - " + user.Description); 
    701707            SendNumericReply(NumericReply.RPL_WHOISSERVER, user.ScreenName, "WebSite", user.Url); 
     
    730736 
    731737        /// <summary> 
    732         /// JOIN �Ƃ��N���C�A���g�ɕԂ��� 
     738        /// JOIN とかクライアントに返すやつ 
    733739        /// </summary> 
    734740        /// <param name="msg"></param> 
     
    740746 
    741747        /// <summary> 
    742         /// IRC�T�[�o���b�Z�[�W�n 
     748        /// IRCサーバメッセージ系 
    743749        /// </summary> 
    744750        /// <param name="msg"></param> 
     
    750756 
    751757        /// <summary> 
    752         /// �T�[�o���b�Z�[�W�n 
     758        /// サーバメッセージ系 
    753759        /// </summary> 
    754760        /// <param name="msg"></param> 
     
    763769 
    764770        /// <summary> 
    765         /// �T�[�o�G���[���b�Z�[�W�n 
     771        /// サーバエラーメッセージ系 
    766772        /// </summary> 
    767773        /// <param name="message"></param> 
     
    770776            if (!_server.IgnoreWatchError) 
    771777            { 
    772                 SendTwitterGatewayServerMessage("�G���[: " + message); 
    773             } 
    774         } 
    775  
    776         /// <summary> 
    777         /// �T�[�o�������C�A���g�ɃG���[���v���C����܂��B 
    778         /// </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> 
    781787        public void SendErrorReply(ErrorReply errorNum, params String[] commandParams) 
    782788        { 
     
    785791 
    786792        /// <summary> 
    787         /// �T�[�o�������C�A���g�Ƀj�������b�N���v���C����܂��B 
    788         /// </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> 
    791797        public void SendNumericReply(NumericReply numReply, params String[] commandParams) 
    792798        { 
     
    821827                if (ex.Response == null || (ex.Response is HttpWebResponse) && ((HttpWebResponse)(ex.Response)).StatusCode != HttpStatusCode.NotModified) 
    822828                { 
    823                     // not-modified �ȊO 
     829                    // not-modified 以外 
    824830                    SendTwitterGatewayServerMessage(ex.Message); 
    825831                } 
     
    858864                })); 
    859865 
    860                 // �Ă��Ƃ��ɁB 
    861                 // �������� 
     866                // てきとうに。 
     867                // 増えた分 
    862868                foreach (String screenName in screenNames) 
    863869                { 
     
    870876                    } 
    871877                } 
    872                 // ������� 
     878                // 減った分 
    873879                foreach (String screenName in _nickNames) 
    874880                { 
     
    889895                if (ex.Response == null || !(ex.Response is HttpWebResponse) || ((HttpWebResponse)(ex.Response)).StatusCode != HttpStatusCode.NotModified) 
    890896                { 
    891                     // not-modified �ȊO 
     897                    // not-modified 以外 
    892898                    SendServerErrorMessage(ex.Message); 
    893899                } 
     
    911917                foreach (Status status in statuses.Status) 
    912918                { 
    913                     // �����`�F�b�N 
     919                    // 差分チェック 
    914920                    if (_server.EnableDropProtection) 
    915921                    { 
     
    920926                        if (_statusBuffer.Count > 50) 
    921927                        { 
    922                             // ���Â��̂�� 
     928                            // 一番古いのを消す 
    923929                            Status oldStatus = null; 
    924930                            foreach (Status statTmp in _statusBuffer) 
     
    933939                    } 
    934940 
    935                     // �`�F�b�N 
     941                    // チェック 
    936942                    if (status.User == null || String.IsNullOrEmpty(status.User.ScreenName)) 
    937943                    { 
     
    939945                    } 
    940946                     
    941                     // �t�B���^ 
     947                    // フィルタ 
    942948                    FilterArgs filterArgs = new FilterArgs(this, status.Text, status.User, "PRIVMSG", false); 
    943949                    if (!_filter.ExecuteFilters(filterArgs)) 
    944950                    { 
    945                         // �̂Ă�                        continue; 
     951                        // 捨てる 
     952                        continue; 
    946953                    } 
    947954 
     
    952959                    foreach (String line in lines) 
    953960                    { 
    954                         // ����ecent�낮��ۂ� 
     961                        // 初回はrecentろぐっぽく 
    955962                        if (_isFirstTime) 
    956963                        { 
     
    964971                        else if (_lastStatusFromGateway != line || String.Compare(status.User.ScreenName, _nick, true) != 0) 
    965972                        { 
    966                             // �Q�[�g�E�F�C����đ��M���ꂽ�����̃��b�Z�[�W�͏��� 
     973                            // ゲートウェイを通して送信された自分のメッセージは除く 
    967974                            IRCMessage msg; 
    968975                            switch (filterArgs.IRCMessageType.ToUpperInvariant()) 
     
    10021009                    } 
    10031010 
    1004                     // �ŏI�X�V���� 
     1011                    // 最終更新時刻 
    10051012                    if (_server.EnableDropProtection) 
    10061013                    { 
    1007                         // �����ڂ��h�~���Ă������͈��Â���                        if (status.CreatedAt < _lastAccessTimeline) 
     1014                        // 取りこぼし防止しているときは一番古い日付 
     1015                        if (status.CreatedAt < _lastAccessTimeline) 
    10081016                        { 
    10091017                            _lastAccessTimeline = status.CreatedAt; 
     
    10241032                if (ex.Response == null || !(ex.Response is HttpWebResponse) || ((HttpWebResponse)(ex.Response)).StatusCode != HttpStatusCode.NotModified) 
    10251033                { 
    1026                     // not-modified �ȊO 
     1034                    // not-modified 以外 
    10271035                    SendServerErrorMessage(ex.Message); 
    10281036                } 
     
    10461054                foreach (DirectMessage message in directMessages.DirectMessage) 
    10471055                { 
    1048                     // �`�F�b�N 
     1056                    // チェック 
    10491057                    if (message == null || String.IsNullOrEmpty(message.SenderScreenName)) 
    10501058                    { 
     
    10651073                        Send(privMsg); 
    10661074                    } 
    1067                     // �ŏI�X�V���� 
     1075                    // 最終更新時刻 
    10681076                    if (message.CreatedAt > _lastAccessDirectMessage) 
    10691077                    { 
     
    10761084                if (ex.Response == null || !(ex.Response is HttpWebResponse) || ((HttpWebResponse)(ex.Response)).StatusCode != HttpStatusCode.NotModified) 
    10771085                { 
    1078                     // not-modified �ȊO 
     1086                    // not-modified 以外 
    10791087                    SendServerErrorMessage(ex.Message); 
    10801088                } 
     
    11031111        } 
    11041112 
    1105         #region IDisposable �����o 
     1113        #region IDisposable メンバ 
    11061114        private Boolean _isDisposed = false; 
    11071115 
     
    11191127                    _timer.Dispose(); 
    11201128 
    1121                     // �ꉞ�҂� 
     1129                    // 一応待つ 
    11221130                    while (_isCallbackRunning) 
    11231131                        Thread.Sleep(100); 
  • TwitterIrcGateway/TwitterIrcGatewayCore/TwitterService.cs

    r51 r70  
    4545        { 
    4646            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            } 
    4855        } 
    4956 
     
    5663        { 
    5764            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            } 
    5973        } 
    6074 
     
    6680        public User[] GetFriends() 
    6781        { 
    68             String responseBody = null; 
    69             responseBody = GET(String.Format("http://twitter.com/statuses/friends.xml", _userName)); 
    70  
    7182            try 
    7283            { 
     84                String responseBody = GET(String.Format("http://twitter.com/statuses/friends.xml", _userName)); 
    7385                if (NilClasses.CanDeserialize(responseBody)) 
    7486                { 
     
    91103                throw new TwitterServiceException(xe); 
    92104            } 
     105            catch (IOException ie) 
     106            { 
     107                throw new TwitterServiceException(ie); 
     108            } 
    93109        } 
    94110 
     
    100116        public User GetUser(String id) 
    101117        { 
    102             String responseBody = null; 
    103             responseBody = GET(String.Format("http://twitter.com/users/show/{0}.xml", id)); 
    104  
    105118            try 
    106119            { 
     120                String responseBody = GET(String.Format("http://twitter.com/users/show/{0}.xml", id)); 
    107121                if (NilClasses.CanDeserialize(responseBody)) 
    108122                { 
     
    122136            { 
    123137                throw new TwitterServiceException(xe); 
     138            } 
     139            catch (IOException ie) 
     140            {