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

50 lines
1.5 KiB
Lua
Raw Normal View History

2014-11-05 20:51:20 +01:00
local OAuth = require "OAuth"
local consumer_key = ""
local consumer_secret = ""
local access_token = ""
local access_token_secret = ""
2014-11-05 20:51:20 +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"
2015-01-06 14:32:42 +01:00
}, {
2014-11-05 20:51:20 +01:00
OAuthToken = access_token,
OAuthTokenSecret = access_token_secret
})
function run(msg, matches)
2015-01-06 14:32:42 +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-27 21:44:29 +01:00
if not is_sudo(msg) then
return "You aren't allowed to send tweets"
end
2015-01-06 14:32:42 +01:00
local response_code, response_headers, response_status_line, response_body =
2014-11-05 20:51:20 +01:00
client:PerformRequest("POST", "https://api.twitter.com/1.1/statuses/update.json", {
2015-01-06 14:32:42 +01:00
status = matches[1]
})
2014-11-05 20:51:20 +01:00
if response_code ~= 200 then
2015-01-06 14:32:42 +01:00
return "Error: "..response_code
2014-11-05 20:51:20 +01:00
end
2015-01-06 14:32:42 +01:00
return "Tweet sended"
2014-11-05 20:51:20 +01:00
end
return {
description = "Sends a tweet",
usage = "!tw [text]",
2014-11-17 21:55:25 +01:00
patterns = {"^!tw (.+)"},
2014-11-05 20:51:20 +01:00
run = run
}