Skip to content

Commit

Permalink
Add /remote_mute and /remote_unmute commands (#65)
Browse files Browse the repository at this point in the history
* Create remote_mute.lua

* Maybe fix luacheck and indentation?

* Load remote_mute.lua

* Fix name for remote_mute checks
  • Loading branch information
S-S-X committed Jun 8, 2022
1 parent 69400d6 commit eaae526
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ load_plugin("whisper", true)
-- Adds "/chat_jail playername" and "/chat_unjail playername" commands
load_plugin("jail", false)

-- Allow muting remote users
load_plugin("remote_mute", false)

-- Removes control characters from incoming messages
load_plugin("cleaner", false)

Expand Down
48 changes: 48 additions & 0 deletions plugin/remote_mute.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
local remote_muted = {}

minetest.register_chatcommand("remote_mute", {
params = "<Player Name> [<Player Name> ...]",
description = ("Mute remote users. Requires %s privilege."):format(beerchat.jail.priv),
privs = { [beerchat.jail.priv] = true },
func = function(_, param)
if not param or param == "" then
return false, "ERROR: Invalid number of arguments. Please supply the player name(s)."
end
local names = string.gmatch(param, "[^%s,]+")
for remote_name in names do
remote_muted[remote_name] = true
end
return true
end
})

minetest.register_chatcommand("remote_unmute", {
params = "[<Player Name> <Player Name> ...]",
description = ("Unmute remote users or list muted remote users. Requires %s privilege."):format(beerchat.jail.priv),
privs = { [beerchat.jail.priv] = true },
func = function(name, param)
if not param or param == "" then
local names = {}
for remote_name,_ in pairs(remote_muted) do
table.insert(names, remote_name)
end
if #names > 0 then
minetest.chat_send_player(name, "Muted remote users: " .. table.concat(names, ", "))
else
minetest.chat_send_player(name, "No muted remote users.")
end
else
local names = string.gmatch(param, "[^%s,]+")
for remote_name in names do
remote_muted[remote_name] = nil
end
end
return true
end
})

beerchat.register_callback('on_http_receive', function(msg_data)
if remote_muted[msg_data.username .. "@" .. msg_data.name] then
return false
end
end)

0 comments on commit eaae526

Please sign in to comment.