From 08e5a6c85f2b3abf5d6d36d6d4069c8bb3b5484d Mon Sep 17 00:00:00 2001 From: yago Date: Tue, 6 Jan 2015 14:10:26 +0100 Subject: [PATCH] Checks if Twitter keys are empty --- bot/utils.lua | 5 +++++ plugins/twitter.lua | 23 ++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/bot/utils.lua b/bot/utils.lua index bce3c4a..506727b 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -180,4 +180,9 @@ function serialize_to_file(data, file) }) file:write(serialized) file:close() +end + +-- Retruns true if the string is empty +function string:isempty() + return self == nil or self == '' end \ No newline at end of file diff --git a/plugins/twitter.lua b/plugins/twitter.lua index 312e746..725873a 100644 --- a/plugins/twitter.lua +++ b/plugins/twitter.lua @@ -16,16 +16,23 @@ local client = OAuth.new(consumer_key, consumer_secret, { function run(msg, matches) + if consumer_key:isempty() then + return "Twitter Consumer Key is empty, write it in plugins/twitter.lua" + end + if consumer_secret:isempty() then + return "Twitter Consumer Secret is empty, write it in plugins/twitter.lua" + end + if access_token:isempty() then + return "Twitter Access Token is empty, write it in plugins/twitter.lua" + end + if access_token_secret:isempty() then + return "Twitter Access Token Secret is empty, write it in plugins/twitter.lua" + end + local twitter_url = "https://api.twitter.com/1.1/statuses/show/" .. matches[1] .. ".json" - - print(twitter_url) - local response_code, response_headers, response_status_line, response_body = client:PerformRequest("GET", twitter_url) - print(response_body) local response = json:decode(response_body) - print("response = ", response) - local header = "Tweet from " .. response.user.name .. " (@" .. response.user.screen_name .. ")\n" local text = response.text @@ -65,6 +72,4 @@ return { usage = "", patterns = {"https://twitter.com/[^/]+/status/([0-9]+)"}, run = run -} - - +} \ No newline at end of file