This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/twitter_send.lua

51 lines
1.7 KiB
Lua
Raw Normal View History

2015-04-14 20:23:55 +02:00
do
local OAuth = require "OAuth"
local consumer_key = cred_data.tw_consumer_key
local consumer_secret = cred_data.tw_consumer_secret
local access_token = cred_data.tw_access_token
local access_token_secret = cred_data.tw_access_token_secret
2015-04-14 20:23:55 +02: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
2015-04-14 20:23:55 +02:00
})
function run(msg, matches)
if consumer_key:isempty() then
return "Twitter Consumer Key ist nicht vorhanden, schreibe ihn in data/credentials.lua"
2015-04-14 20:23:55 +02:00
end
if consumer_secret:isempty() then
return "Twitter Consumer Secret ist nicht vorhanden, schreibe ihn in data/credentials.lua"
2015-04-14 20:23:55 +02:00
end
if access_token:isempty() then
return "Twitter Access Token ist nicht vorhanden, schreibe ihn in data/credentials.lua"
2015-04-14 20:23:55 +02:00
end
if access_token_secret:isempty() then
return "Twitter Access Token Secret ist nicht vorhanden, schreibe ihn in data/credentials.lua"
2015-04-14 20:23:55 +02:00
end
local response_code, response_headers, response_status_line, response_body =
client:PerformRequest("POST", "https://api.twitter.com/1.1/statuses/update.json", {
status = matches[1]
})
if response_code ~= 200 then
return "Fehler: "..response_code
end
local data = json:decode(response_body)
2015-06-10 14:30:08 +02:00
return "Tweet gesendet! Sieh ihn dir an: https://twitter.com/Mikubot_/status/"..data.id_str
2015-04-14 20:23:55 +02:00
end
return {
description = "Sende Tweets auf Twitter! twitter.com/Mikubot_",
usage = {"#tw [Text]"},
patterns = {"^#tw (.+)"},
run = run,
2015-04-14 20:23:55 +02:00
}
end