luacheck fixes

This commit is contained in:
NatureFreshMilk 2019-08-05 09:00:27 +02:00
parent 179b9ebe4e
commit 1c941ba62a
6 changed files with 185 additions and 85 deletions

View File

@ -1,12 +1,15 @@
local mod_storage = minetest.get_mod_storage()
local channel_created_string = "|#${channel_name}| Channel created"
local channel_invitation_string = "|#${channel_name}| Channel invite from (${from_player}), to join the channel, do /jc ${channel_name},${channel_password} after which you can send messages to the channel via #${channel_name}: message"
local channel_invitation_string = "|#${channel_name}| Channel invite from (${from_player}), " ..
"to join the channel, do /jc ${channel_name},${channel_password} after " ..
"which you can send messages to the channel via #${channel_name}: message"
local channel_invited_string = "|#${channel_name}| Invite sent to ${to_player}"
local channel_deleted_string = "|#${channel_name}| Channel deleted"
local channel_joined_string = "|#${channel_name}| Joined channel"
local channel_left_string = "|#${channel_name}| Left channel"
local channel_already_deleted_string = "|#${channel_name}| Channel seems to have already been deleted, will unregister channel from your list of channels"
local channel_already_deleted_string = "|#${channel_name}| Channel seems to have already been deleted, " ..
"will unregister channel from your list of channels"
local join_channel_sound = "beerchat_chirp" -- Sound when you join a channel
local leave_channel_sound = "beerchat_chirp" -- Sound when you leave a channel
@ -26,7 +29,8 @@ local create_channel = {
local str = string.split(param, ",")
if #str > 3 then
return false, "ERROR: Invalid number of arguments. 4 parameters passed, maximum of 3 allowed: <Channel Name>,<Password>,<Color>"
return false, "ERROR: Invalid number of arguments. 4 parameters passed, " ..
"maximum of 3 allowed: <Channel Name>,<Password>,<Color>"
end
local lchannel_name = string.trim(str[1])
@ -39,7 +43,8 @@ local create_channel = {
end
if beerchat.channels[lchannel_name] then
return false, "ERROR: Channel "..lchannel_name.." already exists, owned by player "..beerchat.channels[lchannel_name].owner
return false, "ERROR: Channel "..lchannel_name.." already exists, owned by player "..
beerchat.channels[lchannel_name].owner
end
local arg2 = str[2]
@ -62,7 +67,10 @@ local create_channel = {
mod_storage:set_string("channels", minetest.write_json(beerchat.channels))
beerchat.playersChannels[lowner][lchannel_name] = "owner"
minetest.get_player_by_name(lowner):set_attribute("beerchat:channels", minetest.write_json(beerchat.playersChannels[lowner]))
minetest.get_player_by_name(lowner):set_attribute(
"beerchat:channels",
minetest.write_json(beerchat.playersChannels[lowner])
)
if beerchat.enable_sounds then
minetest.sound_play(beerchat.channel_management_sound, { to_player = lowner, gain = 1.0 } )
end
@ -74,10 +82,9 @@ local create_channel = {
local delete_channel = {
params = "<Channel Name>",
description = "Delete channel named <Channel Name>. You must be the owner of the channel or you are not allowed to delete the channel",
description = "Delete channel named <Channel Name>. " ..
"You must be the owner of the channel or you are not allowed to delete the channel",
func = function(name, param)
local owner = name
if not param or param == "" then
return false, "ERROR: Invalid number of arguments. Please supply the channel name"
end
@ -99,7 +106,10 @@ local delete_channel = {
mod_storage:set_string("channels", minetest.write_json(beerchat.channels))
beerchat.playersChannels[name][param] = nil
minetest.get_player_by_name(name):set_attribute("beerchat:channels", minetest.write_json(beerchat.playersChannels[name]))
minetest.get_player_by_name(name):set_attribute(
"beerchat:channels",
minetest.write_json(beerchat.playersChannels[name])
)
if beerchat.enable_sounds then
minetest.sound_play(beerchat.channel_management_sound, { to_player = name, gain = 1.0 } )
@ -114,7 +124,8 @@ local delete_channel = {
local my_channels = {
params = "<Channel Name optional>",
description = "List the channels you have joined or are the owner of, or show channel information when passing channel name as argument",
description = "List the channels you have joined or are the owner of, " ..
"or show channel information when passing channel name as argument",
func = function(name, param)
if not param or param == "" then
if beerchat.enable_sounds then
@ -138,7 +149,8 @@ local my_channels = {
local join_channel = {
params = "<Channel Name>,<Password (only mandatory if channel was created using a password)>",
description = "Join channel named <Channel Name>. After joining you will see messages sent to that channel (in addition to the other channels you have joined)",
description = "Join channel named <Channel Name>. " ..
"After joining you will see messages sent to that channel (in addition to the other channels you have joined)",
func = function(name, param)
if not param or param == "" then
return false, "ERROR: Invalid number of arguments. Please supply the channel name as a minimum"
@ -157,7 +169,8 @@ local join_channel = {
if beerchat.channels[channel_name].password and beerchat.channels[channel_name].password ~= "" then
if #str == 1 then
return false, "ERROR: This channel requires that you supply a password. Supply it in the following format: /jc my channel,password01"
return false, "ERROR: This channel requires that you supply a password. " ..
"Supply it in the following format: /jc my channel,password01"
end
if str[2] ~= beerchat.channels[channel_name].password then
return false, "ERROR: Invalid password"
@ -166,7 +179,11 @@ local join_channel = {
beerchat.playersChannels[name] = beerchat.playersChannels[name] or {}
beerchat.playersChannels[name][channel_name] = "joined"
minetest.get_player_by_name(name):set_attribute("beerchat:channels", minetest.write_json(beerchat.playersChannels[name]))
minetest.get_player_by_name(name):set_attribute(
"beerchat:channels",
minetest.write_json(beerchat.playersChannels[name])
)
if beerchat.enable_sounds then
minetest.sound_play(join_channel_sound, { to_player = name, gain = 1.0 } )
end
@ -179,7 +196,9 @@ local join_channel = {
local leave_channel = {
params = "<Channel Name>",
description = "Leave channel named <Channel Name>. When you leave the channel you can no longer send/ receive messages from that channel. NOTE: You can also leave the main channel",
description = "Leave channel named <Channel Name>. " ..
"When you leave the channel you can no longer send/ receive messages from that channel. " ..
"NOTE: You can also leave the main channel",
func = function(name, param)
if not param or param == "" then
return false, "ERROR: Invalid number of arguments. Please supply the channel name"
@ -192,7 +211,10 @@ local leave_channel = {
end
beerchat.playersChannels[name][channel_name] = nil
minetest.get_player_by_name(name):set_attribute("beerchat:channels", minetest.write_json(beerchat.playersChannels[name]))
minetest.get_player_by_name(name):set_attribute(
"beerchat:channels",
minetest.write_json(beerchat.playersChannels[name])
)
if beerchat.enable_sounds then
minetest.sound_play(leave_channel_sound, { to_player = name, gain = 1.0 } )
@ -210,10 +232,9 @@ local leave_channel = {
local invite_channel = {
params = "<Channel Name>,<Player Name>",
description = "Invite player named <Player Name> to channel named <Channel Name>. You must be the owner of the channel in order to do invites",
description = "Invite player named <Player Name> to channel named <Channel Name>. " ..
"You must be the owner of the channel in order to do invites",
func = function(name, param)
local owner = name
if not param or param == "" then
return false, "ERROR: Invalid number of arguments. Please supply the channel name and the player name"
end
@ -244,12 +265,18 @@ local invite_channel = {
minetest.sound_play(channel_invite_sound, { to_player = player_name, gain = 1.0 } )
end
-- Sending the message
minetest.chat_send_player(player_name, format_message(channel_invitation_string, { channel_name = channel_name, from_player = name }))
minetest.chat_send_player(
player_name,
format_message(channel_invitation_string, { channel_name = channel_name, from_player = name })
)
end
if beerchat.enable_sounds then
minetest.sound_play(channel_invite_sound, { to_player = name, gain = 1.0 } )
end
minetest.chat_send_player(name, format_message(channel_invited_string, { channel_name = channel_name, to_player = player_name }))
minetest.chat_send_player(
name,
format_message(channel_invited_string, { channel_name = channel_name, to_player = player_name })
)
end
return true
@ -258,7 +285,8 @@ local invite_channel = {
local mute_player = {
params = "<Player Name>",
description = "Mute a player. After muting a player, you will no longer see chat messages of this user, regardless of what channel his user sends messages to",
description = "Mute a player. After muting a player, you will no longer see chat messages of this user, " ..
"regardless of what channel his user sends messages to",
func = function(name, param)
if not param or param == "" then
return false, "ERROR: Invalid number of arguments. Please supply the name of the user to mute"

View File

@ -1,9 +1,49 @@
local channel_message_string = "|#${channel_name}| <${from_player}> ${message}"
-- # chat a.k.a. hash chat/ channel chat code, to send messages in chat channels using # e.g. #my channel: hello everyone in my channel!
-- # chat a.k.a. hash chat/ channel chat code, to send messages in chat channels using #
-- e.g. #my channel: hello everyone in my channel!
hashchat_lastrecv = {}
local hash_send_all = function(msg, name, channel_name)
for _,player in ipairs(minetest.get_connected_players()) do
local target = player:get_player_name()
-- Checking if the target is in this channel
if beerchat.playersChannels[target] and beerchat.playersChannels[target][channel_name] then
if not minetest.get_player_by_name(target):get_attribute("beerchat:muted:"..name) then
if channel_name == beerchat.main_channel_name then
minetest.chat_send_player(
target,
format_message(
beerchat.main_channel_message_string, {
channel_name = channel_name,
from_player = name,
message = msg
}
)
)
else
minetest.chat_send_player(
target,
format_message(
channel_message_string, {
channel_name = channel_name,
from_player = name,
message = msg
}
)
)
if beerchat.enable_sounds then
minetest.sound_play(beerchat.channel_message_sound, { to_player = target, gain = 1.0 } )
end
end
end
end
end
-- Register the chat in the target persons last spoken to table
hashchat_lastrecv[name] = channel_name
end
minetest.register_on_chat_message(function(name, message)
local channel_name, msg = string.match(message, "^#(.-): (.*)")
if not beerchat.channels[channel_name] then
@ -27,24 +67,7 @@ minetest.register_on_chat_message(function(name, message)
channel_name = hashchat_lastrecv[name]
end
if channel_name and channel_name ~= "" then
for _,player in ipairs(minetest.get_connected_players()) do
local target = player:get_player_name()
-- Checking if the target is in this channel
if beerchat.playersChannels[target] and beerchat.playersChannels[target][channel_name] then
if not minetest.get_player_by_name(target):get_attribute("beerchat:muted:"..name) then
if channel_name == beerchat.main_channel_name then
minetest.chat_send_player(target, format_message(beerchat.main_channel_message_string, { channel_name = channel_name, from_player = name, message = msg }))
else
minetest.chat_send_player(target, format_message(channel_message_string, { channel_name = channel_name, from_player = name, message = msg }))
if beerchat.enable_sounds then
minetest.sound_play(beerchat.channel_message_sound, { to_player = target, gain = 1.0 } )
end
end
end
end
end
-- Register the chat in the target persons last spoken to table
hashchat_lastrecv[name] = channel_name
hash_send_all(msg, name, channel_name)
else
return false
end
@ -61,10 +84,18 @@ minetest.register_on_chat_message(function(name, message)
beerchat.currentPlayerChannel[name] = channel_name
minetest.get_player_by_name(name):set_attribute("beerchat:current_channel", channel_name)
if channel_name == beerchat.main_channel_name then
minetest.chat_send_player(name, "Switched to channel "..channel_name..", messages will now be sent to this channel")
minetest.chat_send_player(
name,
"Switched to channel "..channel_name..
", messages will now be sent to this channel"
)
else
minetest.chat_send_player(name, "Switched to channel "..channel_name..", messages will now be sent to this channel. To switch back "..
"to the main channel, type #"..beerchat.main_channel_name)
minetest.chat_send_player(
name,
"Switched to channel "..channel_name..
", messages will now be sent to this channel. To switch back "..
"to the main channel, type #"..beerchat.main_channel_name
)
end
if beerchat.enable_sounds then

12
me.lua
View File

@ -3,7 +3,8 @@ local me_message_string = "|#${channel_name}| * ${from_player} ${message}"
local me_override = {
params = "<Message>",
description = "Send message in the \"* player message\" format, e.g. /me eats pizza becomes |#"..beerchat.main_channel_name.."| * Player01 eats pizza",
description = "Send message in the \"* player message\" format, e.g. /me eats pizza becomes |#"..
beerchat.main_channel_name.."| * Player01 eats pizza",
func = function(name, param)
local msg = param
local channel_name = beerchat.main_channel_name
@ -19,7 +20,14 @@ local me_override = {
-- Checking if the target is in this channel
if beerchat.playersChannels[target] and beerchat.playersChannels[target][channel_name] then
if not minetest.get_player_by_name(target):get_attribute("beerchat:muted:"..name) then
minetest.chat_send_player(target, format_message(me_message_string, { channel_name = channel_name, from_player = name, message = msg }))
minetest.chat_send_player(
target,
format_message(me_message_string, {
channel_name = channel_name,
from_player = name,
message = msg
})
)
end
end
end

View File

@ -13,7 +13,8 @@
-- ${channel_owner} owner of the channel
-- ${channel_password} password to use when joining the channel, used e.g. for invites
-- ${from_player} the player that is sending the message
-- ${to_player} player to which the message is sent, will contain multiple player names e.g. when sending a PM to multiple players
-- ${to_player} player to which the message is sent, will contain multiple player names
-- e.g. when sending a PM to multiple players
-- ${message} the actual message that is to be sent
-- ${time} the current time in 24 hour format, as returned from os.date("%X")
--
@ -54,7 +55,11 @@ minetest.register_on_chat_message(function(name, message)
local channel_name = beerchat.currentPlayerChannel[name]
if not beerchat.channels[channel_name] then
minetest.chat_send_player(name, "Channel "..channel_name.." does not exist, switching back to "..beerchat.main_channel_name..". Please resend your message")
minetest.chat_send_player(
name,
"Channel "..channel_name.." does not exist, switching back to "..
beerchat.main_channel_name..". Please resend your message"
)
beerchat.currentPlayerChannel[name] = beerchat.main_channel_name
minetest.get_player_by_name(name):set_attribute("beerchat:current_channel", beerchat.main_channel_name)
return true
@ -72,7 +77,17 @@ minetest.register_on_chat_message(function(name, message)
-- Checking if the target is in this channel
if beerchat.playersChannels[target] and beerchat.playersChannels[target][channel_name] then
if not minetest.get_player_by_name(target):get_attribute("beerchat:muted:"..name) then
minetest.chat_send_player(target, format_message(beerchat.main_channel_message_string, { channel_name = channel_name, from_player = name, message = message }))
minetest.chat_send_player(
target,
format_message(
beerchat.main_channel_message_string, {
channel_name = channel_name,
from_player = name,
message = message
}
)
)
if channel_name ~= beerchat.main_channel_name and beerchat.enable_sounds then
minetest.sound_play(beerchat.channel_message_sound, { to_player = target, gain = 0.6 } )
end

89
pm.lua
View File

@ -50,21 +50,70 @@ minetest.register_on_chat_message(function(name, message)
if atleastonesent then
successplayers = successplayers:sub(1, -2)
if (successplayers ~= name) then
minetest.chat_send_player(name, format_message(private_message_sent_string, { to_player = successplayers, message = msg }))
minetest.chat_send_player(
name,
format_message(
private_message_sent_string, {
to_player = successplayers,
message = msg
}
)
)
end
end
else
minetest.chat_send_player(name, "You have not sent private messages to anyone yet, please specify player names to send message to")
minetest.chat_send_player(name, "You have not sent private messages to anyone yet, " ..
"please specify player names to send message to")
end
end
return true
end
end)
local send_pm = function(players, name, msg)
local atleastonesent = false
local successplayers = ""
for target in string.gmatch(","..players..",", ",([^,]+),") do
-- Checking if the target exists
if not minetest.get_player_by_name(target) then
minetest.chat_send_player(name, ""..target.." is not online")
else
if not minetest.get_player_by_name(target):get_attribute("beerchat:muted:"..name) then
if target ~= name then
-- Sending the message
minetest.chat_send_player(target, format_message(private_message_string, { from_player = name, message = msg }))
if beerchat.enable_sounds then
minetest.sound_play(private_message_sound, { to_player = target, gain = 1.0 } )
end
else
minetest.chat_send_player(target, format_message(self_message_string, { from_player = name, message = msg }))
if beerchat.enable_sounds then
minetest.sound_play(self_message_sound, { to_player = target, gain = 1.0 } )
end
end
end
atleastonesent = true
successplayers = successplayers..target..","
end
end
-- Register the chat in the target persons last spoken to table
atchat_lastrecv[name] = players
if atleastonesent then
successplayers = successplayers:sub(1, -2)
if (successplayers ~= name) then
minetest.chat_send_player(
name,
format_message(private_message_sent_string, { to_player = successplayers, message = msg })
)
end
end
end
local msg_override = {
params = "<Player Name> <Message>",
description = "Send private message to player, for compatibility with the old chat command but with new style chat muting support "..
description = "Send private message to player, "..
"for compatibility with the old chat command but with new style chat muting support "..
"(players will not receive your message if they muted you) and multiple (comma separated) player support",
func = function(name, param)
minetest.log("action", "PM " .. name .. ": " .. param)
@ -78,39 +127,7 @@ local msg_override = {
return false
else
if players and players ~= "" then
local atleastonesent = false
local successplayers = ""
for target in string.gmatch(","..players..",", ",([^,]+),") do
-- Checking if the target exists
if not minetest.get_player_by_name(target) then
minetest.chat_send_player(name, ""..target.." is not online")
else
if not minetest.get_player_by_name(target):get_attribute("beerchat:muted:"..name) then
if target ~= name then
-- Sending the message
minetest.chat_send_player(target, format_message(private_message_string, { from_player = name, message = msg }))
if beerchat.enable_sounds then
minetest.sound_play(private_message_sound, { to_player = target, gain = 1.0 } )
end
else
minetest.chat_send_player(target, format_message(self_message_string, { from_player = name, message = msg }))
if beerchat.enable_sounds then
minetest.sound_play(self_message_sound, { to_player = target, gain = 1.0 } )
end
end
end
atleastonesent = true
successplayers = successplayers..target..","
end
end
-- Register the chat in the target persons last spoken to table
atchat_lastrecv[name] = players
if atleastonesent then
successplayers = successplayers:sub(1, -2)
if (successplayers ~= name) then
minetest.chat_send_player(name, format_message(private_message_sent_string, { to_player = successplayers, message = msg }))
end
end
send_pm(players, name, msg)
end
end
return true

View File

@ -5,7 +5,8 @@ local whisper_color = "#aaaaaa" -- Whisper color override
local whisper_string = "|#${channel_name}| <${from_player}> whispers: ${message}"
-- $ chat a.k.a. dollar chat code, to whisper messages in chat to nearby players only using $, optionally supplying a radius e.g. $32 Hello
-- $ chat a.k.a. dollar chat code, to whisper messages in chat to nearby players only using $,
-- optionally supplying a radius e.g. $32 Hello
minetest.register_on_chat_message(function(name, message)
local dollar, sradius, msg = string.match(message, "^($)(.-) (.*)")
if dollar == "$" then