Skip to content

Commit

Permalink
in_reply_to_status_id を自動で付ける機能を reply コマンドの方に実装。update コマンドは前の仕様に戻した。
Browse files Browse the repository at this point in the history
  • Loading branch information
jugyo committed Apr 10, 2009
1 parent 4cace89 commit 3af7d61
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/plugins/standard_plugins.rb
Expand Up @@ -12,11 +12,9 @@ module Termtter::Client
register_command(
:name => :update, :aliases => [:u],
:exec_proc => lambda {|arg|
unless /^\s*$/ =~ arg
# TODO: Change to able to disable erb.
unless arg.empty?
text = ERB.new(arg).result(binding).gsub(/\n/, ' ')
reply_to_status_id = public_storage[:last_status_id][$1] if /^@([A-Za-z0-9_]+)/ =~ text
result = Termtter::API.twitter.update(text, {'in_reply_to_status_id' => reply_to_status_id})
result = Termtter::API.twitter.update(text)
puts "=> #{text}"
result
end
Expand Down Expand Up @@ -405,12 +403,11 @@ def self.formatted_help(helps)
id, text = $1, $2
user = public_storage[:log].select {|l| l.id == id.to_i }.first.user
update_with_user_and_id(text, user.screen_name, id) if user
when /^\s*@(\w+)\s+(.+)$/
username, text = $1, $2
id = public_storage[:log].
select {|l| l.user.screen_name = username}.
sort {|a,b| b.id <=> a.id}.first.id
update_with_user_and_id(text, username, id) if id
when /^\s*@(\w+)/
in_reply_to_status_id = Termtter::API.twitter.user($1).status.id rescue nil
params = in_reply_to_status_id ? {:in_reply_to_status_id => in_reply_to_status_id} : {}
Termtter::API.twitter.update(arg, params)
puts "=> #{arg}"
end
},
:completion_proc => lambda {|cmd, args|
Expand Down

1 comment on commit 3af7d61

@Yasushi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最初は確実なのでこの方法を考えたのですが、これだとreply1回でAPIコール2回になるかなと思ったので、last_status_idをキャッシュするようにしてました。

Please sign in to comment.