2014-11-05 13:22:07 +01:00
|
|
|
local OAuth = require "OAuth"
|
|
|
|
|
2014-12-31 17:14:48 +01:00
|
|
|
local consumer_key = ""
|
|
|
|
local consumer_secret = ""
|
|
|
|
local access_token = ""
|
|
|
|
local access_token_secret = ""
|
2014-11-05 13:22:07 +01:00
|
|
|
|
|
|
|
local client = OAuth.new(consumer_key, consumer_secret, {
|
|
|
|
RequestToken = "https://api.twitter.com/oauth/request_token",
|
|
|
|
AuthorizeUser = {"https://api.twitter.com/oauth/authorize", method = "GET"},
|
|
|
|
AccessToken = "https://api.twitter.com/oauth/access_token"
|
|
|
|
}, {
|
|
|
|
OAuthToken = access_token,
|
|
|
|
OAuthTokenSecret = access_token_secret
|
|
|
|
})
|
|
|
|
|
|
|
|
function run(msg, matches)
|
|
|
|
|
2015-01-06 14:10:26 +01:00
|
|
|
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
|
2014-11-05 13:22:07 +01:00
|
|
|
|
2015-01-06 14:10:26 +01:00
|
|
|
local twitter_url = "https://api.twitter.com/1.1/statuses/show/" .. matches[1] .. ".json"
|
2014-11-05 13:22:07 +01:00
|
|
|
local response_code, response_headers, response_status_line, response_body = client:PerformRequest("GET", twitter_url)
|
|
|
|
local response = json:decode(response_body)
|
|
|
|
|
|
|
|
local header = "Tweet from " .. response.user.name .. " (@" .. response.user.screen_name .. ")\n"
|
|
|
|
local text = response.text
|
|
|
|
|
|
|
|
-- replace short URLs
|
|
|
|
if response.entities.url then
|
|
|
|
for k, v in pairs(response.entities.urls) do
|
|
|
|
local short = v.url
|
|
|
|
local long = v.expanded_url
|
|
|
|
text = text:gsub(short, long)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- remove images
|
|
|
|
local images = {}
|
2015-02-13 01:55:16 +01:00
|
|
|
if response.extended_entities.media then
|
|
|
|
for k, v in pairs(response.extended_entities.media) do
|
2014-11-05 13:22:07 +01:00
|
|
|
local url = v.url
|
|
|
|
local pic = v.media_url
|
|
|
|
text = text:gsub(url, "")
|
|
|
|
table.insert(images, pic)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- send the parts
|
|
|
|
local receiver = get_receiver(msg)
|
|
|
|
send_msg(receiver, header .. "\n" .. text, ok_cb, false)
|
2015-02-15 14:06:01 +01:00
|
|
|
send_photos_from_url(receiver, images)
|
2014-11-05 13:22:07 +01:00
|
|
|
return nil
|
|
|
|
end
|
2015-02-15 14:06:01 +01:00
|
|
|
|
2014-11-05 13:22:07 +01:00
|
|
|
|
|
|
|
return {
|
2014-11-22 15:05:54 +01:00
|
|
|
description = "When user sends twitter URL, send text and images to origin. Requieres OAuth Key.",
|
2014-11-05 13:22:07 +01:00
|
|
|
usage = "",
|
|
|
|
patterns = {"https://twitter.com/[^/]+/status/([0-9]+)"},
|
|
|
|
run = run
|
2015-02-13 01:55:16 +01:00
|
|
|
}
|