forgeFRENParcourir les dépôts

misehooksbackend_search_tools.lua

6b43a505698341ce02e15c97ca3d37e17537fa47

At commit 6b43a50

38 lines · 1.4 KiBLuaRaw
  1. local forge = require("forge")
  2. function PLUGIN:BackendSearchTools(ctx)
  3. local base_url = forge.base_url(nil)
  4. local repos = forge.list_repos(base_url)
  5. local query = string.lower(tostring((ctx and ctx.query) or ""))
  6. local tools = {}
  7. for _, repo in ipairs(repos) do
  8. if type(repo) == "table" and type(repo.name) == "string" and repo.name ~= "" then
  9. if type(repo.latest_release) == "string" and repo.latest_release ~= "" then
  10. local name = repo.name
  11. local desc = type(repo.description) == "string" and repo.description or ""
  12. local match = (query == "")
  13. or (string.lower(name):find(query, 1, true) ~= nil)
  14. or (string.lower(desc):find(query, 1, true) ~= nil)
  15. if not match and type(repo.topics) == "table" then
  16. for _, topic in ipairs(repo.topics) do
  17. if type(topic) == "string" and string.lower(topic):find(query, 1, true) ~= nil then
  18. match = true
  19. break
  20. end
  21. end
  22. end
  23. if match then
  24. table.insert(tools, {
  25. name = name,
  26. description = desc,
  27. })
  28. end
  29. end
  30. end
  31. end
  32. return { tools = tools }
  33. end