capturetheflag/mods/chatplus/init.lua

106 lines
2.5 KiB
Lua
Raw Normal View History

2015-11-24 22:20:32 +00:00
-- Chat Plus
2015-12-18 01:50:19 +00:00
-- by rubenwardy
---------------------
-- init.lua
-- Three handlers: ignoring, distance, and mail.
---------------------
2015-11-24 22:20:32 +00:00
2015-12-18 01:50:19 +00:00
dofile(minetest.get_modpath("chatplus") .. "/api.lua")
2015-11-24 22:20:32 +00:00
2015-12-18 01:50:19 +00:00
--
2015-11-24 22:20:32 +00:00
-- Ignoring
2015-12-18 01:50:19 +00:00
--
chatplus.register_handler(function(from, to, msg)
if chatplus.players[to] and chatplus.players[to].ignore and chatplus.players[to].ignore[from] then
2015-11-24 22:20:32 +00:00
return false
end
return nil
end)
minetest.register_chatcommand("ignore", {
params = "name",
description = "ignore: Ignore a player",
func = function(name, param)
chatplus.poke(name)
2015-12-18 01:50:19 +00:00
if not chatplus.players[name].ignore[param] then
chatplus.players[name].ignore[param] = true
minetest.chat_send_player(name, param .. " has been ignored")
2015-11-24 22:20:32 +00:00
chatplus.save()
else
2015-12-18 01:50:19 +00:00
minetest.chat_send_player(name, "Player " .. param .. " is already ignored.")
2015-11-24 22:20:32 +00:00
end
end
})
minetest.register_chatcommand("unignore", {
params = "name",
description = "unignore: Unignore a player",
func = function(name, param)
chatplus.poke(name)
2015-12-18 01:50:19 +00:00
if chatplus.players[name].ignore[param] then
chatplus.players[name].ignore[param] = false
minetest.chat_send_player(name, param .. " has been unignored")
2015-11-24 22:20:32 +00:00
chatplus.save()
else
2015-12-18 01:50:19 +00:00
minetest.chat_send_player(name, "Player " .. param .. " is already unignored.")
2015-11-24 22:20:32 +00:00
end
2015-12-07 22:51:27 +00:00
end
2015-11-24 22:20:32 +00:00
})
2015-12-18 01:50:19 +00:00
--
-- Distance
--
chatplus.register_handler(function(from, to, msg)
local d = chatplus.setting("distance")
if d <= 0 then
2015-11-24 22:20:32 +00:00
return nil
end
local from_o = minetest.get_player_by_name(from)
local to_o = minetest.get_player_by_name(to)
if not from_o or not to_o then
return nil
end
2015-12-18 01:50:19 +00:00
return not d or vector.distance(from_o:getpos(), to_o:getpos()) <= tonumber(d)
2015-11-24 22:20:32 +00:00
end)
2015-12-18 01:50:19 +00:00
--
-- Bad words
--
2015-11-24 22:20:32 +00:00
chatplus.register_handler(function(from,to,msg)
local words = chatplus.setting("badwords"):split(",")
for _,v in pairs(words) do
if (v:trim()~="") and ( msg:find(v:trim(), 1, true) ~= nil ) then
minetest.chat_send_player(from, "Swearing is banned")
return false
end
end
return nil
end)
2018-04-06 11:58:31 +00:00
--
-- Highlighted PMs
--
minetest.registered_chatcommands["msg"].func = function(name, param)
local sendto, message = param:match("^(%S+)%s(.+)$")
if not sendto then
return false, "Invalid usage, see /help msg."
end
if not core.get_player_by_name(sendto) then
return false, "The player " .. sendto
.. " is not online."
end
core.log("action", "PM from " .. name .. " to " .. sendto
.. ": " .. message)
core.chat_send_player(sendto, minetest.colorize(#00FF55,"PM from " .. name .. ": "
.. message))
return true, "Message sent."
end