+
+ def deauthorize(m, params)
+ if @registry.has_key?(m.sourcenick + "_request_token")
+ @registry.delete(m.sourcenick + "_request_token")
+ end
+ if @registry.has_key?(m.sourcenick + "_access_token")
+ @registry.delete(m.sourcenick + "_access_token")
+ end
+ m.reply "Done! You can reauthorize this account in the future by using 'twitter authorize'"
+ end
+
+ def authorize(m, params)
+ failed_action = "we can't complete the authorization process"
+ unless @has_oauth
+ report_oauth_missing(m, failed_action)
+ return false
+ end
+
+ #remove all old authorization data
+ if @registry.has_key?(m.sourcenick + "_request_token")
+ @registry.delete(m.sourcenick + "_request_token")
+ end
+ if @registry.has_key?(m.sourcenick + "_access_token")
+ @registry.delete(m.sourcenick + "_access_token")
+ end
+
+ key = @bot.config['twitter.key']
+ secret = @bot.config['twitter.secret']
+ if key.empty? or secret.empty?
+ report_key_missing(m, failed_action)
+ return false
+ end
+
+ @consumer = OAuth::Consumer.new(key, secret, {
+ :site => "https://api.twitter.com",
+ :request_token_path => "/oauth/request_token",
+ :access_token_path => "/oauth/access_token",
+ :authorize_path => "/oauth/authorize"
+ } )
+ begin
+ @request_token = @consumer.get_request_token
+ rescue OAuth::Unauthorized
+ m.reply _("My authorization failed! Did you block me? Or is my Twitter Consumer Key/Secret pair incorrect?")
+ return false
+ end
+ @registry[m.sourcenick + "_request_token"] = YAML::dump(@request_token)
+ m.reply "Go to this URL to get your authorization PIN, then use 'twitter pin <pin>' to finish authorization: " + @request_token.authorize_url
+ end
+
+ def pin(m, params)
+ unless @registry.has_key?(m.sourcenick + "_request_token")
+ m.reply "You must first use twitter authorize to get an authorization URL, which you can use to get a PIN for me to use to verify your Twitter account"
+ return false
+ end
+ @request_token = YAML::load(@registry[m.sourcenick + "_request_token"])
+ begin
+ @access_token = @request_token.get_access_token( { :oauth_verifier => params[:pin] } )
+ rescue
+ m.reply "Error: There was a problem registering your Twitter account. Please make sure you have the right PIN. If the problem persists, use twitter authorize again to get a new PIN"
+ return false
+ end
+ @registry[m.sourcenick + "_access_token"] = YAML::dump(@access_token)
+ m.reply "Okay, you're all set"
+ end
+