parent
73d7ec0edb
commit
447cb44166
@ -3,38 +3,167 @@
|
|||||||
|
|
||||||
do
|
do
|
||||||
|
|
||||||
local BASE_URL = 'https://graph.facebook.com'
|
local BASE_URL = 'https://graph.facebook.com/v2.5'
|
||||||
|
local fb_access_token = cred_data.fb_access_token
|
||||||
|
|
||||||
function get_fb_data (fb_code)
|
local makeOurDate = function(dateString)
|
||||||
local access_token = cred_data.fb_access_token
|
local pattern = "(%d+)%/(%d+)%/(%d+)"
|
||||||
local url = BASE_URL..'/'..fb_code..'?access_token='..access_token..'&locale=de_DE'
|
local month, day, year = dateString:match(pattern)
|
||||||
local res,code = https.request(url)
|
return day..'.'..month..'.'..year
|
||||||
if code ~= 200 then return "HTTP-FEHLER" end
|
|
||||||
local data = json:decode(res)
|
|
||||||
return data
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function send_fb_data(data, receiver)
|
local function get_fb_id(name)
|
||||||
|
local url = BASE_URL..'/'..name..'?access_token='..fb_access_token..'&locale=de_DE'
|
||||||
|
local res,code = https.request(url)
|
||||||
|
if code ~= 200 then return nil end
|
||||||
|
local data = json:decode(res)
|
||||||
|
return data.id
|
||||||
|
end
|
||||||
|
|
||||||
|
local function fb_post (id, story_id)
|
||||||
|
local url = BASE_URL..'/'..id..'_'..story_id..'?access_token='..fb_access_token..'&locale=de_DE&fields=from,name,story,message,link'
|
||||||
|
local res,code = https.request(url)
|
||||||
|
if code ~= 200 then return nil end
|
||||||
|
local data = json:decode(res)
|
||||||
|
|
||||||
local from = data.from.name
|
local from = data.from.name
|
||||||
local message = data.message
|
local message = data.message
|
||||||
local name = data.name
|
local name = data.name
|
||||||
local link = data.link
|
if data.link then
|
||||||
local text = from..' hat gepostet:\n'..message..'\n'..name..' '..link
|
link = '\n'..data.name..':\n'..data.link
|
||||||
|
else
|
||||||
|
link = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
if data.story then
|
||||||
|
story = ' ('..data.story..')'
|
||||||
|
else
|
||||||
|
story = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
local text = from..story..':\n'..message..'\n'..link
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
|
||||||
|
local function send_facebook_photo(photo_id, receiver)
|
||||||
|
local url = BASE_URL..'/'..photo_id..'?access_token='..fb_access_token..'&locale=de_DE&fields=images,from,name'
|
||||||
|
local res,code = https.request(url)
|
||||||
|
if code ~= 200 then return nil end
|
||||||
|
local data = json:decode(res)
|
||||||
|
|
||||||
|
local from = data.from.name
|
||||||
|
if data.name then
|
||||||
|
text = from..' hat ein Bild gepostet:\n'..data.name
|
||||||
|
else
|
||||||
|
text = from..' hat ein Bild gepostet:'
|
||||||
|
end
|
||||||
|
local image_url = data.images[1].source
|
||||||
|
local cb_extra = {
|
||||||
|
receiver=receiver,
|
||||||
|
url=image_url
|
||||||
|
}
|
||||||
|
send_msg(receiver, text, send_photo_from_url_callback, cb_extra)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function send_facebook_video(video_id, receiver)
|
||||||
|
local url = BASE_URL..'/'..video_id..'?access_token='..fb_access_token..'&locale=de_DE&fields=description,from,source,title'
|
||||||
|
local res,code = https.request(url)
|
||||||
|
if code ~= 200 then return nil end
|
||||||
|
local data = json:decode(res)
|
||||||
|
|
||||||
|
local from = data.from.name
|
||||||
|
local description = data.description
|
||||||
|
local source = data.source
|
||||||
|
if data.title then
|
||||||
|
text = from..' hat ein Video gepostet:\n'..description..'\n'..source..'\n('..data.title..')'
|
||||||
|
else
|
||||||
|
text = from..' hat ein Video gepostet:\n'..description..'\n'..source
|
||||||
|
end
|
||||||
send_msg(receiver, text, ok_cb, false)
|
send_msg(receiver, text, ok_cb, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
function run(msg, matches)
|
local function facebook_info(name)
|
||||||
local fb_code = matches[2]
|
local url = BASE_URL..'/'..name..'?access_token='..fb_access_token..'&locale=de_DE&fields=about,name,birthday,category,founded,general_info,is_verified'
|
||||||
local data = get_fb_data(fb_code)
|
local res,code = https.request(url)
|
||||||
local receiver = get_receiver(msg)
|
if code ~= 200 then return nil end
|
||||||
send_fb_data(data, receiver)
|
local data = json:decode(res)
|
||||||
|
|
||||||
|
local name = data.name
|
||||||
|
if data.is_verified then
|
||||||
|
name = name..' ✅'
|
||||||
|
end
|
||||||
|
|
||||||
|
local category = data.category
|
||||||
|
|
||||||
|
if data.about then
|
||||||
|
about = '\n'..data.about
|
||||||
|
else
|
||||||
|
about = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
if data.general_info then
|
||||||
|
general_info = '\n'..data.general_info
|
||||||
|
else
|
||||||
|
general_info = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
if data.birthday and data.founded then
|
||||||
|
birth = '\nGeburtstag: '..makeOurDate(data.birthday)
|
||||||
|
elseif data.birthday and not data.founded then
|
||||||
|
birth = '\nGeburtstag: '..makeOurDate(data.birthday)
|
||||||
|
elseif data.founded and not data.birthday then
|
||||||
|
birth = '\nGegründet: '..data.founded
|
||||||
|
else
|
||||||
|
birth = ""
|
||||||
|
end
|
||||||
|
|
||||||
|
local text = name..' ('..category..')'..about..general_info..birth
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
|
||||||
|
local function run(msg, matches)
|
||||||
|
if matches[1] == 'permalink' or matches[2] == 'posts' then
|
||||||
|
story_id = matches[3]
|
||||||
|
if not matches[4] then
|
||||||
|
id = get_fb_id(matches[1])
|
||||||
|
else
|
||||||
|
id = matches[4]
|
||||||
|
end
|
||||||
|
return fb_post(id, story_id)
|
||||||
|
elseif matches[1] == 'photo' or matches[2] == 'photos' then
|
||||||
|
if not matches[4] then
|
||||||
|
photo_id = matches[2]
|
||||||
|
else
|
||||||
|
photo_id = matches[4]
|
||||||
|
end
|
||||||
|
local receiver = get_receiver(msg)
|
||||||
|
send_facebook_photo(photo_id, receiver)
|
||||||
|
elseif matches[1] == 'video' or matches[2] == 'videos' then
|
||||||
|
if not matches[3] then
|
||||||
|
video_id = matches[2]
|
||||||
|
else
|
||||||
|
video_id = matches[3]
|
||||||
|
end
|
||||||
|
local receiver = get_receiver(msg)
|
||||||
|
send_facebook_video(video_id, receiver)
|
||||||
|
else
|
||||||
|
return facebook_info(matches[1])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description = "Sendet Facebook-Post.",
|
description = "Sendet Facebook-Post, -Foto, -Video oder -Info",
|
||||||
usage = {"Link zu einem Facebook-Post"},
|
usage = "URL zu öffentlichem Facebook-Post, -Foto, -Video oder -Info",
|
||||||
patterns = {"facebook.com/([A-Za-z0-9-_-]+)/posts/([0-9-]+)","facebook.com/permalink.([a-z-]+)%?story_fbid=([0-9-]+)"},
|
patterns = {
|
||||||
run = run
|
"facebook.com/([A-Za-z0-9-._-]+)/(posts)/(%d+)",
|
||||||
|
"facebook.com/(permalink).php%?(story_fbid)=(%d+)&id=(%d+)",
|
||||||
|
"facebook.com/(photo).php%?fbid=(%d+)",
|
||||||
|
"facebook.com/([A-Za-z0-9-._-]+)/(photos)/a.(%d+[%d%.]*)/(%d+)",
|
||||||
|
"facebook.com/(video).php%?v=(%d+)",
|
||||||
|
"facebook.com/([A-Za-z0-9-._-]+)/(videos)/(%d+[%d%.]*)",
|
||||||
|
"facebook.com/([A-Za-z0-9-._-]+)"
|
||||||
|
},
|
||||||
|
run = run
|
||||||
}
|
}
|
||||||
|
|
||||||
end
|
end
|
40
plugins/pluginsold/facebook.lua
Normal file
40
plugins/pluginsold/facebook.lua
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 <andi (dot) b (at) outlook (dot) de>
|
||||||
|
-- DO NOT USE WITHOUT PERMISSION
|
||||||
|
|
||||||
|
do
|
||||||
|
|
||||||
|
local BASE_URL = 'https://graph.facebook.com'
|
||||||
|
|
||||||
|
function get_fb_data (fb_code)
|
||||||
|
local access_token = cred_data.fb_access_token
|
||||||
|
local url = BASE_URL..'/'..fb_code..'?access_token='..access_token..'&locale=de_DE'
|
||||||
|
local res,code = https.request(url)
|
||||||
|
if code ~= 200 then return "HTTP-FEHLER" end
|
||||||
|
local data = json:decode(res)
|
||||||
|
return data
|
||||||
|
end
|
||||||
|
|
||||||
|
function send_fb_data(data, receiver)
|
||||||
|
local from = data.from.name
|
||||||
|
local message = data.message
|
||||||
|
local name = data.name
|
||||||
|
local link = data.link
|
||||||
|
local text = from..' hat gepostet:\n'..message..'\n'..name..' '..link
|
||||||
|
send_msg(receiver, text, ok_cb, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
function run(msg, matches)
|
||||||
|
local fb_code = matches[2]
|
||||||
|
local data = get_fb_data(fb_code)
|
||||||
|
local receiver = get_receiver(msg)
|
||||||
|
send_fb_data(data, receiver)
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
description = "Sendet Facebook-Post.",
|
||||||
|
usage = {"Link zu einem Facebook-Post"},
|
||||||
|
patterns = {"facebook.com/([A-Za-z0-9-_-]+)/posts/([0-9-]+)","facebook.com/permalink.([a-z-]+)%?story_fbid=([0-9-]+)"},
|
||||||
|
run = run
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
Reference in New Issue
Block a user