mirror of
https://github.com/arsdragonfly/random_messages.git
synced 2025-06-29 22:51:08 +02:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
bbbccb401c |
0
README.txt
Normal file → Executable file
0
README.txt
Normal file → Executable file
60
init.lua
Normal file → Executable file
60
init.lua
Normal file → Executable file
@ -5,27 +5,12 @@ arsdragonfly@gmail.com
|
||||
--]]
|
||||
--Time between two subsequent messages.
|
||||
local MESSAGE_INTERVAL = 0
|
||||
-- Added default messages file
|
||||
local default_messages_file = "default_random_messages"
|
||||
|
||||
math.randomseed(os.time())
|
||||
|
||||
random_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 )
|
||||
local i = 0
|
||||
for k in pairs( t ) do i = i + 1 end
|
||||
@ -41,8 +26,14 @@ function table.random( t )
|
||||
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)
|
||||
MESSAGE_INTERVAL = tonumber(minetest.settings:get("random_messages_interval") or 120)
|
||||
MESSAGE_INTERVAL = tonumber(minetest.setting_get("random_messages_interval")) or random_messages.initialize()
|
||||
end
|
||||
|
||||
function random_messages.check_params(name,func,params)
|
||||
@ -56,28 +47,14 @@ end
|
||||
|
||||
function random_messages.read_messages()
|
||||
local line_number = 1
|
||||
-- define input
|
||||
local input = io.open(minetest.get_worldpath().."/random_messages","r")
|
||||
-- no input file found
|
||||
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")
|
||||
if not default_input then
|
||||
-- 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
|
||||
output:write("Blame the server admin! He/She has probably not edited the random messages yet.\n")
|
||||
output:write("Tell your dumb admin that this line is in (worldpath)/random_messages \n")
|
||||
io.close(output)
|
||||
io.close(default_input)
|
||||
input = io.open(minetest.get_worldpath().."/random_messages","r")
|
||||
end
|
||||
-- we should have input by now, so lets read it
|
||||
for line in input:lines() do
|
||||
random_messages.messages[line_number] = line
|
||||
line_number = line_number + 1
|
||||
@ -126,21 +103,16 @@ end
|
||||
random_messages.set_interval()
|
||||
random_messages.read_messages()
|
||||
|
||||
local TIMER = 0
|
||||
if random_messages.messages[1] then
|
||||
minetest.register_globalstep(function(dtime)
|
||||
TIMER = TIMER + dtime;
|
||||
if TIMER > MESSAGE_INTERVAL then
|
||||
local function step()
|
||||
random_messages.show_message()
|
||||
TIMER = 0
|
||||
end
|
||||
end)
|
||||
minetest.after(MESSAGE_INTERVAL, step)
|
||||
end
|
||||
minetest.after(0, step)
|
||||
|
||||
local register_chatcommand_table = {
|
||||
params = "viewmessages | removemessage <number> | addmessage <number>",
|
||||
privs = {server = true},
|
||||
description = S("View and/or alter the server's random messages"),
|
||||
description = "View and/or alter the server's random messages",
|
||||
func = function(name,param)
|
||||
local t = string.split(param, " ")
|
||||
if t[1] == "viewmessages" then
|
||||
@ -151,7 +123,7 @@ local register_chatcommand_table = {
|
||||
function (params)
|
||||
if not tonumber(params[2]) or
|
||||
random_messages.messages[tonumber(params[2])] == nil then
|
||||
return false,S("ERROR: No such message.")
|
||||
return false,"ERROR: No such message."
|
||||
end
|
||||
return true
|
||||
end,
|
||||
@ -159,12 +131,12 @@ local register_chatcommand_table = {
|
||||
random_messages.remove_message(t[2])
|
||||
elseif t[1] == "addmessage" then
|
||||
if not t[2] then
|
||||
minetest.chat_send_player(name,S("ERROR: No message."))
|
||||
minetest.chat_send_player(name,"ERROR: No message.")
|
||||
else
|
||||
random_messages.add_message(t)
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(name,S("ERROR: Invalid command."))
|
||||
minetest.chat_send_player(name,"ERROR: Invalid command.")
|
||||
end
|
||||
end
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
# 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.
|
@ -1,8 +0,0 @@
|
||||
# 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
3
mod.conf
@ -1,3 +0,0 @@
|
||||
name = random_messages
|
||||
description = Configure your random messages.
|
||||
author = arsdragonfly
|
@ -1,2 +0,0 @@
|
||||
# Default is 120 seconds.
|
||||
random_messages_interval (Time between two subsequent messages) int 120
|
Reference in New Issue
Block a user