- Timestamp:
- 05/20/09 14:15:35 (4 years ago)
- Location:
- lang/ruby/net-irc/trunk
- Files:
-
- 2 modified
-
examples/tig.rb (modified) (14 diffs)
-
lib/net/irc/server.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/net-irc/trunk/examples/tig.rb
r33421 r33440 171 171 require "rubygems" 172 172 require "net/irc" 173 require "net/http s"173 require "net/http" 174 174 require "uri" 175 175 require "socket" … … 178 178 require "yaml" 179 179 require "pathname" 180 require "cgi"181 180 require "json" 182 181 … … 240 239 @real, *@opts = (@opts.name || @real).split(/\s+/) 241 240 @opts = @opts.inject({}) do |r, i| 242 key, value = i.split("=" )241 key, value = i.split("=", 2) 243 242 key = "mentions" if key == "replies" # backcompat 244 243 r.update key => case value … … 295 294 @ratio = (@opts["ratio"] || "77:1").split(":") 296 295 @ratio = Struct.new(:timeline, :friends, :mentions).new(*@ratio) 297 @ratio [:mentions]||= @opts["mentions"] == true ? 12 : @opts["mentions"]296 @ratio.mentions ||= @opts["mentions"] == true ? 12 : @opts["mentions"] 298 297 299 298 @check_friends_thread = Thread.start do … … 309 308 end 310 309 end 311 sleep interval(@ratio [:friends])310 sleep interval(@ratio.friends) 312 311 end 313 312 end … … 333 332 end 334 333 end 335 sleep interval(@ratio [:timeline])334 sleep interval(@ratio.timeline) 336 335 end 337 336 end … … 340 339 341 340 @check_mentions_thread = Thread.start do 342 sleep interval(@ratio [:timeline]) / 2341 sleep interval(@ratio.timeline) / 2 343 342 344 343 loop do … … 353 352 end 354 353 end 355 sleep interval(@ratio [:mentions])354 sleep interval(@ratio.mentions) 356 355 end 357 356 end … … 529 528 return 530 529 end 531 @ratio [:timeline]= ratios[0]532 @ratio [:friends]= ratios[1]533 @ratio [:mentions]= ratios[2] if @opts["mentions"]530 @ratio.timeline = ratios[0] 531 @ratio.friends = ratios[1] 532 @ratio.mentions = ratios[2] if @opts["mentions"] 534 533 end 535 534 log "Intervals: " << @ratio.map {|ratio| interval(ratio).round }.join(", ") … … 890 889 first = @friends.nil? 891 890 athack = @opts["athack"] 892 friends = api("statuses/friends") 891 friends = [] 892 893 1.upto(1) do |page| 894 friends += api("statuses/friends", { :page => page }) 895 c ||= friends.size 896 break if c * page >= @me["friends_count"] 897 #sleep 0.5 898 end 899 893 900 if first and not athack 894 names_list = friends.map do |i|901 rest = friends.map do |i| 895 902 name = i["screen_name"] 896 #prefix = @drones.include?(i["id"]) ? "%" : "+" # FIXME 903 #prefix = @drones.include?(i["id"]) ? "%" : "+" # FIXME ~&% 897 904 prefix = "+" 898 905 "#{prefix}#{name}" 899 end 900 names_list = names_list.push("@#{@nick}").reverse.join(" ") 901 post server_name, RPL_NAMREPLY, @nick, "=", main_channel, names_list 906 end.reverse.inject("@#{@nick}") do |r, nick| 907 if r.size < 400 908 r << " " << nick 909 else 910 post server_name, RPL_NAMREPLY, @nick, "=", main_channel, r 911 nick 912 end 913 end 914 post server_name, RPL_NAMREPLY, @nick, "=", main_channel, rest 902 915 post server_name, RPL_ENDOFNAMES, @nick, main_channel, "End of NAMES list" 903 916 else … … 944 957 loop do 945 958 begin 959 require "cgi" 946 960 @im.received_messages.each do |msg| 947 961 @log.debug [msg.from, msg.body] … … 1016 1030 @log.debug uri.inspect 1017 1031 1032 require "net/https" if @opts["secure"] 1033 1018 1034 http = case 1019 1035 when RE_HTTPPROXY === @opts["httpproxy"] … … 1123 1139 1124 1140 def fetch_location_header(uri, limit = 3) 1125 return uri if limit == 0 or uri.nil? 1141 return uri if limit == 0 or uri.nil? or uri.is_a? URI::HTTPS 1126 1142 req = Net::HTTP::Head.new uri.request_uri 1127 1143 req.add_field "User-Agent", user_agent … … 1189 1205 def http_get(uri) 1190 1206 accepts = ["*/*;q=0.1"] 1191 #require 'mime/types'; accepts.unshift MIME::Types.of(uri.path).first.simplified1207 #require "mime/types"; accepts.unshift MIME::Types.of(uri.path).first.simplified 1192 1208 types = { "json" => "application/json", "txt" => "text/plain" } 1193 1209 ext = uri.path[/[^.]+\z/] -
lang/ruby/net-irc/trunk/lib/net/irc/server.rb
r33401 r33440 80 80 def initialize(server, socket, logger, opts={}) 81 81 @server, @socket, @log, @opts = server, socket, logger, opts 82 @prefix = nil83 82 end 84 83 … … 128 127 def on_nick(m) 129 128 @nick = m.params[0] 130 @prefix &&= Prefix.new("#{@nick}!#{@user}@#{@host}")129 @prefix = Prefix.new("#{@nick}!#{@user}@#{@host}") if defined? @prefix 131 130 end 132 131
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)