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/moe.lua
2016-08-24 17:18:17 +02:00

41 lines
1.0 KiB
Lua

local moe = {}
function moe:init(config)
moe.triggers = {
"^/([Rr][Ii][Kk][Oo])$",
"^/([Yy][Aa][Gg][Yy][Uu][Uu])$"
}
moe.doc = [[*
]]..config.cmd_pat..[[riko*: Postet ein Bild von riko.moe
*]]..config.cmd_pat..[[yagyuu*: Postet ein Bild von yagyuu.moe
]]
end
moe.command = 'riko, /yagyuu'
function moe:get_url(site_url)
local res,code = http.request(site_url)
if code ~= 200 then return nil end
local photo_url = res:match("<img src%=\"(.-)\" alt")
local photo_url = site_url..'/'..photo_url
return photo_url
end
function moe:action(msg, config, matches)
if matches[1]:match('[Rr][Ii][Kk][Oo]') then
site_url = 'http://riko.moe'
elseif matches[1]:match('[Yy][Aa][Gg][Yy][Uu][Uu]') then
site_url = 'http://yagyuu.moe'
end
utilities.send_typing(msg.chat.id, 'upload_photo')
local photo_url = moe:get_url(site_url)
if not photo_url then
utilities.send_reply(msg, config.errors.connection)
return
end
local file = download_to_file(photo_url)
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
end
return moe