Add chat3 compatibility

This commit is contained in:
octacian 2017-06-29 20:11:00 -07:00
parent 927f26b60c
commit 30f788b52a
4 changed files with 45 additions and 28 deletions

8
API.md
View File

@ -53,11 +53,17 @@ The ranks API allows you to register, unregister, and manage ranks.
* Removes all ranking information from a player
* `player`: PlayerRef or string
`ranks.chat_send(name, message)`
* Simulates a chat message being sent to all players from a ranked player
* `name`: Sender player name
* `message`: Message to send
#### Rank definition
```lua
{
prefix = "Moderator", -- Prefix to be shown on nametag and chat
colour = {a = 255, r = 255, g = 83, b = 37}, -- A table of RGBA values or a single base colour (e.g. "red")
colour = {a = 255, r = 255, g = 83, b = 37}, -- A table of RGBA values, a single base colour (e.g. "red"), or a hex string
strict_privs = false, -- Whether the rank should have a strict set of privileges (prevents privileges from being granted/revoked)
grant_missing = true, -- Whether missing privileges should be automatically granted
revoke_extra = false, -- Whether extra privileges should be automatically revoked

View File

@ -12,7 +12,7 @@ Ranks is an advanced ranks mod geared towards larger servers helps to both disti
This mod was made in an effort to solve two problems. One of these is new players getting confused when they see moderators or administrators doing things that normal players cannot, resulting in repeated accusations of hacking. Ranks allows there to be no confusion between what a player should or should not be able to do, as their rank is displayed in both their nametag and as a prefix to chat messages sent by them.
Displaying the rank prefix on a player's nametag can be disabled by setting `ranks.prefix_nametag = false` in `minetest.conf`, while prefixes before chat messages can be disabled with `ranks.prefix_chat = false`.
Displaying the rank prefix on a player's nametag can be disabled by setting `ranks.prefix_nametag = false` in `minetest.conf`, while prefixes before chat messages can be disabled with `ranks.prefix_chat = false`. Ranks message prefixes are also supported even when used alongside my other chat-related mods, for example, [chat3](https://forum.minetest.net/viewtopic.php?t=17163).
Ranks also attempts to make privilege updates easier by allowing you to assign a set of privileges to each rank allowing a strict set of privileges for that rank, automatically granting missing privileges, and automatically revoking extra privileges (configurable per-rank). This means that when a player is given a rank with privilege definitions, they will automatically inherit the privileges specified. Whenever `/grant`, `/grantme`, or `/revoke` is called on a player, their privileges are updated according to rank and a warning is sent to the player who called the chatcommand if privileges are modified further.

1
depends.txt Normal file
View File

@ -0,0 +1 @@
chat3?

View File

@ -2,6 +2,7 @@
ranks = {}
local chat3_exists = minetest.get_modpath("chat3")
local registered = {}
local default
@ -214,6 +215,27 @@ function ranks.remove_rank(player)
end
end
-- [function] Send prefixed message (if enabled)
function ranks.chat_send(name, message)
if minetest.settings:get("ranks.prefix_chat") ~= "false" then
local rank = ranks.get_rank(name)
if rank then
local def = ranks.get_def(rank)
if def.prefix then
local colour = get_colour(def.colour)
local prefix = minetest.colorize(colour, def.prefix)
if chat3_exists then
chat3.send(name, message, prefix.." ", "ranks")
else
minetest.chat_send_all(prefix.." <"..name.."> "..message)
minetest.log("action", "CHAT: ".."<"..name.."> "..message)
end
return true
end
end
end
end
---
--- Registrations
---
@ -240,19 +262,7 @@ end)
-- Prefix messages if enabled
minetest.register_on_chat_message(function(name, message)
if minetest.settings:get("ranks.prefix_chat") ~= "false" then
local rank = ranks.get_rank(name)
if rank then
local def = ranks.get_def(rank)
if def.prefix then
local colour = get_colour(def.colour)
minetest.chat_send_all(minetest.colorize(colour, def.prefix)..
" <"..name.."> "..message)
minetest.log("action", "CHAT: ".."<"..name.."> "..message)
return true
end
end
end
return ranks.chat_send(name, message)
end)
-- [chatcommand] /rank