Add luacheck and Travis-CI support
This commit is contained in:
parent
498a62bc93
commit
daa2241de2
20
.luacheckrc
Normal file
20
.luacheckrc
Normal file
@ -0,0 +1,20 @@
|
||||
unused_args = false
|
||||
allow_defined_top = true
|
||||
|
||||
globals = {
|
||||
"mail",
|
||||
}
|
||||
|
||||
read_globals = {
|
||||
-- Stdlib
|
||||
string = {fields = {"split"}},
|
||||
table = {fields = {"copy", "getn"}},
|
||||
|
||||
-- Minetest
|
||||
"minetest",
|
||||
"vector", "ItemStack",
|
||||
"dump",
|
||||
|
||||
-- Deps
|
||||
"unified_inventory",
|
||||
}
|
12
.travis.yml
Normal file
12
.travis.yml
Normal file
@ -0,0 +1,12 @@
|
||||
language: generic
|
||||
sudo: false
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- luarocks
|
||||
before_install:
|
||||
- luarocks install --local luacheck
|
||||
script:
|
||||
- $HOME/.luarocks/bin/luacheck --no-color .
|
||||
notifications:
|
||||
email: false
|
1
api.lua
1
api.lua
@ -9,6 +9,7 @@ function mail.register_on_receive(func)
|
||||
end
|
||||
|
||||
mail.receive_mail_message = "You have a new message from %s! Subject: %s\nTo view it, type /mail"
|
||||
mail.read_later_message = "You can read your messages later by using the /mail command"
|
||||
|
||||
function mail.send(src,dst,subject,body)
|
||||
minetest.log("action", "[mail] '" .. src .. "' sends mail to '" .. dst ..
|
||||
|
61
gui.lua
61
gui.lua
@ -28,9 +28,8 @@ end
|
||||
function mail.showinbox(name)
|
||||
local formspec = mail.inboxformspec
|
||||
if not mail.messages[name] then mail.messages[name] = {} end
|
||||
local idx, message
|
||||
if mail.messages[name][1] then
|
||||
for idx,message in ipairs(mail.messages[name]) do
|
||||
for idx, message in ipairs(mail.messages[name]) do
|
||||
if idx ~= 1 then formspec = formspec .. "," end
|
||||
if message.unread then
|
||||
formspec = formspec .. "#FF8888"
|
||||
@ -55,7 +54,17 @@ end
|
||||
|
||||
function mail.showmessage(name,msgnumber)
|
||||
local message = mail.messages[name][msgnumber]
|
||||
local formspec = "size[8,6]button[7.5,0;0.5,0.5;back;X]label[0,0;From: %s]label[0,0.5;Subject: %s]textarea[0.25,1;8,4;body;;%s]button[1,5;2,1;reply;Reply]button[3,5;2,1;forward;Forward]button[5,5;2,1;delete;Delete]"
|
||||
local formspec = [[
|
||||
size[8,6]
|
||||
button[7.5,0;0.5,0.5;back;X]
|
||||
label[0,0;From: %s]
|
||||
label[0,0.5;Subject: %s]
|
||||
textarea[0.25,1;8,4;body;;%s]
|
||||
button[1,5;2,1;reply;Reply]
|
||||
button[3,5;2,1;forward;Forward]
|
||||
button[5,5;2,1;delete;Delete]
|
||||
]]
|
||||
|
||||
local sender = minetest.formspec_escape(message.sender)
|
||||
local subject = minetest.formspec_escape(message.subject)
|
||||
local body = minetest.formspec_escape(message.body)
|
||||
@ -64,8 +73,21 @@ function mail.showmessage(name,msgnumber)
|
||||
end
|
||||
|
||||
function mail.showcompose(name,defaulttgt,defaultsubj,defaultbody)
|
||||
local formspec = "size[8,8]field[0.25,0.5;4,1;to;To:;%s]field[0.25,1.5;4,1;subject;Subject:;%s]textarea[0.25,2.5;8,4;body;;%s]button[1,7;2,1;cancel;Cancel]button[7.5,0;0.5,0.5;cancel;X]button[5,7;2,1;send;Send]"
|
||||
formspec = string.format(formspec,minetest.formspec_escape(defaulttgt),minetest.formspec_escape(defaultsubj),minetest.formspec_escape(defaultbody))
|
||||
local formspec = [[
|
||||
size[8,8]
|
||||
field[0.25,0.5;4,1;to;To:;%s]
|
||||
field[0.25,1.5;4,1;subject;Subject:;%s]
|
||||
textarea[0.25,2.5;8,4;body;;%s]
|
||||
button[1,7;2,1;cancel;Cancel]
|
||||
button[7.5,0;0.5,0.5;cancel;X]
|
||||
button[5,7;2,1;send;Send]
|
||||
]]
|
||||
|
||||
formspec = string.format(formspec,
|
||||
minetest.formspec_escape(defaulttgt),
|
||||
minetest.formspec_escape(defaultsubj),
|
||||
minetest.formspec_escape(defaultbody))
|
||||
|
||||
minetest.show_formspec(name,"mail:compose",formspec)
|
||||
end
|
||||
|
||||
@ -94,23 +116,30 @@ function mail.handle_receivefields(player, formname, fields)
|
||||
mail.showmessage(name,mail.highlightedmessages[name])
|
||||
end
|
||||
elseif fields.delete then
|
||||
if mail.messages[name][mail.highlightedmessages[name]] then table.remove(mail.messages[name],mail.highlightedmessages[name]) end
|
||||
if mail.messages[name][mail.highlightedmessages[name]] then
|
||||
table.remove(mail.messages[name], mail.highlightedmessages[name])
|
||||
end
|
||||
|
||||
mail.showinbox(name)
|
||||
mail.save()
|
||||
elseif fields.reply and mail.messages[name][mail.highlightedmessages[name]] then
|
||||
local message = mail.messages[name][mail.highlightedmessages[name]]
|
||||
local replyfooter = "Type your reply here."..string.char(10)..string.char(10).."--Original message follows--"..string.char(10)..message.body
|
||||
local replyfooter = "Type your reply here.\n\n--Original message follows--\n" ..message.body
|
||||
mail.showcompose(name,message.sender,"Re: "..message.subject,replyfooter)
|
||||
elseif fields.forward and mail.messages[name][mail.highlightedmessages[name]] then
|
||||
local message = mail.messages[name][mail.highlightedmessages[name]]
|
||||
local fwfooter = "Type your message here."..string.char(10)..string.char(10).."--Original message follows--"..string.char(10)..message.body
|
||||
local fwfooter = "Type your message here.\n\n--Original message follows--\n" ..message.body
|
||||
mail.showcompose(name,"","Fw: "..message.subject,fwfooter)
|
||||
elseif fields.markread then
|
||||
if mail.messages[name][mail.highlightedmessages[name]] then mail.messages[name][mail.highlightedmessages[name]].unread = false end
|
||||
if mail.messages[name][mail.highlightedmessages[name]] then
|
||||
mail.messages[name][mail.highlightedmessages[name]].unread = false
|
||||
end
|
||||
mail.showinbox(name)
|
||||
mail.save()
|
||||
elseif fields.markunread then
|
||||
if mail.messages[name][mail.highlightedmessages[name]] then mail.messages[name][mail.highlightedmessages[name]].unread = true end
|
||||
if mail.messages[name][mail.highlightedmessages[name]] then
|
||||
mail.messages[name][mail.highlightedmessages[name]].unread = true
|
||||
end
|
||||
mail.showinbox(name)
|
||||
mail.save()
|
||||
elseif fields.new then
|
||||
@ -129,14 +158,16 @@ function mail.handle_receivefields(player, formname, fields)
|
||||
mail.showinbox(name)
|
||||
elseif fields.reply then
|
||||
local message = mail.messages[name][mail.highlightedmessages[name]]
|
||||
local replyfooter = "Type your reply here."..string.char(10)..string.char(10).."--Original message follows--"..string.char(10)..message.body
|
||||
local replyfooter = "Type your reply here.\n\n--Original message follows--\n" ..message.body
|
||||
mail.showcompose(name,message.sender,"Re: "..message.subject,replyfooter)
|
||||
elseif fields.forward then
|
||||
local message = mail.messages[name][mail.highlightedmessages[name]]
|
||||
local fwfooter = "Type your message here."..string.char(10)..string.char(10).."--Original message follows--"..string.char(10)..message.body
|
||||
local fwfooter = "Type your message here.\n\n--Original message follows--\n" ..message.body
|
||||
mail.showcompose(name,"","Fw: "..message.subject,fwfooter)
|
||||
elseif fields.delete then
|
||||
if mail.messages[name][mail.highlightedmessages[name]] then table.remove(mail.messages[name],mail.highlightedmessages[name]) end
|
||||
if mail.messages[name][mail.highlightedmessages[name]] then
|
||||
table.remove(mail.messages[name],mail.highlightedmessages[name])
|
||||
end
|
||||
mail.showinbox(name)
|
||||
mail.save()
|
||||
end
|
||||
@ -153,7 +184,7 @@ function mail.handle_receivefields(player, formname, fields)
|
||||
if fields.yes then
|
||||
mail.showinbox(player:get_player_name())
|
||||
else
|
||||
minetest.chat_send_player(player:get_player_name(),"You can use the /mail command" .. (minetest.get_modpath("unified_inventory") and " or the mail button in the inventory " or " ") .. "to read your messages later.")
|
||||
minetest.chat_send_player(player:get_player_name(), mail.read_later_message)
|
||||
end
|
||||
return true
|
||||
elseif fields.mail then
|
||||
@ -169,6 +200,8 @@ minetest.register_on_player_receive_fields(mail.handle_receivefields)
|
||||
if minetest.get_modpath("unified_inventory") then
|
||||
mail.receive_mail_message = mail.receive_mail_message ..
|
||||
" or use the mail button in the inventory"
|
||||
mail.read_later_message = mail.read_later_message ..
|
||||
" or by using the mail button in the inventory"
|
||||
|
||||
unified_inventory.register_button("mail", {
|
||||
type = "image",
|
||||
|
10
onjoin.lua
10
onjoin.lua
@ -1,15 +1,13 @@
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
minetest.after(0,function(player)
|
||||
local name = player:get_player_name()
|
||||
minetest.after(0, function(name)
|
||||
local unreadflag = false
|
||||
if mail.messages[name] then
|
||||
for _,message in ipairs(mail.messages[name]) do
|
||||
for _, message in ipairs(mail.messages[name]) do
|
||||
if message.unread then unreadflag = true end
|
||||
end
|
||||
end
|
||||
if unreadflag then
|
||||
minetest.show_formspec(name,"mail:unreadnag",
|
||||
minetest.show_formspec(name, "mail:unreadnag",
|
||||
"size[3,2]" ..
|
||||
"label[0,0;You have unread messages in your inbox.]" ..
|
||||
"label[0,0.5;Go there now?]" ..
|
||||
@ -17,5 +15,5 @@ minetest.register_on_joinplayer(function(player)
|
||||
"button_exit[0.5,1.5;2,1;no;No]"
|
||||
)
|
||||
end
|
||||
end,player)
|
||||
end, player:get_player_name())
|
||||
end)
|
||||
|
@ -1,11 +1,9 @@
|
||||
|
||||
-- bi-directional http-channel
|
||||
-- with long-poll GET and POST on the same URL
|
||||
|
||||
local debug = false
|
||||
|
||||
local Channel = function(http, url, cfg)
|
||||
|
||||
local function Channel(http, url, cfg)
|
||||
cfg = cfg or {}
|
||||
local extra_headers = cfg.extra_headers or {}
|
||||
local timeout = cfg.timeout or 1
|
||||
@ -24,6 +22,8 @@ local Channel = function(http, url, cfg)
|
||||
local recv_loop
|
||||
|
||||
recv_loop = function()
|
||||
assert(run)
|
||||
|
||||
-- long-poll GET
|
||||
http.fetch({
|
||||
url = url,
|
||||
@ -53,6 +53,7 @@ local Channel = function(http, url, cfg)
|
||||
|
||||
|
||||
local send = function(data)
|
||||
assert(run)
|
||||
-- POST
|
||||
|
||||
if debug then
|
||||
@ -89,4 +90,4 @@ end
|
||||
|
||||
|
||||
|
||||
return Channel
|
||||
return Channel
|
||||
|
19
webmail.lua
19
webmail.lua
@ -1,12 +1,9 @@
|
||||
|
||||
local webmail = {}
|
||||
|
||||
local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||
local Channel = dofile(MP .. "/util/channel.lua")
|
||||
local channel
|
||||
|
||||
-- auth request from webmail
|
||||
local auth_handler = function(auth)
|
||||
local function auth_handler(auth)
|
||||
local handler = minetest.get_auth_handler()
|
||||
minetest.log("action", "[webmail] auth: " .. auth.name)
|
||||
|
||||
@ -26,14 +23,14 @@ local auth_handler = function(auth)
|
||||
end
|
||||
|
||||
-- send request from webmail
|
||||
local send_handler = function(sendmail)
|
||||
local function send_handler(sendmail)
|
||||
-- send mail from webclient
|
||||
minetest.log("action", "[webmail] sending mail from webclient: " .. sendmail.src .. " -> " .. sendmail.dst)
|
||||
mail.send(sendmail.src, sendmail.dst, sendmail.subject, sendmail.body)
|
||||
end
|
||||
|
||||
-- get player messages request from webmail
|
||||
local get_player_messages_handler = function(playername)
|
||||
local function get_player_messages_handler(playername)
|
||||
channel.send({
|
||||
type = "player-messages",
|
||||
playername = playername,
|
||||
@ -42,27 +39,27 @@ local get_player_messages_handler = function(playername)
|
||||
end
|
||||
|
||||
-- remove mail
|
||||
local delete_mail_handler = function(playername, index)
|
||||
local function delete_mail_handler(playername, index)
|
||||
if mail.messages[playername] and mail.messages[playername][index] then
|
||||
table.remove(mail.messages[playername], index)
|
||||
end
|
||||
end
|
||||
|
||||
-- mark mail as read
|
||||
local mark_mail_read_handler = function(playername, index)
|
||||
local function mark_mail_read_handler(playername, index)
|
||||
if mail.messages[playername] and mail.messages[playername][index] then
|
||||
mail.messages[playername][index].unread = false
|
||||
end
|
||||
end
|
||||
|
||||
-- mark mail as unread
|
||||
local mark_mail_unread_handler = function(playername, index)
|
||||
local function mark_mail_unread_handler(playername, index)
|
||||
if mail.messages[playername] and mail.messages[playername][index] then
|
||||
mail.messages[playername][index].unread = true
|
||||
end
|
||||
end
|
||||
|
||||
mail.webmail_send_hook = function(src,dst,subject,body)
|
||||
function mail.webmail_send_hook(src,dst,subject,body)
|
||||
channel.send({
|
||||
type = "new-message",
|
||||
data = {
|
||||
@ -75,7 +72,7 @@ mail.webmail_send_hook = function(src,dst,subject,body)
|
||||
end
|
||||
mail.register_on_receive(mail.webmail_send_hook)
|
||||
|
||||
mail.webmail_init = function(http, url, key)
|
||||
function mail.webmail_init(http, url, key)
|
||||
channel = Channel(http, url .. "/api/minetest/channel", {
|
||||
extra_headers = { "webmailkey: " .. key }
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user