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 | |
---|---|---|---|
8834e127a8 |
1
depends.txt
Normal file
1
depends.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
intllib?
|
46
init.lua
46
init.lua
@ -13,18 +13,9 @@ 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
|
-- Load support for intllib.
|
||||||
if minetest.get_translator ~= nil then
|
local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||||
S = minetest.get_translator("random_messages")
|
local S, NS = dofile(MP.."/intllib.lua")
|
||||||
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
|
||||||
@ -41,8 +32,14 @@ function table.random( t )
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function random_messages.initialize() --Set the interval in minetest.conf.
|
||||||
|
minetest.settings:set("random_messages_interval",120)
|
||||||
|
minetest.settings: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.settings:get("random_messages_interval") or 120)
|
MESSAGE_INTERVAL = tonumber(minetest.settings:get("random_messages_interval")) or random_messages.initialize()
|
||||||
end
|
end
|
||||||
|
|
||||||
function random_messages.check_params(name,func,params)
|
function random_messages.check_params(name,func,params)
|
||||||
@ -65,9 +62,8 @@ function random_messages.read_messages()
|
|||||||
local output = io.open(minetest.get_worldpath().."/random_messages","w")
|
local output = io.open(minetest.get_worldpath().."/random_messages","w")
|
||||||
if not default_input then
|
if not default_input then
|
||||||
-- blame the admin if not found
|
-- 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("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")
|
output:write(S("Tell your dumb admin that this line is in (worldpath)/random_messages\n"))
|
||||||
return
|
|
||||||
else
|
else
|
||||||
-- or write default_input content in worldpath message file
|
-- or write default_input content in worldpath message file
|
||||||
local content = default_input:read("*all")
|
local content = default_input:read("*all")
|
||||||
@ -127,15 +123,13 @@ random_messages.set_interval()
|
|||||||
random_messages.read_messages()
|
random_messages.read_messages()
|
||||||
|
|
||||||
local TIMER = 0
|
local TIMER = 0
|
||||||
if random_messages.messages[1] then
|
minetest.register_globalstep(function(dtime)
|
||||||
minetest.register_globalstep(function(dtime)
|
TIMER = TIMER + dtime;
|
||||||
TIMER = TIMER + dtime;
|
if TIMER > MESSAGE_INTERVAL then
|
||||||
if TIMER > MESSAGE_INTERVAL then
|
random_messages.show_message()
|
||||||
random_messages.show_message()
|
TIMER = 0
|
||||||
TIMER = 0
|
end
|
||||||
end
|
end)
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
local register_chatcommand_table = {
|
local register_chatcommand_table = {
|
||||||
params = "viewmessages | removemessage <number> | addmessage <number>",
|
params = "viewmessages | removemessage <number> | addmessage <number>",
|
||||||
@ -171,3 +165,5 @@ local register_chatcommand_table = {
|
|||||||
|
|
||||||
minetest.register_chatcommand("random_messages", register_chatcommand_table)
|
minetest.register_chatcommand("random_messages", register_chatcommand_table)
|
||||||
minetest.register_chatcommand("rmessages", register_chatcommand_table)
|
minetest.register_chatcommand("rmessages", register_chatcommand_table)
|
||||||
|
|
||||||
|
minetest.log("action", "[random_messages] loaded.")
|
||||||
|
45
intllib.lua
Normal file
45
intllib.lua
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
-- Fallback functions for when `intllib` is not installed.
|
||||||
|
-- Code released under Unlicense <http://unlicense.org>.
|
||||||
|
|
||||||
|
-- Get the latest version of this file at:
|
||||||
|
-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua
|
||||||
|
|
||||||
|
local function format(str, ...)
|
||||||
|
local args = { ... }
|
||||||
|
local function repl(escape, open, num, close)
|
||||||
|
if escape == "" then
|
||||||
|
local replacement = tostring(args[tonumber(num)])
|
||||||
|
if open == "" then
|
||||||
|
replacement = replacement..close
|
||||||
|
end
|
||||||
|
return replacement
|
||||||
|
else
|
||||||
|
return "@"..open..num..close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
|
||||||
|
end
|
||||||
|
|
||||||
|
local gettext, ngettext
|
||||||
|
if minetest.get_modpath("intllib") then
|
||||||
|
if intllib.make_gettext_pair then
|
||||||
|
-- New method using gettext.
|
||||||
|
gettext, ngettext = intllib.make_gettext_pair()
|
||||||
|
else
|
||||||
|
-- Old method using text files.
|
||||||
|
gettext = intllib.Getter()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Fill in missing functions.
|
||||||
|
|
||||||
|
gettext = gettext or function(msgid, ...)
|
||||||
|
return format(msgid, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
ngettext = ngettext or function(msgid, msgid_plural, n, ...)
|
||||||
|
return format(n==1 and msgid or msgid_plural, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
return gettext, ngettext
|
50
locale/fr.po
Normal file
50
locale/fr.po
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# SOME DESCRIPTIVE TITLE.
|
||||||
|
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||||
|
# This file is distributed under the same license as the PACKAGE package.
|
||||||
|
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: \n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2017-08-04 15:04+0200\n"
|
||||||
|
"PO-Revision-Date: 2017-08-04 15:05+0200\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 1.8.12\n"
|
||||||
|
"Last-Translator: fat115 <fat115@framasoft.org>\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||||
|
"Language: fr\n"
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid ""
|
||||||
|
"Blame the server admin! He/She has probably not edited the random messages "
|
||||||
|
"yet.\n"
|
||||||
|
msgstr ""
|
||||||
|
"Tirez les oreilles à l'administrateur du serveur. Il/elle n'a pas encore "
|
||||||
|
"modifié les messages aléatoires.\n"
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid ""
|
||||||
|
"Tell your dumb admin that this line is in (worldpath)/random_messages\n"
|
||||||
|
msgstr ""
|
||||||
|
"Dites à votre administrateur à la noix que cette ligne se trouve dans "
|
||||||
|
"(worldpath)/random_messages\n"
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid "View and/or alter the server's random messages"
|
||||||
|
msgstr "Afficher et/ou modifier les messages aléatoires du serveur"
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid "ERROR: No such message."
|
||||||
|
msgstr "ERREUR : ce message est inexistant."
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid "ERROR: No message."
|
||||||
|
msgstr "ERREUR : pas de message."
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid "ERROR: Invalid command."
|
||||||
|
msgstr "ERREUR : Commande invalide."
|
@ -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.
|
|
44
locale/template.pot
Normal file
44
locale/template.pot
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# SOME DESCRIPTIVE TITLE.
|
||||||
|
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
|
||||||
|
# This file is distributed under the same license as the PACKAGE package.
|
||||||
|
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||||
|
#
|
||||||
|
#, fuzzy
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2017-08-04 15:04+0200\n"
|
||||||
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
"Language: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=CHARSET\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid ""
|
||||||
|
"Blame the server admin! He/She has probably not edited the random messages "
|
||||||
|
"yet.\n"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid "Tell your dumb admin that this line is in (worldpath)/random_messages\n"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid "View and/or alter the server's random messages"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid "ERROR: No such message."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid "ERROR: No message."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: init.lua
|
||||||
|
msgid "ERROR: Invalid command."
|
||||||
|
msgstr ""
|
@ -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