Changeset 15240
- Timestamp:
- 07/06/08 03:01:44 (5 years ago)
- Files:
-
- 1 modified
-
lang/ruby/net-irc/trunk/examples/wig.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/net-irc/trunk/examples/wig.rb
r15236 r15240 262 262 target, message = *m.params 263 263 begin 264 if target =~ /^#/ 264 if target =~ /^#(.+)/ 265 channel = Regexp.last_match[1] 265 266 if @opts.key?("alwaysim") && @im && @im.connected? # in jabber mode, using jabber post 267 message = "##{channel} #{message}" unless channel == main_channel 266 268 ret = @im.deliver(jabber_bot_id, message) 267 post "#{nick}!#{nick}@#{api_base.host}", TOPIC, main_channel, untinyurl(message)269 post "#{nick}!#{nick}@#{api_base.host}", TOPIC, channel, untinyurl(message) 268 270 else 269 ret = api("statuses/update", {"status" => message}) 271 if channel == main_channel 272 ret = api("statuses/update", {"status" => message}) 273 else 274 ret = api("channel_message/update", {"name_en" => channel, "body" => message}) 275 end 270 276 end 271 277 else … … 336 342 post nil, ERR_NOSUCHNICK, nick, "No such nick/channel" 337 343 end 344 end 345 346 def on_join(m) 347 # TODO 348 channels = m.params[0].split(/\s*,\s*/) 349 channels.each do |channel| 350 next if channel == main_channel 351 post "#{@nick}!#{@nick}@#{api_base.host}", JOIN, channel 352 end 353 end 354 355 def on_part(m) 356 # TODO 357 channel = m.params[0] 358 return if channel == main_channel 359 post "#{@nick}!#{@nick}@#{api_base.host}", PART, channel 338 360 end 339 361 … … 509 531 nick, id = Regexp.last_match.captures 510 532 body = CGI.unescapeHTML(body) 511 message(id || nick, main_channel, body) 533 534 # channel message or not 535 if body =~ /^#([a-z_]+)\s+(.+)$/i 536 message(id || nick, Regexp.last_match[1], Regexp.last_match[2]) 537 else 538 message(id || nick, main_channel, body) 539 end 512 540 end 513 541 end … … 524 552 end 525 553 554 def require_post?(path) 555 %w|statuses/update direct_messages/new channel_message/update|.include?(path) 556 end 557 526 558 def api(path, q={}) 527 ret = {} 528 headers = { 529 "User-Agent" => @user_agent, 530 "Authorization" => "Basic " + ["#{@real}:#{@pass}"].pack("m"), 531 } 532 headers["If-Modified-Since"] = q["since"] if q.key?("since") 533 559 ret = {} 534 560 q["source"] ||= api_source 535 q = q.inject([]) {|r,(k,v)| v.inject(r) {|r,i| r << "#{k}=#{URI.escape(i, /[^-.!~*'()\w]/n)}" } }.join("&")536 561 537 562 uri = api_base.dup 538 uri.path = path.sub(%r{^/*}, "/") << ".json" 539 uri.query = q 563 uri.path = "/#{path}.json" 564 uri.query = q.inject([]) {|r,(k,v)| v.inject(r) {|r,i| r << "#{k}=#{URI.escape(i, /[^-.!~*'()\w]/n)}" } }.join("&") 565 566 567 req = nil 568 if require_post?(path) 569 req = Net::HTTP::Post.new(uri.path) 570 req.body = uri.query 571 else 572 req = Net::HTTP::Get.new(uri.request_uri) 573 end 574 req.basic_auth(@real, @pass) 575 req["User-Agent"] = @user_agent 576 req["If-Modified-Since"] = q["since"] if q.key?("since") 540 577 541 578 @log.debug uri.inspect 542 Net::HTTP.start(uri.host, uri.port) do |http| 543 case uri.path 544 when "/statuses/update.json", "/direct_messages/new.json" 545 ret = http.post(uri.request_uri, q, headers) 546 else 547 ret = http.get(uri.request_uri, headers) 548 end 549 end 579 ret = Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) } 550 580 551 581 case ret
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)