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-2/miku/plugins/pr0gramm.lua

43 lines
1.1 KiB
Lua
Raw Normal View History

local pr0gramm = {}
function pr0gramm:init(config)
pr0gramm.triggers = {
"pr0gramm.com/.*/(%d+)",
"^/[Pp][Rr]0 (%d+)$"
}
pr0gramm.doc = [[*
]]..config.cmd_pat..[[pr0* _<ID>_: Sendet Bild von pr0gramm]]
end
pr0gramm.command = 'pr0 <ID>'
function pr0gramm:get_post(id)
local url = 'http://pr0gramm.com/api/items/get.json?id='..id
local res, code = http.request(url)
if code ~= 200 then return nil end
local data = json.decode(res).items[1]
if not data then return nil end
local img = data.image
return 'http://img.pr0gramm.com/'..img
end
function pr0gramm:action(msg, config, matches)
local id = matches[1]
local url = pr0gramm:get_post(id)
if not url then
utilities.send_reply(self, msg, config.errors.results)
return
end
utilities.send_typing(self, msg.chat.id, 'upload_photo')
local file = download_to_file(url)
if string.match(url, ".gif") or string.match(url, ".zip") or string.match(url, ".webm") or string.match(url, ".mp4") then
utilities.send_document(self, msg.chat.id, file, nil, msg.message_id)
else
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
end
end
return pr0gramm