Chatcommand scheduler_add without paramater mask

This commit is contained in:
AliasAlreadyTaken 2024-04-09 18:40:56 +02:00
parent b50d0fea33
commit d0f0a5fb14
2 changed files with 53 additions and 7 deletions

View File

@ -1,6 +1,6 @@
local chatcommand_cmd = "scheduler_add"
local chatcommand_params =
"<time$function$[param1, param2, param3, ...][$notes]>"
"<time$function$[param1, param2, param3, ...][$param mask][$notes]>"
local chatcommand_description =
"Adds a new task that executes a function with params at the given time. See /" ..
chatcommand_cmd .. " help"

View File

@ -24,8 +24,7 @@ end
local function is_uuid_duplicate(UUID)
for i, task in ipairs(yl_scheduler.tasks) do
say("action",
"task.id=" .. dump(task.id) .. ", UUID=" .. dump(UUID))
say("action", "task.id=" .. dump(task.id) .. ", UUID=" .. dump(UUID))
if task.id == UUID then return true end
end
return false
@ -232,13 +231,15 @@ local function load_all_tasks()
if bad == 0 then
minetest.log("action",
"[MOD] yl_scheduler : bad = " .. tostring(bad) .. ", good = " ..
tostring(good) .. ", total = " .. tostring(total))
"[MOD] yl_scheduler : bad = " .. tostring(bad) ..
", good = " .. tostring(good) .. ", total = " ..
tostring(total))
return true, good, bad
else
minetest.log("warning",
"[MOD] yl_scheduler : bad = " .. tostring(bad) .. ", good = " ..
tostring(good) .. ", total = " .. tostring(total))
"[MOD] yl_scheduler : bad = " .. tostring(bad) ..
", good = " .. tostring(good) .. ", total = " ..
tostring(total))
return false, good, bad
end
end
@ -305,7 +306,52 @@ function yl_scheduler.remove_file(UUID) return remove_file(UUID) end
-- ### scheduler_add ###
local function cmd_scheduler_add(name, c_params)
-- This is what a chatcommand may look like:
-- /scheduler_add 384756378465$minetest.log$action, text to be logged$$some notes
-- /scheduler_add 384756378465$minetest.log$action, text to be logged
-- /scheduler_add 384756378465$switch_maze
-- /scheduler_add 384756378465$switch_maze$$$some more notes
-- cast:
-- /scheduler_add 384756378465$switch_maze$(int)456, (string)mystring$some more notes
-- mask:
-- /scheduler_add 384756378465$switch_maze$456,mystring$int, string$some more notes
-- The mask should be optional, if none is given we assume strings
if not c_params or c_params == "help" then
return true,
"Adds a new task that executes a function with params at the given time.\n" ..
"Separate time, function, parameters, mask and notes with $\n" ..
"Example: /scheduler_add 1712679465$minetest.log$action,mytext$string,string$mynotes\n"
elseif c_params == "helpmask" then
return true, "Provide a parameter mask to convert the parameters to number or table" ..
"Allowed values are \"string\",\"number\",\"table\"" ..
"If your use case requires other types, please create a wrapper function."
end
local t_parameters = string.split(c_params, "$", true)
local at = tonumber(t_parameters[1])
local func = t_parameters[2]
--local string_params = string.split(t_parameters[3], ",") -- optional
local params = string.split(t_parameters[3], ",") -- optional
local mask = string.split(t_parameters[4], ",") or {} -- optional
local owner = name or "N/A"
local notes = t_parameters[5] or "" -- optional
-- local param_success, params = unmask_params(string_params, mask)
if (param_success == false) then return false, params end
local success, message = yl_scheduler.set_task(at, func, params, owner,
notes)
if success == true then
yl_scheduler.tasks = sort_by_timestamp(yl_scheduler.tasks)
end
return success, message
end
function yl_scheduler.cmd_scheduler_add(name, params)