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

40 lines
1.0 KiB
Lua
Raw Normal View History

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)
2016-10-13 12:43:50 +02:00
local res,code = https.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
2016-10-13 12:43:50 +02:00
site_url = 'https://riko.moe'
elseif matches[1]:match('[Yy][Aa][Gg][Yy][Uu][Uu]') then
2016-10-13 12:43:50 +02:00
site_url = 'https://yagyuu.moe'
end
2016-08-24 17:18:17 +02:00
utilities.send_typing(msg.chat.id, 'upload_photo')
local photo_url = moe:get_url(site_url)
if not photo_url then
2016-08-24 17:18:17 +02:00
utilities.send_reply(msg, config.errors.connection)
return
end
2017-01-21 19:25:19 +01:00
utilities.send_photo(msg.chat.id, photo_url, nil, msg.message_id)
end
return moe