summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwjoe <joe@lc8n.com>2012-02-07 14:08:33 +0000
committerwjoe <joe@lc8n.com>2012-02-07 14:08:33 +0000
commit8aec40442a5543a6ef1f17db6bf8f50d9e381102 (patch)
treeb61f518392e57787aeb5add70cbc1b296ddb9ad5
parent48db66311f1f67edd112cb8d906959bc0a5f9ab9 (diff)
Historic commit 2.1.0 - Changed help/options display and added length of
tweet if over limit (07-Feb-2012 13:52)
-rw-r--r--blatweet.rb22
1 files changed, 15 insertions, 7 deletions
diff --git a/blatweet.rb b/blatweet.rb
index 75b6faa..4cba2a7 100644
--- a/blatweet.rb
+++ b/blatweet.rb
@@ -11,8 +11,9 @@ number_of_tweets = 1
message = nil
limit = false
debug = false
-version = 'v2.0.7'
+version = 'v2.1.0'
help = false
+options = false
irc_nick = nil
ops = nil
@@ -29,7 +30,8 @@ options = OptionParser.new do |opts|
opts.on( '-l', '--limit', 'Display remaining hits' ) { limit = true }
opts.on( '-d', '--debug', 'Display debug info.' ) { debug = true }
opts.on( "-v", "--version", "blatweet version number." ) { puts version; exit }
- opts.on( '-h', '--help', 'Display this screen.' ) { help = true; ops = opts }
+ opts.on( '-h', '--help', 'Display use examples' ) { help = true }
+ opts.on( '-o', '--options', 'Display this screen.' ) { options = true; ops = opts }
opts.on( '-a', '--auth NICK', 'IRC nick to auth. Set by BB.' ) { |n| irc_nick = n }
end;options.parse!
@@ -39,6 +41,12 @@ if args == []
exit(-1)
end
+def post_message account, message
+ puts "Your message is #{message.length} characters." if message.length > 140
+ response = oauth_client(account, config).update message
+ puts response['error'] ? response['error'] : "Posted tweet."
+end
+
def oauth_client irc_nick, config
shoes = get_shoes irc_nick, config
TwitterOAuth::Client.new(:consumer_key => config['consumer_key'], :consumer_secret => config['consumer_secret'], :token => shoes['token'], :secret => shoes['secret'])
@@ -92,23 +100,23 @@ begin
config = YAML::load( File.open( 'config.yaml' ) )
client = TwitterOAuth::Client.new
- if help
+ if options
ops.to_s.split(/\n\s*|\s{2,}/).each{|opt| output << opt}
puts output.join(' ')
+ elsif help
+ puts '!tweet MESSAGE (post to intensemarcus), !tweet -u USERNAME -n NUMBER (show the last -n tweets from -u), !tweet -p MESSAGE (post to your account), !tweet -l (remaining api hits), !tweet -v (blatweet verion), !tweet -h (this message), !tweet -o (full options), !tweet -d (debug info).'
elsif limit
rate_limit_status = oauth_client(irc_nick, config).rate_limit_status
remaining_hits = rate_limit_status['remaining_hits']
reset_time = DateTime.parse rate_limit_status['reset_time']
puts remaining_hits == 0 ? "Limit reached. Limit resets in #{(60 + reset_time.min) - Time.now.min} minutes." : "Remaining hits this hour: #{remaining_hits}. #{remaining_hits/((60 + reset_time.min) - Time.now.min)} hits/minute."
elsif message
- response = oauth_client(irc_nick, config).update message
- puts response['error'] ? response['error'] : "Posted tweet from #{irc_nick}."
+ post_message irc_nick, message
elsif username
client.search("from:#{username}", :rpp => number_of_tweets)['results'].each_with_index{|tweet, index| output << "#{index+1}: #{tweet['text']}"}
puts output.join ' '
else
- response = oauth_client('intensemarcus', config).update ARGV.join(' ')
- puts response['error'] ? response['error'] : "Posted tweet to intensemarcus from #{irc_nick}."
+ post_message 'intense_marcus', ARGV.join(' ')
end
rescue StandardError => e