From 24a294498bb3ac7895548378a71146d74931eafe Mon Sep 17 00:00:00 2001 From: AliasAlreadyTaken Date: Wed, 5 Jun 2024 04:08:06 +0200 Subject: [PATCH] your-land/yl_ticker#9 Implements ticker_examples --- README.md | 22 +++++++++++++++++++++- chatcommand_examples.lua | 27 +++++++++++++++++++++++++++ chatcommands.lua | 1 + config.lua | 2 ++ internal.lua | 33 +++++++++++++++++++++++++++++++++ settingtypes.txt | 9 +++++++-- 6 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 chatcommand_examples.lua diff --git a/README.md b/README.md index a22b470..7b00060 100644 --- a/README.md +++ b/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 diff --git a/chatcommand_examples.lua b/chatcommand_examples.lua new file mode 100644 index 0000000..c7d52ed --- /dev/null +++ b/chatcommand_examples.lua @@ -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) diff --git a/chatcommands.lua b/chatcommands.lua index 504105d..4971054 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -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") diff --git a/config.lua b/config.lua index 9f9719e..65f7985 100644 --- a/config.lua +++ b/config.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" diff --git a/internal.lua b/internal.lua index a036df8..6820068 100644 --- a/internal.lua +++ b/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 diff --git a/settingtypes.txt b/settingtypes.txt index d3c50ee..e24fef7 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -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