Show
Ignore:
Timestamp:
04/15/08 09:54:42 (5 years ago)
Author:
walf443
Message:

lang/ruby/net-irc: tig.rbで!list nickとprimsgを送ったときにuser_timelineを取得してnoticeで表示させるようにしてみた

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/net-irc/trunk/examples/tig.rb

    r9295 r9462  
    196196                begin 
    197197                        if target =~ /^#/ 
    198                                 ret = api("statuses/update", {"status" => message}) 
     198                                # XXX: !list nick でユーザーの発言を表示させてみる試み 
     199                                if message =~ /^!list ([A-Za-z0-9_]+)$/ 
     200                                        nick = $1 
     201                                        @log.debug([ nick, message ]) 
     202                                        res = api('statuses/user_timeline', { 'id' => nick }).reverse_each do |s| 
     203                                                @log.debug(s) 
     204                                                mesg = "#{generate_status_message(s)}" 
     205                                                post(nick, NOTICE, main_channel, mesg) 
     206                                        end 
     207           
     208                                        unless res 
     209                                                post nil, ERR_NOSUCHNICK, nick, "No such nick/channel"  
     210                                        end 
     211                                        ret = true 
     212                                else 
     213                                        ret = api("statuses/update", {"status" => message}) 
     214                                end 
    199215                        else 
    200216                                # direct message 
     
    312328                        @timeline << id 
    313329                        nick = s["user_login_id"] || s["user"]["screen_name"] # it may be better to use user_login_id in Wassr 
    314                         mesg = s["text"] 
    315  
    316                         # added @user in no use @user reply message ( Wassr only ) 
    317                         if s.has_key?('reply_status_url') and s['reply_status_url'] and s['text'] !~ /^@.*/ and %r{([^/]+)/statuses/[^/]+}.match(s['reply_status_url']) 
    318                                 reply_user_id = $1 
    319                                 mesg = "@#{reply_user_id} #{mesg}" 
    320                         end 
    321                         # display area name(Wassr only) 
    322                         if s.has_key?('areaname') and s["areaname"] 
    323                                 mesg += " L: #{s['areaname']}" 
    324                         end 
    325                         # display photo url(Wassr only) 
    326                         if s.has_key?('photo_url') and s["photo_url"] 
    327                                 mesg += " #{s['photo_url']}" 
    328                         end 
    329  
    330                         # time = Time.parse(s["created_at"]) rescue Time.now 
    331                         m = { "&quot;" => "\"", "&lt;"=> "<", "&gt;"=> ">", "&amp;"=> "&", "\n" => " "} 
    332                         mesg.gsub!(/(#{m.keys.join("|")})/) { m[$1] } 
     330                        mesg = generate_status_message(s) 
    333331 
    334332                        @log.debug [id, nick, mesg] 
     
    347345                @timeline  = @timeline.last(100) 
    348346                @prev_time = Time.now 
     347        end 
     348 
     349        def generate_status_message(status) 
     350                        s = status 
     351                        mesg = s["text"] 
     352      @log.debug(mesg) 
     353 
     354                        # added @user in no use @user reply message ( Wassr only ) 
     355                        if s.has_key?('reply_status_url') and s['reply_status_url'] and s['text'] !~ /^@.*/ and %r{([^/]+)/statuses/[^/]+}.match(s['reply_status_url']) 
     356                                reply_user_id = $1 
     357                                mesg = "@#{reply_user_id} #{mesg}" 
     358                        end 
     359                        # display area name(Wassr only) 
     360                        if s.has_key?('areaname') and s["areaname"] 
     361                                mesg += " L: #{s['areaname']}" 
     362                        end 
     363                        # display photo url(Wassr only) 
     364                        if s.has_key?('photo_url') and s["photo_url"] 
     365                                mesg += " #{s['photo_url']}" 
     366                        end 
     367 
     368                        # time = Time.parse(s["created_at"]) rescue Time.now 
     369                        m = { "&quot;" => "\"", "&lt;"=> "<", "&gt;"=> ">", "&amp;"=> "&", "\n" => " "} 
     370                        mesg.gsub!(/(#{m.keys.join("|")})/) { m[$1] } 
     371                        mesg 
    349372        end 
    350373