Add forward and send as to email

This commit is contained in:
rubenwardy 2018-02-02 14:40:36 +00:00
parent eb5b2514e6
commit b9dfb1b5b0

View file

@ -2,6 +2,9 @@ email = {
log = function(msg) end log = function(msg) end
} }
local _loading = true local _loading = true
local send_as = {}
local forward_to = {}
local storage = minetest.get_mod_storage()
if minetest.global_exists("chatplus") then if minetest.global_exists("chatplus") then
email.log = chatplus.log email.log = chatplus.log
@ -37,6 +40,9 @@ function email.load()
end end
end end
end end
forward_to = minetest.parse_json(storage:get_string("forward_to")) or {}
send_as = minetest.parse_json(storage:get_string("send_as")) or {}
end end
function email.save() function email.save()
@ -164,10 +170,16 @@ minetest.register_on_player_receive_fields(function(player,formname,fields)
end]]-- end]]--
end) end)
function email.send_mail(name, to, msg) function email.send_mail(aname, ato, msg)
minetest.log("Email - To: "..to..", From: "..name..", MSG: "..msg) local name = send_as[aname] or aname
local to = forward_to[ato] or ato
minetest.log("action", "Email - To: "..to..", From: "..name..", MSG: "..msg)
email.log("Email - To: "..to..", From: "..name..", MSG: "..msg) email.log("Email - To: "..to..", From: "..name..", MSG: "..msg)
if true then if not minetest.player_exists(to) then
return false, "Player '" .. to .. "' does not exist"
end
local mail = { local mail = {
date = os.date("%Y-%m-%d %H:%M:%S"), date = os.date("%Y-%m-%d %H:%M:%S"),
from = name, from = name,
@ -183,10 +195,7 @@ function email.send_mail(name, to, msg)
minetest.chat_send_player(to, "Mail from " .. name .. ": " .. msg) minetest.chat_send_player(to, "Mail from " .. name .. ": " .. msg)
return true, "Message sent to " .. to return true, "Message sent to " .. ato
else
return false, "Player '" .. to .. "' does not exist"
end
end end
minetest.register_chatcommand("inbox", { minetest.register_chatcommand("inbox", {