Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /remote_mute and /remote_unmute commands #65

Merged
merged 4 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)