Advertisement
Seniru_Pasan

api-searcher

Jun 25th, 2020
964
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.73 KB | None | 0 0
  1. local query = (parameters or ""):gsub("%s+", "%%20")
  2.  
  3. if query == "" then
  4.     return discord.sendError("apis", "Invalid query")
  5. end
  6.  
  7. local head, body = discord.http("https://www.programmableweb.com/category/all/apis?keyword=" .. query)
  8. print(body)
  9. local fields = {}
  10. for api in body:gmatch("<tr .->(.-)</tr>") do
  11.     if #fields < 10 then
  12.          local link, name, desc, cat, followers = api:match("<a href=\"(.-)\">(.-)</a>.-<td.->(.-)</td>.-<a href=\"/category/.-\">(.-)</a></td><td.-> (%d+)</td>")          
  13.           fields[#fields + 1] = {name=name, value=(desc and desc:gsub("</?strong>", "**") or "") .. "\n👥 " .. followers .. " | 🗂 " .. cat .. " | [link](https://www.programmableweb.com" .. link .. ")"}
  14. else break end
  15. end
  16.  
  17. discord.reply {
  18.     embed = {
  19.         description = ":mag_right: Searched for `" .. parameters .. "`\n Check all results [here](https://www.programmableweb.com/category/all/apis?keyword=" .. query .. ")",
  20.         title = "Search APIs",
  21.         fields = fields,
  22.         color = 0x5588ff
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement