Created
July 12, 2024 08:32
-
-
Save ZookaOnGit/e0348b98e24ef78045863a503527dff7 to your computer and use it in GitHub Desktop.
Command Line API Search for Mudlet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE MudletPackage> | |
<MudletPackage version="1.001"> | |
<AliasPackage> | |
<Alias isActive="yes" isFolder="no"> | |
<name>Command Line API</name> | |
<script>-- Command line API search and open tool | |
-- by Zooka. | |
-- Usage: !api string.lower -- specify a known function to open webpage | |
-- !api string -- specify a keyword to search | |
-- !api -- just open the technical manual | |
local API = "https://wiki.mudlet.org/w/Manual:Technical_Manual" | |
local gFunc = {} | |
local tFunc = {} | |
for k,v in spairs(_G) do | |
if type(v) == "function" then | |
-- remove some _G variable cruft | |
if not k:match("^Trigger%d+") and not k:match("^Alias%d+") and not k:match("^Key%d+") and not k:match("^Timer%d+")then | |
table.insert(gFunc, k) | |
end | |
end | |
if type(v) == "table" then | |
-- remove some _G variable cruft and generic_mapper functions | |
if not k:starts("_G") then | |
table.insert(tFunc, k) | |
end | |
end | |
end | |
for _,n in spairs(tFunc) do | |
for k,v in spairs(_G[n]) do | |
if type(_G[n][k]) == "function" then | |
local fun = f"{n}.{k}" | |
fun = string.gsub(fun, "^db.", "db:") -- fix objects | |
if not fun:starts("map.") then -- remove generic_mapper | |
table.insert(gFunc, fun) | |
end | |
end | |
end | |
end | |
-- if no args, just open up the API | |
if not matches[2] then | |
openWebPage(API) | |
return | |
end | |
local arg = matches[2]:lower() | |
for k,v in spairs(gFunc) do | |
if arg == v:lower() then | |
openWebPage(f"{API}#" .. gFunc[k]) | |
return | |
end | |
end | |
-- hrm, no match, let's search through and find some possible candidates | |
local matchFound = false | |
for k,v in spairs(gFunc) do | |
if string.match(v:lower(), arg) then | |
if not matchFound then echo("No matching functions found. Possible match:\n") end | |
cechoLink(f" {v}\n", function() openWebPage(API .. "#" ..v) end, "Click to open Mudlet API in a browser.", true) | |
matchFound = true | |
end | |
end | |
if not matchFound then | |
cechoLink("No matching functions found. Click to here open API anyway.\n", function() openWebPage(API) end, "Click to open Mudlet API in a browser.", true) | |
end</script> | |
<command></command> | |
<packageName></packageName> | |
<regex>^!api(?: (.*))?$</regex> | |
</Alias> | |
</AliasPackage> | |
</MudletPackage> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment