smart_chat/cmd_talk2public.lua

92 lines
3.1 KiB
Lua
Raw Permalink Normal View History

local sc = smart_chat
local S = sc.S
local cname = "talk2public"
local short = "tp"
local activate = minetest.settings:get_bool("smart_chat.cmd_" .. cname, true)
if(not activate) then return end
sc.register_help({
Name = cname,
Usage = "/c " .. cname .. " <message>",
2022-02-26 08:01:05 -08:00
Description = S("Send's a message to the public channel."),
Parameter = "<message>",
Shortcut = "/c " .. short .. " <message>",
}
)
2022-02-26 13:27:59 -08:00
local all_send_to_irc = function (message)
2022-02-26 14:17:02 -08:00
local line = "PRIVMSG " .. sc.irc_channel .. " :" .. message .. sc.crlf
2022-02-26 12:28:40 -08:00
2022-02-26 13:42:50 -08:00
sc.client:send(line)
2022-02-26 12:28:40 -08:00
sc.irc_message_count = 1 -- This prevents for IRC-Echos of multiple player
2022-02-26 13:42:50 -08:00
sc.irc_message = line -- and remembers the last message
2022-02-26 12:28:40 -08:00
end -- function
local all_send_to_bridge = function (player, message)
2022-02-26 13:00:16 -08:00
--local line = "<" .. player .. "@" .. sc.servername .. "> " .. message
2022-02-26 13:14:47 -08:00
yl_matterbridge.send_to_bridge(player, message)
2022-02-26 12:28:40 -08:00
end -- function
sc.registered_commands[cname] = function(player, parameter)
local pprivs = minetest.get_player_privs(player)
2022-04-14 02:52:52 -07:00
if not pprivs.interact and sc.cmd_tp_needs_interact then
2022-04-14 02:51:11 -07:00
minetest.chat_send_player(player,sc.red .. S("Error - require 'interact' privilege."))
return
end -- if not privs.basic_privs
local message = ""
local command = sc.last_command -- Get the last complete command
local pos = command:find(" ") -- Where is the Command
if pos then -- is there a Parameter
message = command:sub(pos + 1)
end -- if pos
local channel = sc.player[player]
if(sc.player[player] ~= nil) then
2022-02-26 08:35:20 -08:00
local all_players = minetest.get_connected_players()
local line = sc.yellow .. "[" .. sc.yellow .. player .. "@" .. channel
.. sc.yellow .. "] " .. sc.green .. message
2022-02-26 12:28:40 -08:00
for _,players in pairs(all_players) do
local pname = players:get_player_name()
2022-02-26 09:30:34 -08:00
if ((sc.player[pname] == nil) or (sc.public[pname])) then -- player in or public is on
2022-02-26 09:20:55 -08:00
sc.print(pname, line)
2022-02-26 08:35:20 -08:00
end -- if((sc.player
end -- for (_,player
2022-02-26 13:14:47 -08:00
2022-02-26 11:14:46 -08:00
sc.chat(player, sc.green .. message) -- send to own channel
2022-03-01 12:51:28 -08:00
line = "[" .. player .. "]" .. message
2022-02-26 12:28:40 -08:00
if(sc.irc_on) then
2022-02-26 13:42:50 -08:00
all_send_to_irc(line)
2022-02-27 14:26:04 -08:00
minetest.log("action", "[MOD] .. " .. sc.modname .. " : Module cmd_talk2public : " .. line)
2022-02-26 12:28:40 -08:00
end
2022-02-26 09:56:32 -08:00
if(sc.matterbridge) then
2022-02-26 13:14:47 -08:00
all_send_to_bridge(player, line)
2022-02-27 14:26:04 -08:00
minetest.log("action", "[MOD] .. " .. sc.modname .. " : Module cmd_talk2public : [Matterbridge] " .. line)
2022-02-26 08:35:20 -08:00
end -- if(matterbridge)
else
minetest.chat_send_player(player,sc.red .. S("You're already in the public channel."))
end -- if(sc.player[player] ~= nil
end -- sc["talk2public"
sc.registered_commands[short] = function(player, parameter)
sc.registered_commands[cname](player, parameter)
end -- sc.registered_commands[talk2public_shortcut