From 9ed8ad84aa87a414319ffea22b4ffc3cee5e53bf Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Tue, 14 Sep 2010 23:46:13 +0200 Subject: twitter: report missing key/secret configuration Instead of failing (silently) when the OAuth process cannot complete due to a missing key/secret pair, report the issue to the user. --- data/rbot/plugins/twitter.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'data') diff --git a/data/rbot/plugins/twitter.rb b/data/rbot/plugins/twitter.rb index 045b6172..1c8f61dd 100644 --- a/data/rbot/plugins/twitter.rb +++ b/data/rbot/plugins/twitter.rb @@ -58,6 +58,10 @@ class TwitterPlugin < Plugin m.reply [failed_action, "I cannot authenticate to Twitter (OAuth not available)"].join(' because ') end + def report_key_missing(m, failed_action) + m.reply [failed_action, "no Twitter Consumer Key/Secret is defined"].join(' because ') + end + def help(plugin, topic="") return "twitter status [nick] => show nick's (or your) status, use 'twitter friends status [nick]' to also show the friends' timeline | twitter update [status] => updates your status on twitter | twitter authorize => Generates an authorization URL which will give you a PIN to authorize the bot to use your twitter account. | twitter pin [pin] => Finishes bot authorization using the PIN provided by the URL from twitter authorize. | twitter deauthorize => Makes the bot forget your Twitter account. | twitter actions [on|off] => enable/disable twitting of actions (/me does ...)" end @@ -167,8 +171,9 @@ class TwitterPlugin < Plugin end def authorize(m, params) + failed_action = "we can't complete the authorization process" unless @has_oauth - report_oauth_missing(m, "we can't complete the authorization process") + report_oauth_missing(m, failed_action) return false end @@ -182,6 +187,11 @@ class TwitterPlugin < Plugin 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", -- cgit v1.2.3