Skip to content
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.

Commit

Permalink
making retweet api function optional in settings (good for the swtich…
Browse files Browse the repository at this point in the history
…over). allow allowing ability to follow retweeted user (double incentive to play the game). adding options to settings.default, also cleaning up foul language (dirty boy!)
  • Loading branch information
gleuch committed Oct 3, 2009
1 parent cf7478b commit 1dd648a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
50 changes: 28 additions & 22 deletions retweet.rb
Expand Up @@ -19,15 +19,7 @@

helpers do
def twitter_connect(user={})
begin
unless user.blank?
@twitter_client = TwitterOAuth::Client.new(:consumer_key => configatron.twitter_oauth_token, :consumer_secret => configatron.twitter_oauth_secret, :token => user.oauth_token, :secret => user.oauth_secret) rescue nil
else
@twitter_client = TwitterOAuth::Client.new(:consumer_key => configatron.twitter_oauth_token, :consumer_secret => configatron.twitter_oauth_secret) rescue nil
end
rescue
@twitter_client = nil
end
@twitter_client = TwitterOAuth::Client.new(:consumer_key => configatron.twitter_oauth_token, :consumer_secret => configatron.twitter_oauth_secret, :token => (!@user.blank? ? user.oauth_token : nil), :secret => (!@user.blank? ? user.oauth_secret : nil)) rescue nil
end

def twitter_fail(msg=false)
Expand All @@ -41,18 +33,20 @@ def launch_retweet_hell
rand = "RAND()" if configatron.db_type.downcase == 'mysql' # if using MySQL
rand ||= "RANDOM()" # if using SQLite

# If you get an error with this in DM 0.10.*, run 'sudo gem install dm-ar-finders' :D
# If you get an error with this in DM 0.10.*, run 'sudo gem install dm-ar-finders'
@base_users = User.find_by_sql("SELECT id, account_id, screen_name, oauth_token, oauth_secret FROM users WHERE active=1 ORDER BY #{rand} LIMIT 10")

@base_users.each do |user|
twitter_connect(user)
unless @twitter_client.blank?
info = @twitter_client.info rescue nil

unless info.blank? || @twitter_client.info.blank? || @twitter_client.info['status']['text'].blank?
retweet = "RT: @#{info['screen_name']}: %s #{configatron.twitter_hashtag}"
retweet = retweet.gsub(/\%s/, (info['status']['text'])[0, (142-retweet.length) ])

@tweet = Tweet.create(:account_id => user.account_id, :tweet_id => info['status']['id'], :tweet => info['status']['text'], :retweet => retweet, :sent_at => Time.now)
break #end each
break
end
else
# Fucking get rid of the user if they don't validate...
Expand All @@ -68,29 +62,38 @@ def launch_retweet_hell
@users.each do |user|
twitter_connect(user)
unless @twitter_client.blank?
@twitter_client.update(@tweet.retweet)

# Use Twitter Retweet API
if configatron.use_retweet_api
@twitter_client.retweet(@tweet.tweet_id)
# Retweet through standard method.
else
@twitter_client.update(@tweet.retweet)
end

# Also auto-follow retweeted user. (idea by Patrick Ewing -- http://github.com/hoverbird)
if configatron.allow_user_follow && !@twitter_client.exists?(user.account_id, @tweet.account_id)
@twitter_client.friend(@tweet.account_id)
end

else
# Fucking get rid of the user if they don't validate...
user.destroy
end
end

haml :run
else
@error = 'Could not load a tweet for this launch.'
haml :fail
end

haml (@error.blank? ? :run : :fail)
end
end
end #helpers


# Homepage
get '/' do
get_user unless session[:user].blank?
unless @user.blank?
haml :thanks
else
haml :home
end
haml (@user.blank? ? :home : :thanks)
end


Expand All @@ -99,6 +102,7 @@ def launch_retweet_hell
@title = 'Connect to Twitter'

twitter_connect

begin
request_token = @twitter_client.request_token(:oauth_callback => "http://#{request.env['HTTP_HOST']}/auth")
session[:request_token] = request_token.token
Expand All @@ -109,6 +113,7 @@ def launch_retweet_hell
end
end


# Callback URL to return to after talking with Twitter
get '/auth' do
@title = 'Authenticate with Twitter'
Expand Down Expand Up @@ -143,8 +148,9 @@ def launch_retweet_hell
redirect '/'
end

# Launch retweet hell...
get '/run/*' do
@title = 'Launch Retweet Hell'
@title = 'Launch Retweet Hell!'

if params[:splat].to_s == configatron.secret_launch_code.to_s
launch_retweet_hell
Expand Down
20 changes: 12 additions & 8 deletions settings.yml.default
@@ -1,13 +1,17 @@
development: &local
site_name: Retweet Fucker
site_name: Retweet Game

secret_launch_code: FFFFFAT

twitter_oauth_token: ENTER-YOUR-TOKEN-HERE
twitter_oauth_secret: ENTER-YOUR-TOKEN-SECRET-HERE

twitter_sync_tweet: 'I am now using Retweet Fucker by @fffffat.'
twitter_hashtag: '#rtfuck'
twitter_sync_tweet: 'I am now using Retweet Game by @fffffat & @gleuch. http://bit.ly/rtgame'
twitter_hashtag: '#rtgame'

twitter_use_retweet_api: true
twitter_allow_user_follow: true


twitter_retweet_percent: 50
twitter_retweet_max: 10
Expand All @@ -16,15 +20,15 @@ development: &local
g_analytics_code: UA-#######-##

db_type: sqlite
db_connection: sqlite3:///ROOT/retweet.db
db_connection: sqlite3:///ROOT/rtgame_dev.db

production:
<<: *local

# db_type: mysql
# db_connection: mysql://root:*****@localhost/rtfuck_prod
# db_connection: mysql://root:*****@localhost/rtgame_prod
db_type: sqlite
db_connection: sqlite3:///ROOT/retweet.db
db_connection: sqlite3:///ROOT/rtgame_prod.db

twitter_retweet_percent: 20
twitter_retweet_max: 500
Expand All @@ -33,9 +37,9 @@ production:
staging:
<<: *local

db_connection: sqlite3:///ROOT/retweet.db
db_connection: sqlite3:///ROOT/rtgame_stage.db

test:
<<: *local

db_connection: sqlite3:///ROOT/retweet.db
db_connection: sqlite3:///ROOT/rtgame_test.db

0 comments on commit 1dd648a

Please sign in to comment.