Refactors announcement to ticker. Great headache!

This commit is contained in:
AliasAlreadyTaken 2024-06-02 03:27:35 +02:00
parent 10dfaf4936
commit c49884062e
19 changed files with 375 additions and 375 deletions

114
README.md
View File

@ -1,5 +1,5 @@
# yl_announcements # yl_ticker
## Purpose ## Purpose
@ -7,54 +7,54 @@ This mod allows you to send messages to your players in an interval.
## Download ## Download
Get it from https://gitea.your-land.de/your-land/yl_announcements Get it from https://gitea.your-land.de/your-land/yl_ticker
## Installation ## Installation
1. Copy the "yl_announcements" folder to your mod directory. 1. Copy the "yl_ticker" folder to your mod directory.
2. Enable the mod in your world.mt file. 2. Enable the mod in your world.mt file.
## Configuration ## Configuration
``` ```
yl_announcements.debug = false yl_ticker.debug = false
``` ```
Set to true to enable debug mode Set to true to enable debug mode
``` ```
yl_announcements.save_path yl_ticker.save_path
``` ```
Set this to where in the worldfolder you want the JSON files stored. Set this to where in the worldfolder you want the JSON files stored.
``` ```
yl_announcements.colour yl_ticker.colour
``` ```
Set this to the colour you want the announcements have in chat Set this to the colour you want the ticker have in chat
``` ```
yl_announcements.frequency yl_ticker.frequency
``` ```
Set this to the default repeat timer you want the announcements have in chat. 3600 means "once per hour" Set this to the default repeat timer you want the ticker have in chat. 3600 means "once per hour"
``` ```
yl_announcements.user_privs yl_ticker.user_privs
yl_announcements.admin_privs yl_ticker.admin_privs
``` ```
Set those to the list of privs you want to allow the execution of the corresponding commands: Set those to the list of privs you want to allow the execution of the corresponding commands:
yl_announcements.user_privs allows yl_ticker.user_privs allows
* listing single announcement * listing single ticker
* copy single announcement * copy single ticker
* listing all announcements * listing all tickers
yl_announcements.admin_privs allows yl_ticker.admin_privs allows
* listing single announcement * listing single ticker
* copy single announcement * copy single ticker
* listing all announcements * listing all tickers
* add announcement * add ticker
* delete announcement * delete ticker
* say announcement to main chat * say ticker to main chat
* say all announcements to main chat * say all tickers to main chat
## Usage ## Usage
@ -62,7 +62,7 @@ This mod targets servers, but should work in singleplayer, too. It comes with no
### Data structure ### Data structure
One announcement consists of an id, a message, an owner, a runtime and a frequency. Example: One ticker consists of an id, a message, an owner, a runtime and a frequency. Example:
``` ```
{ {
@ -75,99 +75,99 @@ One announcement consists of an id, a message, an owner, a runtime and a frequen
} }
``` ```
Those announcements sit in a table with `id` as index: Those tickers sit in a table with `id` as index:
``` ```
{ {
1 = {announcement}, 1 = {ticker},
2 = {announcement}, 2 = {ticker},
["5"] = {announcement} ["5"] = {ticker}
} }
``` ```
### Chatcommands ### Chatcommands
``` ```
/announcement_add message$frequency in seconds$runtime in seconds /ticker_add message$frequency in seconds$runtime in seconds
``` ```
Sends the message each frequency seconds for a maximum number of runtime seconds. Sends the message each frequency seconds for a maximum number of runtime seconds.
``` ```
/announcement_copy announcement_id /ticker_copy ticker_id
``` ```
Open the announcement with ID in a formspec, so it can be copied. Open the ticker with ID in a formspec, so it can be copied.
``` ```
/announcement_delete announcement_id /ticker_delete ticker_id
``` ```
Delete the announcement ID. Delete the ticker ID.
``` ```
/announcement_list /ticker_list
``` ```
List announcement with ID to you. List ticker with ID to you.
``` ```
/announcement_list_all /ticker_list_all
``` ```
Lists all announcements to you. Lists all ticker to you.
``` ```
/announcement_say announcement_id /ticker_say ticker_id
``` ```
Say the announcement with ID in main chat. Say the ticker with ID in main chat.
``` ```
/announcement_say_all /ticker_say_all
``` ```
Say all announcements in main chat. Say all tickers in main chat.
### Modmakers ### Modmakers
Use the following public functions to get, set, list and remove announcements Use the following public functions to get, set, list and remove ticker
``` ```
yl_announcements.get(announcement_id) yl_ticker.get(ticker_id)
``` ```
Returns a table with the values of this announcement_id. Returns `nil`, if it does not exist. Returns `false, "errormessage"` if an error occurred. Returns a table with the values of this ticker_id. Returns `nil`, if it does not exist. Returns `false, "errormessage"` if an error occurred.
``` ```
yl_announcements.set(message, frequency, runtime, owner) yl_ticker.set(message, frequency, runtime, owner)
``` ```
Adds this announcement to the list and returns `true, announcement_id` if accepted, `false, "errormessage"` if not. Adds this ticker to the list and returns `true, ticker_id` if accepted, `false, "errormessage"` if not.
``` ```
yl_announcements.formspec(announcement_id) yl_ticker.formspec(ticker_id)
``` ```
Returns `true, formspecstring` if an announcement was found, with formspecstring including the `/announcement_add` string, so it can be easily copied from. Returns `false, errormessage` if an error occurred. Returns `true, formspecstring` if a ticker was found, with formspecstring including the `/ticker_add` string, so it can be easily copied from. Returns `false, errormessage` if an error occurred.
``` ```
yl_announcements.delete(announcement_id) yl_ticker.delete(ticker_id)
``` ```
Returns `true, {announcement}` if one task was successfully removed, `false, "errormessage"` otherwise. Returns `true, {ticker}` if one ticker was successfully removed, `false, "errormessage"` otherwise.
``` ```
yl_announcements.list() yl_ticker.list()
``` ```
Returns `true, { id = {announcement}, ... }` if one or more announcements were found or `false, {}` if none were found. Returns `true, { id = {ticker}, ... }` if one or more ticker were found or `false, {}` if none were found.
``` ```
yl_announcements.say(announcement_id) yl_ticker.say(ticker_id)
``` ```
Returns `true, {announcement}` if one announcement was found or `false, {}` if none were found. Returns `true, {ticker}` if one ticker was found or `false, {}` if none were found.
## Limitations ## Limitations
@ -176,12 +176,12 @@ Returns `true, {announcement}` if one announcement was found or `false, {}` if n
## Alternatives ## Alternatives
* For immediate one-time announcements, use the notification mod * For immediate one-time ticker, use the notification mod
* For future one-time announcements, use the yl_scheduler mod * For future one-time ticker, use the yl_scheduler mod
## Supported versions ## Supported versions
If you run yl_announcements, but something is wrong, please [file a bug](https://gitea.your-land.de/your-land/yl_announcements/issues/new). PRs also welcome. If you run yl_ticker, but something is wrong, please [file a bug](https://gitea.your-land.de/your-land/yl_ticker/issues/new). PRs also welcome.
There is no reason to believe it doesn't work anywhere, but you never know. There is no reason to believe it doesn't work anywhere, but you never know.

124
api.lua
View File

@ -1,28 +1,28 @@
function yl_announcements.list() function yl_ticker.list()
if next(yl_announcements.data) ~= nil then if next(yl_ticker.data) ~= nil then
return true, yl_announcements.data return true, yl_ticker.data
end end
return false, {} return false, {}
end end
function yl_announcements.get(announcement_id) function yl_ticker.get(ticker_id)
-- Check announcement_id -- Check ticker_id
if (type(announcement_id) ~= "number") then if (type(ticker_id) ~= "number") then
return false, "Announcement ID is not a number" return false, "Ticker ID is not a number"
end end
if (announcement_id <= 0) then if (ticker_id <= 0) then
return false, "Announcement ID cannot be zero or negative" return false, "Ticker ID cannot be zero or negative"
end end
local success, data = yl_announcements.list() local success, data = yl_ticker.list()
if ((success == true) and (data[announcement_id] ~= nil)) then if ((success == true) and (data[ticker_id] ~= nil)) then
return true, table.copy(data[announcement_id]) return true, table.copy(data[ticker_id])
end end
return nil return nil
end end
function yl_announcements.set(message, frequency, runtime, owner) function yl_ticker.set(message, frequency, runtime, owner)
-- Check message -- Check message
if (type(message) ~= "string") then return false, "message not a string" end if (type(message) ~= "string") then return false, "message not a string" end
@ -44,7 +44,7 @@ function yl_announcements.set(message, frequency, runtime, owner)
if (owner == "") then return false, "Owner cannot be empty" end if (owner == "") then return false, "Owner cannot be empty" end
local index = 1 local index = 1
while yl_announcements.data[index] ~= nil do index = index + 1 end while yl_ticker.data[index] ~= nil do index = index + 1 end
local content = { local content = {
id = index, id = index,
@ -55,100 +55,100 @@ function yl_announcements.set(message, frequency, runtime, owner)
owner = owner owner = owner
} }
yl_announcements.data[index] = content yl_ticker.data[index] = content
local success = yl_announcements.save_json(tostring(index) .. ".json", local success = yl_ticker.save_json(tostring(index) .. ".json",
content) content)
if (success == true) then return true, index end if (success == true) then return true, index end
return false, "Could not store announcement" return false, "Could not store ticker"
end end
-- /announcement_add message$frequency in seconds$runtime in seconds -- /ticker_add message$frequency in seconds$runtime in seconds
function yl_announcements.formspec(announcement_id) function yl_ticker.formspec(ticker_id)
-- Check announcement_id -- Check ticker_id
if (type(announcement_id) ~= "number") then if (type(ticker_id) ~= "number") then
return false, "Announcement ID is not a number" return false, "Ticker ID is not a number"
end end
if (announcement_id <= 0) then if (ticker_id <= 0) then
return false, "Announcement ID cannot be zero or negative" return false, "Ticker ID cannot be zero or negative"
end end
local success, announcement = yl_announcements.get(announcement_id) local success, ticker = yl_ticker.get(ticker_id)
core.log("action", "announcement = " .. dump(announcement)) core.log("action", "ticker = " .. dump(ticker))
if ((success == false) or (announcement == nil)) then if ((success == false) or (ticker == nil)) then
return false, "No announcement" return false, "No ticker"
end end
local m = announcement.message or "message" local m = ticker.message or "message"
local f = announcement.frequency or "frequency" local f = ticker.frequency or "frequency"
local r = announcement.runtime or "runtime" local r = ticker.runtime or "runtime"
local c = "/announcement_add " .. m .. "$" .. f .. "$" .. r local c = "/ticker_add " .. m .. "$" .. f .. "$" .. r
local content = minetest.formspec_escape(c .. "\n\n" .. dump(announcement)) local content = minetest.formspec_escape(c .. "\n\n" .. dump(ticker))
local formspec = "formspec_version[6]" .. "size[16,4]" .. local formspec = "formspec_version[6]" .. "size[16,4]" ..
"button_exit[15.4,0.1;0.5,0.5;X;X]" .. "button_exit[15.4,0.1;0.5,0.5;X;X]" ..
"textarea[0.05,0.05;15.3,3.9;;;" .. content .. "]" "textarea[0.05,0.05;15.3,3.9;;;" .. content .. "]"
return true, formspec return true, formspec
end end
function yl_announcements.delete(announcement_id) function yl_ticker.delete(ticker_id)
-- Check announcement_id -- Check ticker_id
if (type(announcement_id) ~= "number") then if (type(ticker_id) ~= "number") then
return false, "Announcement ID is not a number" return false, "Ticker ID is not a number"
end end
if (announcement_id <= 0) then if (ticker_id <= 0) then
return false, "Announcement ID cannot be zero or negative" return false, "Ticker ID cannot be zero or negative"
end end
local success, data = yl_announcements.list() local success, data = yl_ticker.list()
if ((success == false) or (data == nil)) then if ((success == false) or (data == nil)) then
return false, "Could not retrieve list" return false, "Could not retrieve list"
end end
if ((success == true) and (data[announcement_id] == nil)) then if ((success == true) and (data[ticker_id] == nil)) then
return false, "Could not retrieve announcement" return false, "Could not retrieve ticker"
end end
local announcement = table.copy(data[announcement_id]) or local ticker = table.copy(data[ticker_id]) or
"No data available" "No data available"
if (announcement ~= nil) then if (ticker ~= nil) then
data[announcement_id] = nil data[ticker_id] = nil
local success_f, err = yl_announcements.remove_file(announcement_id .. local success_f, err = yl_ticker.remove_file(ticker_id ..
".json") ".json")
if (success_f == nil) then return false, err end if (success_f == nil) then return false, err end
success = true success = true
end end
if (success ~= true) then if (success ~= true) then
announcement = "Could not find announcement with id " .. ticker = "Could not find ticker with id " ..
dump(announcement_id) dump(ticker_id)
end end
return success, announcement return success, ticker
end end
function yl_announcements.say(announcement_id, target) function yl_ticker.say(ticker_id, target)
-- Check announcement_id -- Check ticker_id
if (type(announcement_id) ~= "number") then if (type(ticker_id) ~= "number") then
return false, "Announcement ID is not a number" return false, "Ticker ID is not a number"
end end
if (announcement_id <= 0) then if (ticker_id <= 0) then
return false, "Announcement ID cannot be zero or negative" return false, "Ticker ID cannot be zero or negative"
end end
-- No check for target, it is optional -- No check for target, it is optional
local success = false local success = false
local announcement = yl_announcements.data[announcement_id] local ticker = yl_ticker.data[ticker_id]
if (announcement ~= nil) then if (ticker ~= nil) then
local color = yl_announcements.settings.colour local color = yl_ticker.settings.colour
local message = announcement.message local message = ticker.message
local content = minetest.colorize(color, message) local content = minetest.colorize(color, message)
if ((target == "*") or (target == nil)) then if ((target == "*") or (target == nil)) then
@ -160,8 +160,8 @@ function yl_announcements.say(announcement_id, target)
end end
if (success ~= true) then if (success ~= true) then
announcement = "Could not find announcement with id " .. ticker = "Could not find ticker with id " ..
dump(announcement_id) dump(ticker_id)
end end
return success, announcement return success, ticker
end end

View File

@ -1,21 +1,21 @@
local chatcommand_cmd = "announcement_add" local chatcommand_cmd = "ticker_add"
local chatcommand_definition = { local chatcommand_definition = {
params = "<message>$<frequency in seconds>$<runtime in seconds>", params = "<message>$<frequency in seconds>$<runtime in seconds>",
description = "Sends the message each frequency seconds for a maximum number of runtime seconds." .. description = "Sends the message each frequency seconds for a maximum number of runtime seconds." ..
"\nExample: /announcement_add Runs every 50 seconds for one hour (= 3600 seconds)$50$3600", "\nExample: /ticker_add Runs every 50 seconds for one hour (= 3600 seconds)$50$3600",
privs = {[yl_announcements.settings.admin_privs] = true}, privs = {[yl_ticker.settings.admin_privs] = true},
func = function(name, param) func = function(name, param)
local success, message = yl_announcements.chatcommand_announcement_add( local success, message = yl_ticker.chatcommand_ticker_add(
name, param) name, param)
if success then if success then
minetest.log("action", "[yl_announcements] player " .. name .. minetest.log("action", "[yl_ticker] player " .. name ..
" added new announcement: " .. param) " added new ticker: " .. param)
return true, message return true, message
else else
minetest.log("warning", minetest.log("warning",
"[yl_announcements] player " .. name .. "[yl_ticker] player " .. name ..
" added new announcement: " .. param .. " added new ticker: " .. param ..
" unsuccessfully, message: " .. message) " unsuccessfully, message: " .. message)
return false, message return false, message
end end
@ -23,4 +23,4 @@ local chatcommand_definition = {
} }
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition) minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)
yl_announcements.register_help(chatcommand_cmd, chatcommand_definition) yl_ticker.register_help(chatcommand_cmd, chatcommand_definition)

View File

@ -1,21 +1,21 @@
local chatcommand_cmd = "announcement_copy" local chatcommand_cmd = "ticker_copy"
local chatcommand_definition = { local chatcommand_definition = {
params = "<announcement ID>", params = "<ticker ID>",
description = "Open the announcement with ID in a formspec, so it can be copied." .. description = "Open the ticker with ID in a formspec, so it can be copied." ..
"\nExample: /announcement_copy 5", "\nExample: /ticker_copy 5",
privs = {[yl_announcements.settings.user_privs] = true}, privs = {[yl_ticker.settings.user_privs] = true},
func = function(name, param) func = function(name, param)
local success, message = yl_announcements.chatcommand_announcement_copy( local success, message = yl_ticker.chatcommand_ticker_copy(
name, param) name, param)
if success then if success then
minetest.log("action", "[yl_announcements] player " .. name .. minetest.log("action", "[yl_ticker] player " .. name ..
" copied announcement: " .. param) " copied ticker: " .. param)
return true, message return true, message
else else
minetest.log("warning", minetest.log("warning",
"[yl_announcements] player " .. name .. "[yl_ticker] player " .. name ..
" copied announcement: " .. param .. " copied ticker: " .. param ..
" unsuccessfully, message: " .. message) " unsuccessfully, message: " .. message)
return false, message return false, message
end end
@ -23,4 +23,4 @@ local chatcommand_definition = {
} }
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition) minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)
yl_announcements.register_help(chatcommand_cmd, chatcommand_definition) yl_ticker.register_help(chatcommand_cmd, chatcommand_definition)

View File

@ -1,21 +1,21 @@
local chatcommand_cmd = "announcement_delete" local chatcommand_cmd = "ticker_delete"
local chatcommand_definition = { local chatcommand_definition = {
params = "<announcement ID>", params = "<ticker ID>",
description = "Delete the announcement ID." .. description = "Delete the ticker ID." ..
"\nExample: /announcement_delete 5", "\nExample: /ticker_delete 5",
privs = {[yl_announcements.settings.admin_privs] = true}, privs = {[yl_ticker.settings.admin_privs] = true},
func = function(name, param) func = function(name, param)
local success, message = local success, message =
yl_announcements.chatcommand_announcement_delete(name, param) yl_ticker.chatcommand_ticker_delete(name, param)
if success then if success then
minetest.log("action", "[yl_announcements] player " .. name .. minetest.log("action", "[yl_ticker] player " .. name ..
" deleted new announcement: " .. param) " deleted ticker: " .. param)
return true, message return true, message
else else
minetest.log("warning", minetest.log("warning",
"[yl_announcements] player " .. name .. "[yl_ticker] player " .. name ..
" deleted new announcement: " .. param .. " deleted ticker: " .. param ..
" unsuccessfully, message: " .. message) " unsuccessfully, message: " .. message)
return false, message return false, message
end end
@ -23,4 +23,4 @@ local chatcommand_definition = {
} }
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition) minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)
yl_announcements.register_help(chatcommand_cmd, chatcommand_definition) yl_ticker.register_help(chatcommand_cmd, chatcommand_definition)

View File

@ -1,22 +1,22 @@
local chatcommand_cmd = "announcement_help" local chatcommand_cmd = "ticker_help"
local chatcommand_definition = { local chatcommand_definition = {
params = "", params = "",
description = "Lists the command help for the announcements." .. description = "Lists the command help for the ticker." ..
"\nExample: /announcement_help", "\nExample: /ticker_help",
privs = {[yl_announcements.settings.user_privs] = true}, privs = {[yl_ticker.settings.user_privs] = true},
func = function(name, param) func = function(name, param)
local success, message = yl_announcements.chatcommand_announcement_help( local success, message = yl_ticker.chatcommand_ticker_help(
name, param) name, param)
if success then if success then
minetest.log("action", minetest.log("action",
"[yl_announcements] player " .. name .. "[yl_ticker] player " .. name ..
" displays help for announcements: " .. param) " displays help for ticker: " .. param)
return true, message return true, message
else else
minetest.log("warning", minetest.log("warning",
"[yl_announcements] player " .. name .. "[yl_ticker] player " .. name ..
" displays help for announcements: " .. param .. " displays help for ticker: " .. param ..
" unsuccessfully, message: " .. message) " unsuccessfully, message: " .. message)
return false, message return false, message
end end
@ -24,4 +24,4 @@ local chatcommand_definition = {
} }
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition) minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)
yl_announcements.register_help(chatcommand_cmd, chatcommand_definition) yl_ticker.register_help(chatcommand_cmd, chatcommand_definition)

View File

@ -1,21 +1,21 @@
local chatcommand_cmd = "announcement_list" local chatcommand_cmd = "ticker_list"
local chatcommand_definition = { local chatcommand_definition = {
params = "<announcement ID>", params = "<ticker ID>",
description = "List announcement with ID to you." .. description = "List tickers with ID to you." ..
"\nExample: /announcement_list 5", "\nExample: /ticker_list 5",
privs = {[yl_announcements.settings.user_privs] = true}, privs = {[yl_ticker.settings.user_privs] = true},
func = function(name, param) func = function(name, param)
local success, message = yl_announcements.chatcommand_announcement_list( local success, message = yl_ticker.chatcommand_ticker_list(
name, param) name, param)
if success then if success then
minetest.log("action", "[yl_announcements] player " .. name .. minetest.log("action", "[yl_ticker] player " .. name ..
" lists announcement: " .. param) " lists tickers: " .. param)
return true, message return true, message
else else
minetest.log("warning", minetest.log("warning",
"[yl_announcements] player " .. name .. "[yl_ticker] player " .. name ..
" lists announcement: " .. param .. " lists tickers: " .. param ..
" unsuccessfully, message: " .. message) " unsuccessfully, message: " .. message)
return false, message return false, message
end end
@ -23,4 +23,4 @@ local chatcommand_definition = {
} }
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition) minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)
yl_announcements.register_help(chatcommand_cmd, chatcommand_definition) yl_ticker.register_help(chatcommand_cmd, chatcommand_definition)

View File

@ -1,21 +1,21 @@
local chatcommand_cmd = "announcement_list_all" local chatcommand_cmd = "ticker_list_all"
local chatcommand_definition = { local chatcommand_definition = {
params = "", params = "",
description = "Lists all announcements to you." .. description = "Lists all tickers to you." ..
"\nExample: /announcement_list_all", "\nExample: /ticker_list_all",
privs = {[yl_announcements.settings.user_privs] = true}, privs = {[yl_ticker.settings.user_privs] = true},
func = function(name, param) func = function(name, param)
local success, message = local success, message =
yl_announcements.chatcommand_announcement_list_all(name, param) yl_ticker.chatcommand_ticker_list_all(name, param)
if success then if success then
minetest.log("action", "[yl_announcements] player " .. name .. minetest.log("action", "[yl_ticker] player " .. name ..
" lists all announcements: " .. param) " lists all tickers: " .. param)
return true, message return true, message
else else
minetest.log("warning", minetest.log("warning",
"[yl_announcements] player " .. name .. "[yl_ticker] player " .. name ..
" lists all announcements: " .. param .. " lists all tickers: " .. param ..
" unsuccessfully, message: " .. dump(message)) " unsuccessfully, message: " .. dump(message))
return false, dump(message) return false, dump(message)
end end
@ -23,4 +23,4 @@ local chatcommand_definition = {
} }
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition) minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)
yl_announcements.register_help(chatcommand_cmd, chatcommand_definition) yl_ticker.register_help(chatcommand_cmd, chatcommand_definition)

View File

@ -1,21 +1,21 @@
local chatcommand_cmd = "announcement_say" local chatcommand_cmd = "ticker_say"
local chatcommand_definition = { local chatcommand_definition = {
params = "<announcement ID>", params = "<ticker ID>",
description = "Say the announcement with ID in main chat." .. description = "Say the ticker with ID in main chat." ..
"\nExample: /announcement_say 5", "\nExample: /ticker_say 5",
privs = {[yl_announcements.settings.admin_privs] = true}, privs = {[yl_ticker.settings.admin_privs] = true},
func = function(name, param) func = function(name, param)
local success, message = yl_announcements.chatcommand_announcement_say( local success, message = yl_ticker.chatcommand_ticker_say(
name, param) name, param)
if success then if success then
minetest.log("action", "[yl_announcements] player " .. name .. minetest.log("action", "[yl_ticker] player " .. name ..
" sent announcement: " .. param) " sent ticker: " .. param)
return true, message return true, message
else else
minetest.log("warning", minetest.log("warning",
"[yl_announcements] player " .. name .. "[yl_ticker] player " .. name ..
" sent announcement: " .. param .. " sent ticker: " .. param ..
" unsuccessfully, message: " .. message) " unsuccessfully, message: " .. message)
return false, message return false, message
end end
@ -23,4 +23,4 @@ local chatcommand_definition = {
} }
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition) minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)
yl_announcements.register_help(chatcommand_cmd, chatcommand_definition) yl_ticker.register_help(chatcommand_cmd, chatcommand_definition)

View File

@ -1,21 +1,21 @@
local chatcommand_cmd = "announcement_say_all" local chatcommand_cmd = "ticker_say_all"
local chatcommand_definition = { local chatcommand_definition = {
params = "", params = "",
description = "Say all announcements in main chat." .. description = "Say all tickers in main chat." ..
"\nExample: /announcement_say_all", "\nExample: /ticker_say_all",
privs = {[yl_announcements.settings.admin_privs] = true}, privs = {[yl_ticker.settings.admin_privs] = true},
func = function(name, param) func = function(name, param)
local success, message = local success, message =
yl_announcements.chatcommand_announcement_say_all(name, param) yl_ticker.chatcommand_ticker_say_all(name, param)
if success then if success then
minetest.log("action", "[yl_announcements] player " .. name .. minetest.log("action", "[yl_ticker] player " .. name ..
" sent all announcements: " .. param) " sent all tickers: " .. param)
return true, message return true, message
else else
minetest.log("warning", minetest.log("warning",
"[yl_announcements] player " .. name .. "[yl_ticker] player " .. name ..
" sent all announcements: " .. param .. " sent all tickers: " .. param ..
" unsuccessfully, message: " .. message) " unsuccessfully, message: " .. message)
return false, message return false, message
end end
@ -23,4 +23,4 @@ local chatcommand_definition = {
} }
minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition) minetest.register_chatcommand(chatcommand_cmd, chatcommand_definition)
yl_announcements.register_help(chatcommand_cmd, chatcommand_definition) yl_ticker.register_help(chatcommand_cmd, chatcommand_definition)

View File

@ -1,8 +1,8 @@
dofile(yl_announcements.modpath .. DIR_DELIM .. "chatcommand_list.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "chatcommand_list.lua")
dofile(yl_announcements.modpath .. DIR_DELIM .. "chatcommand_list_all.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "chatcommand_list_all.lua")
dofile(yl_announcements.modpath .. DIR_DELIM .. "chatcommand_add.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "chatcommand_add.lua")
dofile(yl_announcements.modpath .. DIR_DELIM .. "chatcommand_delete.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "chatcommand_delete.lua")
dofile(yl_announcements.modpath .. DIR_DELIM .. "chatcommand_say.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "chatcommand_say.lua")
dofile(yl_announcements.modpath .. DIR_DELIM .. "chatcommand_say_all.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "chatcommand_say_all.lua")
dofile(yl_announcements.modpath .. DIR_DELIM .. "chatcommand_copy.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "chatcommand_copy.lua")
dofile(yl_announcements.modpath .. DIR_DELIM .. "chatcommand_help.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "chatcommand_help.lua")

View File

@ -1,16 +1,16 @@
-- Setting a configuration, switch the order in which the settings shall take precedence. First valid one taken. -- Setting a configuration, switch the order in which the settings shall take precedence. First valid one taken.
yl_announcements.settings = {} yl_ticker.settings = {}
yl_announcements.settings.debug = minetest.settings:get("yl_announcements.debug") or false yl_ticker.settings.debug = minetest.settings:get("yl_ticker.debug") or false
yl_announcements.settings.save_path = minetest.settings:get("yl_announcements.save_path") or "yl_announcements" yl_ticker.settings.save_path = minetest.settings:get("yl_ticker.save_path") or "yl_ticker"
yl_announcements.settings.colour = minetest.settings:get("yl_announcements.colour") or "#7676ff" yl_ticker.settings.colour = minetest.settings:get("yl_ticker.colour") or "#7676ff"
yl_announcements.settings.frequency = minetest.settings:get("yl_announcements.frequency") or 3600 yl_ticker.settings.frequency = minetest.settings:get("yl_ticker.frequency") or 3600
yl_announcements.settings.user_privs = minetest.settings:get("yl_announcements.user_privs") or "interact" yl_ticker.settings.user_privs = minetest.settings:get("yl_ticker.user_privs") or "interact"
yl_announcements.settings.admin_privs = minetest.settings:get("yl_announcements.admin_privs") or "server" yl_ticker.settings.admin_privs = minetest.settings:get("yl_ticker.admin_privs") or "server"

View File

@ -2,46 +2,46 @@ local function calculate_bucket(bucket, data) -- This is per bucket
if type(bucket) ~= "number" then bucket = tonumber(bucket) end if type(bucket) ~= "number" then bucket = tonumber(bucket) end
local affected_announcements = {} local affected_tickers = {}
for _, announcement in ipairs(data) do for _, ticker in ipairs(data) do
if announcement.frequency == bucket then if ticker.frequency == bucket then
table.insert(affected_announcements, announcement) table.insert(affected_tickers, ticker)
end end
end end
-- Prevent division by 0 -- Prevent division by 0
if (#affected_announcements == 0) then if (#affected_tickers == 0) then
-- We should never reach this code. If there are members of the bucket, -- We should never reach this code. If there are members of the bucket,
-- then there must be affected announcements. -- then there must be affected ticker.
minetest.log("error", minetest.log("error",
"[yl_announcements] globalstep division by zero, no members of bucket = " .. "[yl_ticker] globalstep division by zero, no members of bucket = " ..
dump(bucket)) dump(bucket))
return return
end end
-- Let's calculate the distance -- Let's calculate the distance
local distance = bucket / #affected_announcements local distance = bucket / #affected_tickers
local n = 0 local n = 0
for _, announcement in ipairs(affected_announcements) do for _, ticker in ipairs(affected_tickers) do
announcement._next_runtime = os.time() + n * distance ticker._next_runtime = os.time() + n * distance
n = n + 1 n = n + 1
end end
end end
local tick = 1 local delta = 1
local timer = 0 local timer = 0
local gs = function(dtime) local gs = function(dtime)
timer = timer + dtime timer = timer + dtime
if timer <= tick then return end if timer <= delta then return end
timer = timer - tick timer = timer - delta
-- payload -- payload
local success, data = yl_announcements.list() local success, data = yl_ticker.list()
if ((success == false) or (data == nil)) then if ((success == false) or (data == nil)) then
return false, "Could not retrieve list" return false, "Could not retrieve list"
end end
@ -49,37 +49,37 @@ local gs = function(dtime)
local current_time = os.time() local current_time = os.time()
local affected_bucket = {} local affected_bucket = {}
-- Check if any announcement should be displayed -- Check if any ticker should be displayed
for _, announcement in pairs(data) do for _, ticker in pairs(data) do
-- Check if any announcement needs to be removed from the list due to runtime expired. -- Check if any ticker needs to be removed from the list due to runtime expired.
if ((type(announcement.runtime) == "number") and if ((type(ticker.runtime) == "number") and
(current_time >= (announcement.creation_date + announcement.runtime))) then (current_time >= (ticker.creation_date + ticker.runtime))) then
yl_announcements.delete(announcement.id) yl_ticker.delete(ticker.id)
elseif current_time >= (announcement._next_runtime or 0) then elseif current_time >= (ticker._next_runtime or 0) then
if (type(announcement._next_runtime) ~= "number") then if (type(ticker._next_runtime) ~= "number") then
table.insert(affected_bucket, announcement.frequency) table.insert(affected_bucket, ticker.frequency)
else else
local a_success, message = local a_success, message =
yl_announcements.say(announcement.id, "*") yl_ticker.say(ticker.id, "*")
if (a_success == false) then if (a_success == false) then
minetest.log("error", minetest.log("error",
"[yl_announcements] globalstep cannot send to target, message = " .. "[yl_ticker] globalstep cannot send to target, message = " ..
dump(message) .. " : announcement = " .. dump(message) .. " : ticker = " ..
dump(announcement)) dump(ticker))
return return
end end
announcement._next_runtime = ticker._next_runtime =
announcement._next_runtime + ticker._next_runtime +
(announcement.frequency or 3600) (ticker.frequency or 3600)
end end
yl_announcements.log(os.date("!%H:%M:%S", os.time()) .. "=" .. yl_ticker.log(os.date("!%H:%M:%S", os.time()) .. "=" ..
tostring(announcement.id)) tostring(ticker.id))
end end
end end
-- If there were any announcements that had no _next_runtime, then we need to recalculate their bucket -- If there were any tickers that had no _next_runtime, then we need to recalculate their bucket
for _, bucket in ipairs(affected_bucket) do for _, bucket in ipairs(affected_bucket) do
calculate_bucket(bucket, data) calculate_bucket(bucket, data)
end end

View File

@ -3,29 +3,29 @@
-- License MIT -- License MIT
-- Changelog -- Changelog
local mod_start_time = core.get_us_time() local mod_start_time = core.get_us_time()
core.log("action", "[MOD] yl_announcements loading") core.log("action", "[MOD] yl_ticker loading")
yl_announcements = {} yl_ticker = {}
yl_announcements.error = {} yl_ticker.error = {}
-- yl_announcements.modstorage = core.get_mod_storage() -- yl_ticker.modstorage = core.get_mod_storage()
yl_announcements.modpath = core.get_modpath("yl_announcements") yl_ticker.modpath = core.get_modpath("yl_ticker")
yl_announcements.worldpath = core.get_worldpath() yl_ticker.worldpath = core.get_worldpath()
yl_announcements.information = {} yl_ticker.information = {}
yl_announcements.information.version = "0.0.1" yl_ticker.information.version = "0.0.1"
yl_announcements.information.author = "AliasAlreadyTaken" yl_ticker.information.author = "AliasAlreadyTaken"
yl_announcements.information.license = "MIT" yl_ticker.information.license = "MIT"
yl_announcements.information.name = "yl_announcements" yl_ticker.information.name = "yl_ticker"
yl_announcements.information.source = "https://gitea.your-land.de/your-land/yl_announcements" yl_ticker.information.source = "https://gitea.your-land.de/your-land/yl_ticker"
yl_announcements.information.additional = "Displays messages once per timeframe" yl_ticker.information.additional = "Displays messages once per timeframe"
dofile(yl_announcements.modpath .. DIR_DELIM .. "config.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "config.lua")
dofile(yl_announcements.modpath .. DIR_DELIM .. "setup.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "setup.lua")
dofile(yl_announcements.modpath .. DIR_DELIM .. "internal.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "internal.lua")
dofile(yl_announcements.modpath .. DIR_DELIM .. "api.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "api.lua")
dofile(yl_announcements.modpath .. DIR_DELIM .. "initialize.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "initialize.lua")
dofile(yl_announcements.modpath .. DIR_DELIM .. "globalsteps.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "globalsteps.lua")
dofile(yl_announcements.modpath .. DIR_DELIM .. "chatcommands.lua") dofile(yl_ticker.modpath .. DIR_DELIM .. "chatcommands.lua")
local mod_end_time = (core.get_us_time() - mod_start_time) / 1000000 local mod_end_time = (core.get_us_time() - mod_start_time) / 1000000
core.log("action", "[MOD] yl_announcements loaded in [" .. mod_end_time .. "s]") core.log("action", "[MOD] yl_ticker loaded in [" .. mod_end_time .. "s]")

View File

@ -1,7 +1,7 @@
local function run_each_serverstart() local function run_each_serverstart()
yl_announcements.data = {} yl_ticker.data = {}
minetest.after(0.0, yl_announcements.load_all_data) minetest.after(0.0, yl_ticker.load_all_data)
minetest.after(0.0, yl_announcements.check_privs) minetest.after(0.0, yl_ticker.check_privs)
end end
run_each_serverstart() run_each_serverstart()

View File

@ -1,18 +1,18 @@
-- The functions and variables in this file are only for use in the mod itself. -- The functions and variables in this file are only for use in the mod itself.
-- Those that do real work should be local and wrapped in public functions -- Those that do real work should be local and wrapped in public functions
local debug = yl_announcements.settings.debug or true local debug = yl_ticker.settings.debug or true
local function log(text) local function log(text)
if debug then minetest.log("action", "[MOD] yl_announcements : " .. text) end if debug then minetest.log("action", "[MOD] yl_ticker : " .. text) end
end end
function yl_announcements.log(text) return log(text) end function yl_ticker.log(text) return log(text) end
-- Storage -- Storage
local function get_savepath() local function get_savepath()
local save_path = yl_announcements.settings.save_path local save_path = yl_ticker.settings.save_path
local path = yl_announcements.worldpath .. DIR_DELIM .. save_path local path = yl_ticker.worldpath .. DIR_DELIM .. save_path
log("get_savepath : " .. dump(path)) log("get_savepath : " .. dump(path))
return path return path
end end
@ -46,11 +46,11 @@ local function load_json(path_to_file)
end end
-- Public functions wrap the private ones, so they can be exchanged easily -- Public functions wrap the private ones, so they can be exchanged easily
function yl_announcements.load_json(filename, ...) function yl_ticker.load_json(filename, ...)
return load_json(filename, ...) return load_json(filename, ...)
end end
function yl_announcements.save_json(filename, content, ...) function yl_ticker.save_json(filename, content, ...)
return save_json(filename, content, ...) return save_json(filename, content, ...)
end end
@ -120,24 +120,24 @@ local function load_all_data()
end end
end end
yl_announcements.data = data yl_ticker.data = data
if bad == 0 then if bad == 0 then
minetest.log("action", minetest.log("action",
"[MOD] yl_announcements : bad = " .. tostring(bad) .. "[MOD] yl_ticker : bad = " .. tostring(bad) ..
", good = " .. tostring(good) .. ", total = " .. ", good = " .. tostring(good) .. ", total = " ..
tostring(total)) tostring(total))
return true, good, bad return true, good, bad
else else
minetest.log("warning", minetest.log("warning",
"[MOD] yl_announcements : bad = " .. tostring(bad) .. "[MOD] yl_ticker : bad = " .. tostring(bad) ..
", good = " .. tostring(good) .. ", total = " .. ", good = " .. tostring(good) .. ", total = " ..
tostring(total)) tostring(total))
return false, good, bad return false, good, bad
end end
end end
function yl_announcements.load_all_data() return load_all_data() end function yl_ticker.load_all_data() return load_all_data() end
-- check privs -- check privs
-- --
@ -155,12 +155,12 @@ local function priv_exists(priv)
end end
local function check_privs() local function check_privs()
for key, value in pairs(yl_announcements.settings) do for key, value in pairs(yl_ticker.settings) do
if ends_with(key, "_privs") then if ends_with(key, "_privs") then
local parts = split(value) local parts = split(value)
for _, part in ipairs(parts) do for _, part in ipairs(parts) do
assert(priv_exists(part), assert(priv_exists(part),
"yl_announcements : configured priv " .. dump(part) .. "yl_ticker : configured priv " .. dump(part) ..
" does not exist.") " does not exist.")
end end
end end
@ -168,7 +168,7 @@ local function check_privs()
log("PASS priv check") log("PASS priv check")
end end
function yl_announcements.check_privs() return check_privs() end function yl_ticker.check_privs() return check_privs() end
-- Remove file -- Remove file
-- --
@ -178,7 +178,7 @@ local function remove_file(filename)
return os.remove(filepath) return os.remove(filepath)
end end
function yl_announcements.remove_file(filename) return remove_file(filename) end function yl_ticker.remove_file(filename) return remove_file(filename) end
-- Help -- Help
-- --
@ -195,7 +195,7 @@ local function register_help(chatcommand_cmd, chatcommand_definition)
help_texts[chatcommand_cmd] = definition help_texts[chatcommand_cmd] = definition
end end
function yl_announcements.register_help(chatcommand_cmd, chatcommand_definition) function yl_ticker.register_help(chatcommand_cmd, chatcommand_definition)
return register_help(chatcommand_cmd, chatcommand_definition) return register_help(chatcommand_cmd, chatcommand_definition)
end end
@ -240,12 +240,12 @@ local function display_help()
return true, s_message return true, s_message
end end
function yl_announcements.display_help() return display_help() end function yl_ticker.display_help() return display_help() end
-- Chatcommands -- Chatcommands
-- --
function yl_announcements.chatcommand_announcement_add(name, param) -- param is a string containing a message and more function yl_ticker.chatcommand_ticker_add(name, param) -- param is a string containing a message and more
-- defense -- defense
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
@ -253,67 +253,67 @@ function yl_announcements.chatcommand_announcement_add(name, param) -- param is
if (not param) or (type(param) ~= "string") or (param == "") then if (not param) or (type(param) ~= "string") or (param == "") then
return false, "Requirements not met" return false, "Requirements not met"
end end
-- Create announcement -- Create ticker
local announcement = string.split(param, "$", true) local ticker = string.split(param, "$", true)
local message = announcement[1] or "" local message = ticker[1] or ""
local frequency = tonumber(announcement[2]) or local frequency = tonumber(ticker[2]) or
yl_announcements.settings.frequency or 3600 yl_ticker.settings.frequency or 3600
local runtime = tonumber(announcement[3]) or 7257600 -- 12 weeks local runtime = tonumber(ticker[3]) or 7257600 -- 12 weeks
local owner = name local owner = name
local success, announcement_id = yl_announcements.set(message, frequency, local success, ticker_id = yl_ticker.set(message, frequency,
runtime, owner) runtime, owner)
return success, "Announcement ID " .. tostring(announcement_id) return success, "Ticker ID " .. tostring(ticker_id)
end end
function yl_announcements.chatcommand_announcement_copy(name, param) -- param is a numerical a_id function yl_ticker.chatcommand_ticker_copy(name, param) -- param is a numerical a_id
-- defense -- defense
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
if not player then return false, "Player not online" end if not player then return false, "Player not online" end
if param == "" then return false, "Announcement ID missing" end if param == "" then return false, "Ticker ID missing" end
local announcement_id = tonumber(param) local ticker_id = tonumber(param)
if type(announcement_id) ~= "number" then if type(ticker_id) ~= "number" then
return false, "Announcement ID is not a number" return false, "Ticker ID is not a number"
end end
if (announcement_id <= 0) then if (ticker_id <= 0) then
return false, "Announcement ID cannot be zero or negative" return false, "Ticker ID cannot be zero or negative"
end end
local success, formspecstring = yl_announcements.formspec(announcement_id) local success, formspecstring = yl_ticker.formspec(ticker_id)
if (success == false) then return false, formspecstring end if (success == false) then return false, formspecstring end
-- Send the formspec -- Send the formspec
minetest.show_formspec(name, "yl_announcements:copy", formspecstring) minetest.show_formspec(name, "yl_ticker:copy", formspecstring)
-- Report -- Report
return true, "Copied announcement ID " .. tostring(announcement_id) return true, "Copied ticker ID " .. tostring(ticker_id)
end end
function yl_announcements.chatcommand_announcement_delete(name, param) -- param is a numerical a_id function yl_ticker.chatcommand_ticker_delete(name, param) -- param is a numerical a_id
-- defense -- defense
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
if not player then return false, "Player not online" end if not player then return false, "Player not online" end
if param == "" then return false, "Announcement ID missing" end if param == "" then return false, "Ticker ID missing" end
local announcement_id = tonumber(param) local ticker_id = tonumber(param)
if type(announcement_id) ~= "number" then if type(ticker_id) ~= "number" then
return false, "Announcement ID not a number" return false, "Ticker ID not a number"
end end
local success, announcement = yl_announcements.delete(announcement_id) local success, ticker = yl_ticker.delete(ticker_id)
if success == false then if success == false then
return false, announcement return false, ticker
else else
return true, "Deleted announcement ID " .. tostring(announcement_id) return true, "Deleted ticker ID " .. tostring(ticker_id)
end end
end end
-- List announcements -- List ticker
-- taken from yl_cinema -- taken from yl_cinema
-- TODO: Shoudl we API-fy this? -- TODO: Should we API-fy this?
local function format_table(t) local function format_table(t)
-- Format of t must be {{row1,row2,row3, ...},{row1,row2,row3, ...},...} -- Format of t must be {{row1,row2,row3, ...},{row1,row2,row3, ...},...}
@ -347,112 +347,112 @@ local function format_table(t)
return table.concat(ret, "\n") return table.concat(ret, "\n")
end end
function yl_announcements.chatcommand_announcement_list_all(name, param) -- param must be empty function yl_ticker.chatcommand_ticker_list_all(name, param) -- param must be empty
-- defense -- defense
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
if not player then return false, "Player not online" end if not player then return false, "Player not online" end
if param ~= "" then if param ~= "" then
return false, "This command lists all announcements. " .. return false, "This command lists all tickers. " ..
"Do /announcement_list <announcement_id> if you want to have only one." "Do /ticker_list <ticker_id> if you want to have only one."
end end
local success, data = yl_announcements.list() local success, data = yl_ticker.list()
if (success == false) then return false, data end if (success == false) then return false, data end
local f_announcements = { local f_ticker = {
{"ID", "message", "created", "owner", "runtime", "frequency"} {"ID", "message", "created", "owner", "runtime", "frequency"}
} }
for _, announcement in pairs(data) do for _, ticker in pairs(data) do
local id = tostring(announcement.id) or "N/A" local id = tostring(ticker.id) or "N/A"
local message = announcement.message or "N/A" local message = ticker.message or "N/A"
local created = os.date("!%Y-%m-%d %H:%M:%S", local created = os.date("!%Y-%m-%d %H:%M:%S",
(announcement.creation_date or 0)) or "N/A" (ticker.creation_date or 0)) or "N/A"
local owner = announcement.owner or "N/A" local owner = ticker.owner or "N/A"
local runtime = tostring(announcement.runtime) or "N/A" local runtime = tostring(ticker.runtime) or "N/A"
local frequency = tostring(announcement.frequency) or "N/A" local frequency = tostring(ticker.frequency) or "N/A"
local t = {id, message, created, owner, runtime, frequency} local t = {id, message, created, owner, runtime, frequency}
table.insert(f_announcements, t) table.insert(f_ticker, t)
end end
return true, format_table(f_announcements) return true, format_table(f_ticker)
end end
function yl_announcements.chatcommand_announcement_list(name, param) -- param is a numerical a_id function yl_ticker.chatcommand_ticker_list(name, param) -- param is a numerical a_id
-- defense -- defense
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
if not player then return false, "Player not online" end if not player then return false, "Player not online" end
if param == "" then return false, "Announcement ID missing" end if param == "" then return false, "Ticker ID missing" end
local announcement_id = tonumber(param) local ticker_id = tonumber(param)
if type(announcement_id) ~= "number" then if type(ticker_id) ~= "number" then
return false, "Announcement ID not a number" return false, "Ticker ID not a number"
end end
local success, announcement = yl_announcements.get(announcement_id) local success, ticker = yl_ticker.get(ticker_id)
if ((success == false) or (success == nil)) then if ((success == false) or (success == nil)) then
return false, "Announcement not found" return false, "Ticker not found"
end end
return true, dump(announcement) return true, dump(ticker)
end end
function yl_announcements.chatcommand_announcement_say_all(name, param) -- param must be empty function yl_ticker.chatcommand_ticker_say_all(name, param) -- param must be empty
-- defense -- defense
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
if not player then return false, "Player not online" end if not player then return false, "Player not online" end
if param ~= "" then if param ~= "" then
return false, return false,
"This command sends all announcements to the main chat. " .. "This command sends all ticker to the main chat. " ..
"Do /announcement_say <announcement_id> if you want to send only one." "Do /ticker_say <ticker_id> if you want to send only one."
end end
local success, data = yl_announcements.list() local success, data = yl_ticker.list()
if (success == false) then return false, "No data" end if (success == false) then return false, "No data" end
local n = 0 local n = 0
for _, announcement in pairs(data) do for _, ticker in pairs(data) do
local s_success, s_message = yl_announcements.say(announcement.id, "*") local s_success, s_message = yl_ticker.say(ticker.id, "*")
if (s_success == false) then return false, s_message end if (s_success == false) then return false, s_message end
n = n + 1 n = n + 1
end end
return true, "Sent " .. tostring(n) .. " announcements to public." return true, "Sent " .. tostring(n) .. " ticker to public."
end end
function yl_announcements.chatcommand_announcement_say(name, param) -- param is a numerical a_id function yl_ticker.chatcommand_ticker_say(name, param) -- param is a numerical a_id
-- defense -- defense
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
if not player then return false, "Player not online" end if not player then return false, "Player not online" end
if param == "" then return false, "Announcement ID missing" end if param == "" then return false, "Ticker ID missing" end
local announcement_id = tonumber(param) local ticker_id = tonumber(param)
if type(announcement_id) ~= "number" then if type(ticker_id) ~= "number" then
return false, "Announcement ID not a number" return false, "Ticker ID not a number"
end end
local s_success, s_message = yl_announcements.say(announcement_id, "*") local s_success, s_message = yl_ticker.say(ticker_id, "*")
if (s_success == false) then return false, s_message end if (s_success == false) then return false, s_message end
return true, return true,
"Sent announcement " .. tostring(announcement_id) .. " to public." "Sent ticker " .. tostring(ticker_id) .. " to public."
end end
function yl_announcements.chatcommand_announcement_help(name, param) -- param must be empty function yl_ticker.chatcommand_ticker_help(name, param) -- param must be empty
-- defense -- defense
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
if not player then return false, "Player not online" end if not player then return false, "Player not online" end
if param ~= "" then if param ~= "" then
return false, return false,
"This command displays the help for the announcements. " .. "This command displays the help for the ticker. " ..
"Do /announcement_help without parameters." "Do /ticker_help without parameters."
end end
local success, message = yl_announcements.display_help() local success, message = yl_ticker.display_help()
if (success == false) then return false, message end if (success == false) then return false, message end

View File

@ -1,4 +1,4 @@
name = yl_announcements name = yl_ticker
description = Displays messages once per timeframe description = Displays messages once per timeframe
author = AliasAlreadyTaken author = AliasAlreadyTaken
title = YL Announcements title = YL Ticker

View File

@ -1,31 +1,31 @@
[yl_announcements] [yl_ticker]
# Debug mode # Debug mode
# Set this to true to enable debug mode, it will output some more values to log # Set this to true to enable debug mode, it will output some more values to log
# Optional, default is false # Optional, default is false
yl_announcements.debug (Debug mode) bool false yl_ticker.debug (Debug mode) bool false
# Save path # Save path
# Set this to where in the worldfolder you want the JSON files stored. # Set this to where in the worldfolder you want the JSON files stored.
# Optional, default is yl_announcements # Optional, default is yl_ticker
yl_announcements.save_path (Save path) string yl_announcements yl_ticker.save_path (Save path) string yl_ticker
# Colour # Colour
# Set this to the colour you want the announcements have in chat # Set this to the colour you want the ticker have in chat
# Optional, default is "#7676ff" ("cornflower blue") # Optional, default is "#7676ff" ("cornflower blue")
yl_announcements.colour (Colour) string #7676ff yl_ticker.colour (Colour) string #7676ff
# Frequency # Frequency
# Set this to the default repeat timer you want the announcements have in chat # Set this to the default repeat timer you want the ticker have in chat
# Optional, default is 3600 seconds (means: once per hour) # Optional, default is 3600 seconds (means: once per hour)
yl_announcements.frequency (Frequency) float 3600.0 1.0 yl_ticker.frequency (Frequency) float 3600.0 1.0
# User privs # User privs
# Enable holders of these privs to list and copy announcements # Enable holders of these privs to list and copy ticker
# Optional, default: interact # Optional, default: interact
yl_announcements.user_privs (User privs) string interact yl_ticker.user_privs (User privs) string interact
# Admin Privs # Admin Privs
# Enable holders of these privs to use all commands # Enable holders of these privs to use all commands
# Optional, default: server # Optional, default: server
yl_announcements.admin_privs (Admin Privs) string server yl_ticker.admin_privs (Admin Privs) string server

View File

@ -1,6 +1,6 @@
local mkdir = minetest.mkdir local mkdir = minetest.mkdir
local save_path = yl_announcements.settings.save_path local save_path = yl_ticker.settings.save_path
local path = yl_announcements.worldpath .. DIR_DELIM .. save_path local path = yl_ticker.worldpath .. DIR_DELIM .. save_path
local function run_once() local function run_once()
local file = io.open(path, "r") local file = io.open(path, "r")