Compare commits

16 Commits

Author SHA1 Message Date
5682172106 Merge pull request #8 from sys4-fr/master
Mod refresh and remove intllib support to Minetest translator
2022-06-26 13:08:26 +08:00
0895cf7ce4 Mod refresh and remove intllib support to Minetest translator
- Remove depends.txt
- Update mod.conf
- Add settingtypes.txt for interval between two subsequent messages
2022-06-25 21:22:38 +02:00
bb61f68038 Merge pull request #7 from zeuner/bugfix1
api compatibility
2019-01-10 19:59:32 -05:00
48c2553798 Merge pull request #6 from zeuner/bugfix2
Bugfixes related to messages file
2019-01-09 09:26:05 -05:00
e4c5ba1c85 Merge pull request #5 from zeuner/integration
add mod.conf
2019-01-08 21:34:46 -05:00
7db0c9c50b avoid crash on missing messages file 2017-10-06 03:14:45 +02:00
17d2fd9f75 avoid error on closing null file handle 2017-10-06 02:56:20 +02:00
24974e109b api compatibility 2017-10-06 02:36:51 +02:00
e9e5bb7bef add mod.conf 2017-09-29 21:53:57 +02:00
365ffd23ad Merge pull request #4 from fat115/master
add intllib support (i18n)
2017-08-11 16:27:55 +08:00
1c507021bf add intllib support (i18n)
add french translation
2017-08-04 15:07:28 +02:00
55e197dc6e Merge pull request #3 from tacotexmex/patch-1
Replace deprecated settings method
2017-07-06 12:42:10 +08:00
12f23d449e Merge pull request #2 from xisd/patch-1
Support for a default messages file
2017-07-06 12:40:55 +08:00
31e1cd5d27 Replace deprecated settings method 2017-06-18 21:05:25 +02:00
1b7ea87932 Support for a default messages file
Hi !
I use your mod on a local server, it's great for displaying tips and news !
But since I'm too lazy to copy-paste the random_messages file from one world to an other, I made this change so if the random_messages file is not in the world folder, it look for a template in the mod folder before the 'blame the admin' last resort.
Anyway I thought it could be useful for others
2016-10-04 01:43:32 +02:00
b6b076a5a3 Merge pull request #1 from rubenwardy/master
Fix messages not showing, remove default from depends
2016-03-26 12:02:56 +08:00
5 changed files with 66 additions and 20 deletions

View File

@ -5,12 +5,27 @@ arsdragonfly@gmail.com
--]] --]]
--Time between two subsequent messages. --Time between two subsequent messages.
local MESSAGE_INTERVAL = 0 local MESSAGE_INTERVAL = 0
-- Added default messages file
local default_messages_file = "default_random_messages"
math.randomseed(os.time()) math.randomseed(os.time())
random_messages = {} random_messages = {}
random_messages.messages = {} --This table contains all messages. random_messages.messages = {} --This table contains all messages.
local S
if minetest.get_translator ~= nil then
S = minetest.get_translator("random_messages")
else
S = function(str, ...)
local args={...}
return str:gsub(
"@%d+",
function(match) return args[tonumber(match:sub(2))] end
)
end
end
function table.count( t ) function table.count( t )
local i = 0 local i = 0
for k in pairs( t ) do i = i + 1 end for k in pairs( t ) do i = i + 1 end
@ -26,14 +41,8 @@ function table.random( t )
end end
end end
function random_messages.initialize() --Set the interval in minetest.conf.
minetest.setting_set("random_messages_interval",120)
minetest.setting_save();
return 120
end
function random_messages.set_interval() --Read the interval from minetest.conf(set it if it doesn'st exist) function random_messages.set_interval() --Read the interval from minetest.conf(set it if it doesn'st exist)
MESSAGE_INTERVAL = tonumber(minetest.setting_get("random_messages_interval")) or random_messages.initialize() MESSAGE_INTERVAL = tonumber(minetest.settings:get("random_messages_interval") or 120)
end end
function random_messages.check_params(name,func,params) function random_messages.check_params(name,func,params)
@ -47,14 +56,28 @@ end
function random_messages.read_messages() function random_messages.read_messages()
local line_number = 1 local line_number = 1
-- define input
local input = io.open(minetest.get_worldpath().."/random_messages","r") local input = io.open(minetest.get_worldpath().."/random_messages","r")
-- no input file found
if not input then if not input then
-- look for default file
local default_input = io.open(minetest.get_modpath("random_messages").."/"..default_messages_file,"r")
local output = io.open(minetest.get_worldpath().."/random_messages","w") local output = io.open(minetest.get_worldpath().."/random_messages","w")
output:write("Blame the server admin! He/She has probably not edited the random messages yet.\n") if not default_input then
output:write("Tell your dumb admin that this line is in (worldpath)/random_messages \n") -- blame the admin if not found
output:write(S("Blame the server admin! He/She has probably not edited the random messages yet.").."\n")
output:write(S("Tell your dumb admin that this line is in (worldpath)/random_messages").."\n")
return
else
-- or write default_input content in worldpath message file
local content = default_input:read("*all")
output:write(content)
end
io.close(output) io.close(output)
io.close(default_input)
input = io.open(minetest.get_worldpath().."/random_messages","r") input = io.open(minetest.get_worldpath().."/random_messages","r")
end end
-- we should have input by now, so lets read it
for line in input:lines() do for line in input:lines() do
random_messages.messages[line_number] = line random_messages.messages[line_number] = line
line_number = line_number + 1 line_number = line_number + 1
@ -104,18 +127,20 @@ random_messages.set_interval()
random_messages.read_messages() random_messages.read_messages()
local TIMER = 0 local TIMER = 0
minetest.register_globalstep(function(dtime) if random_messages.messages[1] then
TIMER = TIMER + dtime; minetest.register_globalstep(function(dtime)
if TIMER > MESSAGE_INTERVAL then TIMER = TIMER + dtime;
random_messages.show_message() if TIMER > MESSAGE_INTERVAL then
TIMER = 0 random_messages.show_message()
end TIMER = 0
end) end
end)
end
local register_chatcommand_table = { local register_chatcommand_table = {
params = "viewmessages | removemessage <number> | addmessage <number>", params = "viewmessages | removemessage <number> | addmessage <number>",
privs = {server = true}, privs = {server = true},
description = "View and/or alter the server's random messages", description = S("View and/or alter the server's random messages"),
func = function(name,param) func = function(name,param)
local t = string.split(param, " ") local t = string.split(param, " ")
if t[1] == "viewmessages" then if t[1] == "viewmessages" then
@ -126,7 +151,7 @@ local register_chatcommand_table = {
function (params) function (params)
if not tonumber(params[2]) or if not tonumber(params[2]) or
random_messages.messages[tonumber(params[2])] == nil then random_messages.messages[tonumber(params[2])] == nil then
return false,"ERROR: No such message." return false,S("ERROR: No such message.")
end end
return true return true
end, end,
@ -134,12 +159,12 @@ local register_chatcommand_table = {
random_messages.remove_message(t[2]) random_messages.remove_message(t[2])
elseif t[1] == "addmessage" then elseif t[1] == "addmessage" then
if not t[2] then if not t[2] then
minetest.chat_send_player(name,"ERROR: No message.") minetest.chat_send_player(name,S("ERROR: No message."))
else else
random_messages.add_message(t) random_messages.add_message(t)
end end
else else
minetest.chat_send_player(name,"ERROR: Invalid command.") minetest.chat_send_player(name,S("ERROR: Invalid command."))
end end
end end
} }

View File

@ -0,0 +1,8 @@
# textdomain: random_messages
Blame the server admin! He/She has probably not edited the random messages yet.=Tirez les oreilles à l'administrateur du serveur. Il/elle n'a pas encore modifié les messages aléatoires.
Tell your dumb admin that this line is in (worldpath)/random_messages=Dites à votre administrateur à la noix que cette ligne se trouve dans (worldpath)/random_messages
View and/or alter the server's random messages=Afficher et/ou modifier les messages aléatoires du serveur
ERROR: No such message.=ERREUR : ce message est inexistant.
ERROR: No message.=ERREUR : pas de message.
ERROR: Invalid command.=ERREUR : Commande invalide.

8
locale/template.txt Normal file
View File

@ -0,0 +1,8 @@
# textdomain: random_messages
Blame the server admin! He/She has probably not edited the random messages yet.=
Tell your dumb admin that this line is in (worldpath)/random_messages=
View and/or alter the server's random messages=
ERROR: No such message.=
ERROR: No message.=
ERROR: Invalid command.=

3
mod.conf Normal file
View File

@ -0,0 +1,3 @@
name = random_messages
description = Configure your random messages.
author = arsdragonfly

2
settingtypes.txt Normal file
View File

@ -0,0 +1,2 @@
# Default is 120 seconds.
random_messages_interval (Time between two subsequent messages) int 120