- Plugin für img.ponywave.de & img.akamaru.de (unterstützt auch Inline)

- /me Plugin
This commit is contained in:
Andreas Bielawski 2016-08-15 23:39:27 +02:00
parent bdae9d5302
commit 9f54bf22f9
2 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,55 @@
local cf_img = {}
cf_img.triggers = {
'(https?://img.ponywave.de)/(.*).html',
'(https?://img.akamaru.de)/(.*).html'
}
cf_img.inline_triggers = cf_img.triggers
function cf_img:get_full_url(site, pic)
local url = site..'/'..pic..'.html'
local doer = http
if url:match('^https') then
doer = https
end
local res, code = doer.request(url)
if code ~= 200 then return nil end
local full_url = string.match(res, "id=\"codedirect\" value%=\"(.-)\" onclick")
return full_url
end
function cf_img:inline_callback(inline_query, config, matches)
local site = matches[1]
local pic = matches[2]
local full_url = cf_img:get_full_url(site, pic)
if not full_url then utilities.answer_inline_query(self, inline_query) return end
local results
if string.ends(full_url, '.gif') then
results = '[{"type":"gif","id":"7778","gif_url":"'..full_url..'","thumb_url":"'..full_url..'"}]'
else
results = '[{"type":"photo","id":"7777","photo_url":"'..full_url..'","thumb_url":"'..full_url..'"}]'
end
utilities.answer_inline_query(self, inline_query, results, 3600, true)
end
function cf_img:action(msg, config, matches)
local site = matches[1]
local pic = matches[2]
local full_url = cf_img:get_full_url(site, pic)
if not full_url then
utilities.send_reply(self, msg, config.errors.connection)
return
end
utilities.send_typing(self, msg.chat.id, 'upload_photo')
local file = download_to_file(full_url)
if string.ends(full_url, '.gif') 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 cf_img

19
miku/plugins/me.lua Normal file
View File

@ -0,0 +1,19 @@
local me = {}
function me:init(config)
me.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('me', true).table
me.doc = '*/me* _<Text>_'
end
me.command = 'me'
function me:action(msg, config)
local input = utilities.input_from_msg(msg)
if not input then
return
end
utilities.send_message(self, msg.chat.id, msg.from.first_name..' '..input)
end
return me