- kickstarter_search hinzugefügt
- Bugfix für WordPress_Posts
This commit is contained in:
parent
91614a1c63
commit
d15a38daff
56
miku/plugins/kickstarter_search.lua
Normal file
56
miku/plugins/kickstarter_search.lua
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
local kickstarter_search = {}
|
||||||
|
|
||||||
|
function kickstarter_search:init(config)
|
||||||
|
kickstarter_search.triggers = {
|
||||||
|
"/[Kk][Ii][Cc][Kk][Ss] (.+)$"
|
||||||
|
}
|
||||||
|
kickstarter_search.doc = [[*
|
||||||
|
]]..config.cmd_pat..[[kicks* _<Suchbegriff>_: Sucht Projekt auf Kickstarter]]
|
||||||
|
kickstarter_search.command = 'kicks <Suchbegriff>'
|
||||||
|
end
|
||||||
|
|
||||||
|
function kickstarter_search:search_it(query)
|
||||||
|
local url = 'https://www.kickstarter.com/projects/search.json?term='..query
|
||||||
|
local res, code = https.request(url)
|
||||||
|
if code ~= 200 then return nil end
|
||||||
|
local data = json.decode(res).projects[1]
|
||||||
|
if not data then return 'NOTFOUND' end
|
||||||
|
|
||||||
|
local title = data.name
|
||||||
|
local from = data.creator.name
|
||||||
|
local country = data.country
|
||||||
|
local desc = data.blurb
|
||||||
|
local pledged = comma_value(string.gsub(data.pledged, "%.(.*)", ""))
|
||||||
|
local goal = comma_value(data.goal)
|
||||||
|
local currency = data.currency_symbol
|
||||||
|
local created = string.gsub(convert_timestamp(data.launched_at, '%d.%m.%Y'), '%\n', '')
|
||||||
|
local ending = convert_timestamp(data.deadline, '%d.%m.%Y')
|
||||||
|
local url = data.urls.web.project
|
||||||
|
if data.photo.full then
|
||||||
|
image_url = data.photo.full
|
||||||
|
end
|
||||||
|
|
||||||
|
local text = '<b>'..title..'</b> von <i>'..from..' ('..country..')</i>\n'..pledged..currency..' von '..goal..currency..' erreicht\n'..'Läuft von '..created..' bis '..ending..'\n<i>'..desc..'</i>\n<a href="'..url..'">Projektseite aufrufen</a>'
|
||||||
|
return text, image_url
|
||||||
|
end
|
||||||
|
|
||||||
|
function kickstarter_search:action(msg, config, matches)
|
||||||
|
local query = matches[1]
|
||||||
|
local text, image_url = kickstarter_search:search_it(query, slug)
|
||||||
|
if not text then
|
||||||
|
utilities.send_reply(self, msg, config.errors.connection)
|
||||||
|
return
|
||||||
|
elseif text == 'NOTFOUND' then
|
||||||
|
utilities.send_reply(self, msg, config.errors.results)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if image_url then
|
||||||
|
utilities.send_typing(self, msg.chat.id, 'upload_photo')
|
||||||
|
local file = download_to_file(image_url, query..'.png')
|
||||||
|
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
|
||||||
|
end
|
||||||
|
utilities.send_reply(self, msg, text, 'HTML')
|
||||||
|
end
|
||||||
|
|
||||||
|
return kickstarter_search
|
@ -73,7 +73,7 @@ function wordpress_recent_post:action(msg, config, matches)
|
|||||||
if image_url then
|
if image_url then
|
||||||
utilities.send_typing(self, msg.chat.id, 'upload_photo')
|
utilities.send_typing(self, msg.chat.id, 'upload_photo')
|
||||||
local file = download_to_file(image_url)
|
local file = download_to_file(image_url)
|
||||||
utilities.send_photo(self, msg.chat.id, file, text, msg.message_id)
|
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
|
||||||
end
|
end
|
||||||
utilities.send_reply(self, msg, text, 'HTML')
|
utilities.send_reply(self, msg, text, 'HTML')
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user