Created
June 26, 2010 02:39
-
-
Save hitode909/453709 to your computer and use it in GitHub Desktop.
termtterで必ず140文字投稿する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Termtter::Client | |
register_hook( | |
:name => :always_140, | |
:points => [:modify_arg_for_update], | |
:exec_proc => lambda {|cmd, body| | |
body.chomp! | |
max = 140 | |
len = body.split(//).length | |
mod = max % len | |
ext = (0...len).to_a.sort_by{ rand }.take(mod) | |
return body.split(//).each_with_index.map{ |c, i| c * (max / len + (ext.include?(i) ? 1 : 0)) }.join('') | |
}) | |
register_command( | |
:name => :always_140, | |
:exec => lambda {|arg| | |
Termtter::API.twitter.safe.user_timeline(config.user_name).each{ |status| | |
Termtter::Client.logger.debug("#{status.text.split(//).length}: #{status.text}") | |
next if status.text.split(//).length > 130 | |
begin | |
Termtter::API.twitter.remove_status(status.id) | |
Termtter::Client.execute("update #{status.text}") | |
rescue => e | |
p e | |
end | |
} | |
}) | |
add_task( | |
:name => :auto_reload, | |
:interval => 120, | |
:after => 10) { | |
Termtter::Client.execute("always_140") | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment