diff --git a/miku/plugins/kickstarter_search.lua b/miku/plugins/kickstarter_search.lua new file mode 100644 index 0000000..e5c3c9d --- /dev/null +++ b/miku/plugins/kickstarter_search.lua @@ -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* __: Sucht Projekt auf Kickstarter]] + kickstarter_search.command = 'kicks ' +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 = ''..title..' von '..from..' ('..country..')\n'..pledged..currency..' von '..goal..currency..' erreicht\n'..'Läuft von '..created..' bis '..ending..'\n'..desc..'\nProjektseite aufrufen' + 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 \ No newline at end of file diff --git a/miku/plugins/wordpress_posts.lua b/miku/plugins/wordpress_posts.lua index a17267f..a498987 100644 --- a/miku/plugins/wordpress_posts.lua +++ b/miku/plugins/wordpress_posts.lua @@ -73,7 +73,7 @@ function wordpress_recent_post:action(msg, config, matches) if image_url then utilities.send_typing(self, msg.chat.id, 'upload_photo') 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 utilities.send_reply(self, msg, text, 'HTML') end