1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-10 04:20:17 +01:00
server-nalc/mods/chatplus/init.lua

85 lines
1.9 KiB
Lua
Raw Normal View History

2014-10-28 18:01:32 +01:00
-- Chat Plus
2015-12-21 17:40:40 +01:00
-- by rubenwardy
---------------------
-- init.lua
-- Three handlers: ignoring, distance, and mail.
---------------------
2014-10-28 18:01:32 +01:00
2015-12-21 17:40:40 +01:00
dofile(minetest.get_modpath("chatplus") .. "/api.lua")
2014-10-28 18:01:32 +01:00
2015-12-21 17:40:40 +01:00
--
2014-10-28 18:01:32 +01:00
-- Ignoring
2015-12-21 17:40:40 +01:00
--
chatplus.register_handler(function(from, to, msg)
if chatplus.players[to] and chatplus.players[to].ignore and chatplus.players[to].ignore[from] then
2014-10-28 18:01:32 +01:00
return false
end
return nil
end)
minetest.register_chatcommand("ignore", {
2015-01-08 20:31:49 +01:00
params = "name",
description = "ignore: Ignore a player",
2014-10-28 18:01:32 +01:00
func = function(name, param)
chatplus.poke(name)
2015-12-21 17:40:40 +01:00
if not chatplus.players[name].ignore[param] then
chatplus.players[name].ignore[param] = true
minetest.chat_send_player(name, param .. " has been ignored")
2014-10-28 18:01:32 +01:00
chatplus.save()
else
2015-12-21 17:40:40 +01:00
minetest.chat_send_player(name, "Player " .. param .. " is already ignored.")
2014-10-28 18:01:32 +01:00
end
end
})
minetest.register_chatcommand("unignore", {
2015-01-08 20:31:49 +01:00
params = "name",
description = "unignore: Unignore a player",
2014-10-28 18:01:32 +01:00
func = function(name, param)
chatplus.poke(name)
2015-12-21 17:40:40 +01:00
if chatplus.players[name].ignore[param] then
chatplus.players[name].ignore[param] = false
minetest.chat_send_player(name, param .. " has been unignored")
2014-10-28 18:01:32 +01:00
chatplus.save()
else
2015-12-21 17:40:40 +01:00
minetest.chat_send_player(name, "Player " .. param .. " is already unignored.")
2014-10-28 18:01:32 +01:00
end
end
})
2014-10-28 18:01:32 +01:00
2015-12-21 17:40:40 +01:00
--
-- Distance
--
chatplus.register_handler(function(from, to, msg)
local d = chatplus.setting("distance")
if d <= 0 then
2014-10-28 18:01:32 +01: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-21 17:40:40 +01:00
return not d or vector.distance(from_o:getpos(), to_o:getpos()) <= tonumber(d)
2014-10-28 18:01:32 +01:00
end)
2015-12-21 17:40:40 +01:00
--
-- Bad words
--
2014-10-28 18:01:32 +01: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
2015-01-08 20:31:49 +01:00
minetest.chat_send_player(from, "Swearing is banned")
2014-10-28 18:01:32 +01:00
return false
end
end
return nil
end)