Cleanup control characters from messages

This commit is contained in:
SX 2020-08-18 19:01:02 +03:00 committed by Buckaroo Banzai
parent bcf6179808
commit 590bfde2bc
4 changed files with 18 additions and 0 deletions

4
cleaner.lua Normal file
View File

@ -0,0 +1,4 @@
beerchat.register_callback('on_receive', function(msg_data)
msg_data.message = msg_data.message:gsub('%c','')
end)

View File

@ -4,6 +4,13 @@
hashchat_lastrecv = {}
minetest.register_on_chat_message(function(name, message)
local msg_data = {name=name,message=message}
if beerchat.execute_callbacks('on_receive', msg_data) then
message = msg_data.message
else
return false
end
local channel_name, msg = string.match(message, "^#(.-): (.*)")
if not beerchat.channels[channel_name] then
channel_name, msg = string.match(message, "^#(.-) (.*)")

View File

@ -13,6 +13,9 @@ beerchat.cb.before_mute = {} -- executed before player is muted
beerchat.cb.before_check_muted = {} -- executed before has_player_muted_player checks
beerchat.cb.on_forced_join = {} -- executed right after player is forced to channel
-- Callbacks that can edit message contents
beerchat.cb.on_receive = {} -- executed when new message is received
beerchat.register_callback = function(trigger, fn)
if type(fn) ~= 'function' then
print('Error: Invalid fn argument for beerchat.register_callback, must be function. Got ' .. type(fn))

View File

@ -79,6 +79,10 @@ if minetest.settings:get_bool("beerchat.enable_jail") then
dofile(MP.."/jail.lua")
end
if minetest.settings:get_bool("beerchat.enable_cleaner") then
dofile(MP.."/cleaner.lua")
end
if minetest.settings:get_bool("enable_beerchat_integration_test") then
dofile(MP.."/integration_test.lua")
end