41 lines
1.0 KiB
Lua
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(self, msg.chat.id, 'upload_photo')
|
||
|
local photo_url = moe:get_url(site_url)
|
||
|
if not photo_url then
|
||
|
utilities.send_reply(self, msg, config.errors.connection)
|
||
|
return
|
||
|
end
|
||
|
local file = download_to_file(photo_url)
|
||
|
utilities.send_photo(self, msg.chat.id, file)
|
||
|
end
|
||
|
|
||
|
return moe
|