generated from your-land/yl_template
your-land/yl_ticker#9 Implements ticker_examples
This commit is contained in:
parent
9d5daf6e63
commit
24a294498b
22
README.md
22
README.md
@ -41,16 +41,24 @@ yl_ticker.frequency
|
||||
```
|
||||
Set this to the default repeat timer you want the ticker have in chat. 3600 means "once per hour"
|
||||
|
||||
```
|
||||
yl_ticker.examples
|
||||
```
|
||||
|
||||
Set this to what the examples command should display. Break line with `\n`
|
||||
|
||||
```
|
||||
yl_ticker.user_privs
|
||||
yl_ticker.admin_privs
|
||||
```
|
||||
Set those to the list of privs you want to allow the execution of the corresponding commands:
|
||||
|
||||
yl_ticker.user_privs allows
|
||||
yl_ticker.user_privs allows
|
||||
* listing single ticker
|
||||
* copy single ticker
|
||||
* listing all tickers
|
||||
* Show help
|
||||
* Show examples
|
||||
|
||||
yl_ticker.admin_privs allows
|
||||
* listing single ticker
|
||||
@ -139,6 +147,18 @@ Say the ticker with ID in main chat.
|
||||
|
||||
Say all tickers in main chat.
|
||||
|
||||
```
|
||||
/ticker_help
|
||||
```
|
||||
|
||||
Displays a help overview of all ticker-related commands
|
||||
|
||||
```
|
||||
/ticker_examples
|
||||
```
|
||||
|
||||
Shows a formspec with (configurable) examples people can copy out of
|
||||
|
||||
### Modmakers
|
||||
|
||||
Use the following public functions to get, set, list and remove ticker
|
||||
|
||||
27
chatcommand_examples.lua
Normal file
27
chatcommand_examples.lua
Normal file
@ -0,0 +1,27 @@
|
||||
local chatcommand_cmd = yl_ticker.settings.chatcommand_domain .. "_examples"
|
||||
local chatcommand_definition = {
|
||||
params = "",
|
||||
description = "Shows copyable examples for /" ..
|
||||
yl_ticker.settings.chatcommand_domain .. "_add commands." ..
|
||||
"\nExample: /" .. chatcommand_cmd,
|
||||
privs = {[yl_ticker.settings.user_privs] = true},
|
||||
func = function(name, param)
|
||||
local success, message = yl_ticker.chatcommand_ticker_examples(name,
|
||||
param)
|
||||
|
||||
if success then
|
||||
minetest.log("action", "[yl_ticker] player " .. name ..
|
||||
" displays examples for ticker: " .. param)
|
||||
return true, message
|
||||
else
|
||||
minetest.log("warning",
|
||||
"[yl_ticker] player " .. name ..
|
||||
" displays examples for ticker: " .. param ..
|
||||
" unsuccessfully, message: " .. message)
|
||||
return false, message
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)
|
||||
yl_ticker.register_help(chatcommand_cmd, chatcommand_definition)
|
||||
@ -6,3 +6,4 @@ dofile(yl_ticker.modpath .. DIR_DELIM .. "chatcommand_say.lua")
|
||||
dofile(yl_ticker.modpath .. DIR_DELIM .. "chatcommand_say_all.lua")
|
||||
dofile(yl_ticker.modpath .. DIR_DELIM .. "chatcommand_copy.lua")
|
||||
dofile(yl_ticker.modpath .. DIR_DELIM .. "chatcommand_help.lua")
|
||||
dofile(yl_ticker.modpath .. DIR_DELIM .. "chatcommand_examples.lua")
|
||||
|
||||
@ -13,6 +13,8 @@ yl_ticker.settings.colour = minetest.settings:get("yl_ticker.colour") or "#7676f
|
||||
|
||||
yl_ticker.settings.frequency = minetest.settings:get("yl_ticker.frequency") or 3600
|
||||
|
||||
yl_ticker.settings.examples = minetest.settings:get("yl_ticker.examples") or "No examples configured"
|
||||
|
||||
yl_ticker.settings.user_privs = minetest.settings:get("yl_ticker.user_privs") or "interact"
|
||||
|
||||
yl_ticker.settings.admin_privs = minetest.settings:get("yl_ticker.admin_privs") or "server"
|
||||
|
||||
33
internal.lua
33
internal.lua
@ -238,6 +238,20 @@ end
|
||||
|
||||
function yl_ticker.display_help() return display_help() end
|
||||
|
||||
local function display_examples()
|
||||
if (type(yl_ticker.settings.examples) ~= "string") then
|
||||
return false, "settings.examples not a string"
|
||||
end
|
||||
local content_raw = yl_ticker.settings.examples:gsub("\\n", "\n")
|
||||
local content = minetest.formspec_escape(content_raw)
|
||||
local formspec = "formspec_version[6]" .. "size[16,6]" ..
|
||||
"button_exit[15.4,0.1;0.5,0.5;X;X]" ..
|
||||
"textarea[0.05,0.05;15.3,5.9;;;" .. content .. "]"
|
||||
return true, formspec
|
||||
end
|
||||
|
||||
function yl_ticker.display_examples() return display_examples() end
|
||||
|
||||
-- Chatcommands
|
||||
--
|
||||
|
||||
@ -566,3 +580,22 @@ function yl_ticker.chatcommand_ticker_help(name, param) -- param must be empty
|
||||
|
||||
return true, message
|
||||
end
|
||||
|
||||
function yl_ticker.chatcommand_ticker_examples(name, param)
|
||||
-- defense
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then return false, "Player not online" end
|
||||
if param ~= "" then
|
||||
return false, "This command displays the help for the ticker. " ..
|
||||
"Do /ticker_examples without parameters."
|
||||
end
|
||||
|
||||
local success, formspecstring = yl_ticker.display_examples()
|
||||
|
||||
if (success == false) then return false, formspecstring end
|
||||
|
||||
-- Send the formspec
|
||||
minetest.show_formspec(name, "yl_ticker:examples", formspecstring)
|
||||
-- Report
|
||||
return true, "Showed examples"
|
||||
end
|
||||
|
||||
@ -20,10 +20,15 @@ yl_ticker.chatcommand_domain (Chatcommand domain) string ticker
|
||||
# Optional, default is "#7676ff" ("cornflower blue")
|
||||
yl_ticker.colour (Colour) string #7676ff
|
||||
|
||||
# Frequency
|
||||
# Default frequency
|
||||
# Set this to the default repeat timer you want the ticker have in chat
|
||||
# Optional, default is 3600 seconds (means: once per hour)
|
||||
yl_ticker.frequency (Frequency) float 3600.0 1.0
|
||||
yl_ticker.frequency (Default frequency) float 3600.0 1.0
|
||||
|
||||
# Examplestring
|
||||
# Set this to what the examples command should display. Break line with \n
|
||||
# Optional, default are some common examples
|
||||
yl_ticker.examples (Examplestring) string /ticker_add [VOTE] Voting ends tonight at midnight! $50$3600\n/ticker_add [EVENT] End of Bailiff Votes!$3600$1w\n/ticker_add [EVENT] End of Bailiff Votes!$1 h $7d
|
||||
|
||||
# User privs
|
||||
# Enable holders of these privs to list and copy ticker
|
||||
|
||||
Loading…
Reference in New Issue
Block a user