Changeset 32900
- Timestamp:
- 04/28/09 18:41:08 (4 years ago)
- Files:
-
- 1 modified
-
lang/ruby/net-irc/trunk/examples/tig.rb (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/net-irc/trunk/examples/tig.rb
r32898 r32900 103 103 ### list (ls) 104 104 105 /me list NICK _or_screen_name105 /me list NICK [NUMBER] 106 106 107 107 ### fav (favorite, favourite, unfav, unfavorite, unfavourite) 108 108 109 /me fav ID[ID...]110 /me unfav ID[ID...]109 /me fav [ID...] 110 /me unfav [ID...] 111 111 112 112 ### link (ln) … … 116 116 ### destroy (del, delete, miss, oops, remove, rm) 117 117 118 /me destroy ID[ID...]118 /me destroy [ID...] 119 119 120 120 ### in (location) … … 217 217 super 218 218 @real, *@opts = (@opts.name || @real).split(/\s+/) 219 @opts = @opts.inject({}) {|r,i|219 @opts = @opts.inject({}) do |r,i| 220 220 key, value = i.split("=") 221 221 key = "mentions" if key == "replies" # backcompat 222 222 r.update(key => value || true) 223 }223 end 224 224 225 225 @me = api("account/verify_credentials") … … 368 368 src = @sources[rand(@sources.size)].first 369 369 ret = api("statuses/update", { :status => mesg, :source => src }) 370 if ret["truncated"] 371 log "Oops! Your update was over 140 characters. We sent the short version" << 372 " to your friends (they can view the entire update on the Web <" << 373 permalink(ret) << ">)." 374 end 370 375 ret.delete("user") 371 376 @me.update("status" => ret) … … 392 397 _, command, *args = mesg.split(/\s+/) 393 398 case command 394 when "call" # /me call <twitter-id> as <nickname> 399 when "call" 400 return log("/me call <Twitter_screen_name> as <IRC_nickname>") if args.size < 2 395 401 screen_name = args[0] 396 402 nickname = args[2] || args[1] # allow omitting 'as' 397 403 if nickname == "is" 398 404 @nicknames.delete(screen_name) 399 log "Removed nickname for #{screen_name}"405 log "Removed the nickname for #{screen_name}" 400 406 else 401 407 @nicknames[screen_name] = nickname … … 411 417 end 412 418 when "list", "ls" 419 return log("/me list <NICK> [<NUM>]") if args.empty? 413 420 nick = args.first 414 421 unless (1..200).include?(count = args[1].to_i) … … 420 427 @log.debug s 421 428 time = Time.parse(s["created_at"]) rescue Time.now 422 post to, NOTICE, main_channel, "#{time.strftime "%m-%d %H:%M"} #{generate_status_message(s)}" 429 post to, NOTICE, main_channel, 430 "#{time.strftime "%m-%d %H:%M"} #{generate_status_message(s)}" 423 431 end 424 432 unless res … … 426 434 end 427 435 when /^(un)?fav(?:ou?rite)?$/ 428 method, prefix = $1.nil? ? ["create", "F"] : ["destroy", "Unf"] 429 args.each_with_index do |tid, i| 430 if st = @tmap[tid] 431 sleep 1 if i > 0 432 res = api("favorites/#{method}/#{st["id"]}") 433 log "#{prefix}av: #{res["user"]["screen_name"]}: #{res["text"]}" 436 # fav, favorite, favourite, unfav, unfavorite, unfavourite 437 method = $1.nil? ? "create" : "destroy" 438 entered = $&.capitalize 439 statuses = [] 440 if args.empty? 441 if method == "create" 442 id = @timeline.last 443 @tmap.each_value do |v| 444 if v["id"] == id 445 statuses.push v 446 break 447 end 448 end 434 449 else 435 log "No such ID #{tid}" 436 end 450 @favorites ||= api("favorites").reverse 451 return log("You've never favorite yet. No favorites to unfavorite.") if @favorites.empty? 452 statuses.push @favorites.last 453 end 454 else 455 args.each do |tid| 456 if status = @tmap[tid] 457 statuses.push status 458 else 459 log "No such ID #{colored_tid(tid)}" 460 end 461 end 462 end 463 @favorites ||= [] 464 statuses.each do |status| 465 res = api("favorites/#{method}/#{status["id"]}") 466 log "#{entered}: #{res["user"]["screen_name"]}: #{res["text"]}" 467 if method == "create" 468 @favorites.push res 469 else 470 @favorites.delete_if {|i| i["id"] == res["id"] } 471 end 472 sleep 1 437 473 end 438 474 when "link", "ln" 439 475 args.each do |tid| 440 if st =@tmap[tid]441 log "#{ api_base + st["user"]["screen_name"]}/statuses/#{st["id"]}"476 if @tmap[tid] 477 log "#{colored_tid(tid)}: #{permalink(@tmap[tid])}" 442 478 else 443 log "No such ID #{ tid}"479 log "No such ID #{colored_tid(tid)}" 444 480 end 445 481 end … … 462 498 # intervals = @ratio.map {|ratio| interval ratio } 463 499 # log "Intervals: #{intervals.join(", ")}" 464 when /^(?:de(?:stroy|l(?:ete)?)|miss|oops|r(?:emove|m))$/ # destroy, delete, del, remove, rm, miss, oops 465 args.each_with_index do |tid, i| 466 if st = @tmap[tid] 467 sleep 1 if i > 0 468 res = api("statuses/destroy/#{st["id"]}") 469 log "Destroyed: #{res["text"]}" 470 else 471 log "No such ID #{tid}" 472 end 473 end 500 when /^(?:de(?:stroy|l(?:ete)?)|miss|oops|r(?:emove|m))$/ 501 # destroy, delete, del, remove, rm, miss, oops 502 statuses = [] 503 if args.empty? 504 statuses.push @me["status"] 505 else 506 args.each do |tid| 507 if status = @tmap[tid] 508 if status["user"]["screen_name"] == @nick 509 statuses.push status 510 else 511 log "The status you specified by the ID #{colored_tid(tid)} is not yours." 512 end 513 else 514 log "No such ID #{colored_tid(tid)}" 515 end 516 end 517 end 518 b = false 519 statuses.each do |status| 520 res = api("statuses/destroy/#{status["id"]}") 521 @tmap.delete_if {|k, v| v["id"] == res["id"] } 522 b = status["id"] == @me["status"]["id"] 523 log "Destroyed: #{res["text"]}" 524 sleep 1 525 end 526 @me = api("account/verify_credentials") if b 474 527 when "name" 475 528 name = mesg.split(/\s+/, 3)[2] … … 510 563 when /^(?:mention|re(?:ply)?)$/ # reply, re, mention 511 564 tid = args.first 512 if st = @tmap[tid]565 if status = @tmap[tid] 513 566 text = mesg.split(/\s+/, 4)[3] 514 567 src = @sources[rand(@sources.size)].first 515 ret = api("statuses/update", { :status => text, :source => src, :in_reply_to_status_id => "#{st["id"]}" }) 516 if ret 517 msg = generate_status_message(st) 518 log "Status updated (In reply to \x03#{@opts["tid"] || 10}[#{tid}]\x0f: #{msg} <#{api_base + st["user"]["screen_name"]}/statuses/#{st["id"]}>)" 519 ret.delete("user") 520 @me.update("status" => ret) 521 end 568 ret = api("statuses/update", { :status => text, :source => src, 569 :in_reply_to_status_id => "#{status["id"]}" }) 570 if ret["truncated"] 571 log "Oops! Your update was over 140 characters. We sent the short version" << 572 " to your friends (they can view the entire update on the Web <" << 573 permalink(ret) << ">)." 574 end 575 msg = generate_status_message(status) 576 url = permalink(status) 577 log "Status updated (In reply to #{colored_tid(tid)}: #{msg} <#{url}>)" 578 ret.delete("user") 579 @me.update("status" => ret) 522 580 end 523 581 when /^spoo(o+)?f$/ … … 649 707 650 708 if @opts["tid"] 651 mesg = "%s \x03%s[%s]" % [mesg, @opts["tid"] || 10, tid]709 mesg << " " << colored_tid(tid) 652 710 end 653 711 … … 697 755 next if created_at < time 698 756 757 @timeline << id 699 758 user = mention["user"] 700 759 mesg = generate_status_message(mention) … … 702 761 703 762 if @opts["tid"] 704 mesg = "%s \x03%s[%s]" % [mesg, @opts["tid"] || 10, tid]763 mesg << " " << colored_tid(tid) 705 764 end 706 765 … … 908 967 ) 909 968 /~?[0-9a-z=-]+ 910 }ix) {|m|969 }ix) do |m| 911 970 uri = URI(m) 912 971 uri.host = uri.host.sub($1, "") if $1 913 Net::HTTP.start(uri.host, uri.port) {|http|972 Net::HTTP.start(uri.host, uri.port) do |http| 914 973 http.open_timeout = 3 915 974 begin … … 918 977 m 919 978 end 920 }921 }979 end 980 end 922 981 end 923 982 … … 948 1007 end 949 1008 950 def fetch_suffix_bl 1009 def fetch_suffix_bl(r = []) 951 1010 source = Net::HTTP.get("svn.coderepos.org", "/share/platform/twitterircgateway/suffixesblacklist.txt") 952 1011 if source.respond_to?(:encoding) and source.encoding == Encoding::BINARY … … 955 1014 source.split 956 1015 rescue 957 []1016 r 958 1017 end 959 1018 960 1019 def hostname(user) 961 1020 user["protected"] ? "protected.#{api_base.host}" : api_base.host 1021 end 1022 1023 def colored_tid(tid) 1024 "\x03%s[%s]\x0f" % [@opts["tid"] || 10, tid] 1025 end 1026 1027 def permalink(status) 1028 "#{api_base}#{status["user"]["screen_name"]}/statuses/#{status["id"]}" 962 1029 end 963 1030 … … 965 1032 Roman = %w[ 966 1033 k g ky gy s z sh j t d ch n ny h b p hy by py m my y r ry w v q 967 ].unshift("").map {|consonant|1034 ].unshift("").map do |consonant| 968 1035 case consonant 969 1036 when "y", /^.{2}/ then %w|a u o| … … 971 1038 else %w|a i u e o| 972 1039 end.map {|vowel| "#{consonant}#{vowel}" } 973 }.flatten1040 end.flatten 974 1041 975 1042 def initialize(size = 1) … … 992 1059 self[id] = obj 993 1060 @n += 1 994 @n = @n % (@seq.size ** @size)1061 @n %= @seq.size ** @size 995 1062 id 996 1063 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)