Adds chatcommands, without inner functions

This commit is contained in:
AliasAlreadyTaken 2024-04-08 03:24:39 +02:00
parent a0b137115e
commit 238f3c022a
8 changed files with 83 additions and 5 deletions

View File

@ -48,7 +48,7 @@ This mod targets servers, but should work in singleplayer, too. It comes with no
```
/scheduler_add time$function$param1, param2, param3, ...$notes
```
Adds a new task that executes function with params at the given time and optionally adds notes
Adds a new task that executes a function with params at the given time and optionally adds notes
time: At best a utc timestamp, at worst some natural time. See [Supported Time formats](#supported-time-formats)

View File

@ -0,0 +1,19 @@
local chatcommand_cmd = "scheduler_add"
local chatcommand_params = "<time$function$[param1, param2, param3, ...][$notes]>"
local chatcommand_description = "Adds a new task that executes a function with params at the given time. See /".. chatcommand_cmd .. " help"
local chatcommand_definition = {
params = chatcommand_params,
description = chatcommand_description,
privs = yl_scheduler.get_privs(chatcommand_cmd),
func = function(name, params)
local success, message = yl_scheduler["cmd_" .. chatcommand_cmd](name, params)
if success then
return true, message
else
return false, message
end
end
}
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)

View File

@ -0,0 +1,19 @@
local chatcommand_cmd = "scheduler_clean"
local chatcommand_params = ""
local chatcommand_description = "Cleans up the past tasks. Old tasks are permanently deleted. See /".. chatcommand_cmd .. " help"
local chatcommand_definition = {
params = chatcommand_params,
description = chatcommand_description,
privs = yl_scheduler.get_privs(chatcommand_cmd),
func = function(name, params)
local success, message = yl_scheduler["cmd_" .. chatcommand_cmd](name, params)
if success then
return true, message
else
return false, message
end
end
}
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)

View File

@ -0,0 +1,19 @@
local chatcommand_cmd = "scheduler_list"
local chatcommand_params = "[[part of] UUID]"
local chatcommand_description = "Lists all tasks, optionally only those that match the given (part of a) UUID. See /".. chatcommand_cmd .. " help"
local chatcommand_definition = {
params = chatcommand_params,
description = chatcommand_description,
privs = yl_scheduler.get_privs(chatcommand_cmd),
func = function(name, params)
local success, message = yl_scheduler["cmd_" .. chatcommand_cmd](name, params)
if success then
return true, message
else
return false, message
end
end
}
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)

View File

@ -0,0 +1,19 @@
local chatcommand_cmd = "scheduler_remove"
local chatcommand_params = "<UUID>"
local chatcommand_description = "Removes the given UUID from the task list. See /".. chatcommand_cmd .. " help"
local chatcommand_definition = {
params = chatcommand_params,
description = chatcommand_description,
privs = yl_scheduler.get_privs(chatcommand_cmd),
func = function(name, params)
local success, message = yl_scheduler["cmd_" .. chatcommand_cmd](name, params)
if success then
return true, message
else
return false, message
end
end
}
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)

View File

@ -1,2 +1,4 @@
dofile(yl_template.modpath .. "chatcommand_admin.lua")
dofile(yl_template.modpath .. "chatcommand_player.lua")
dofile(yl_scheduler.modpath .. "chatcommand_scheduler_add.lua")
dofile(yl_scheduler.modpath .. "chatcommand_scheduler_remove.lua")
dofile(yl_scheduler.modpath .. "chatcommand_scheduler_list.lua")
dofile(yl_scheduler.modpath .. "chatcommand_scheduler_clean.lua")

View File

@ -24,7 +24,7 @@ What's more efficient? Have an index with UUID? We often query those, but the qu
- Create example JSON files OK
- Add loading from JSON files OK
- Add Task via chatcommand
- Add Task via chatcommand <-------
- Remove Task via chatcommand
- List Task via chatcommand
- Clean Tasks via chatcommand

View File

@ -28,7 +28,7 @@ dofile(yl_scheduler.modpath .. "internal.lua")
--dofile(yl_scheduler.modpath .. "api.lua")
dofile(yl_scheduler.modpath .. "initialize.lua")
--dofile(yl_scheduler.modpath .. "globalsteps.lua")
--dofile(yl_scheduler.modpath .. "chatcommands.lua")
dofile(yl_scheduler.modpath .. "chatcommands.lua")
local mod_end_time = (core.get_us_time() - mod_start_time) / 1000000
core.log("action", "[MOD] yl_scheduler loaded in [" .. mod_end_time .. "s]")