diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2010-09-14 23:46:13 +0200 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2010-09-15 00:04:21 +0200 |
commit | 9ed8ad84aa87a414319ffea22b4ffc3cee5e53bf (patch) | |
tree | 4a7b586577c73dcf5f0ce6e70a8e15a309238368 /data/rbot/plugins/twitter.rb | |
parent | 915b8ecffc4b19877f36ddb36fa85f3a4cd53286 (diff) |
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.
Diffstat (limited to 'data/rbot/plugins/twitter.rb')
-rw-r--r-- | data/rbot/plugins/twitter.rb | 12 |
1 files changed, 11 insertions, 1 deletions
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", |