diff --git a/cleaner.lua b/cleaner.lua new file mode 100644 index 0000000..828c97d --- /dev/null +++ b/cleaner.lua @@ -0,0 +1,4 @@ + +beerchat.register_callback('on_receive', function(msg_data) + msg_data.message = msg_data.message:gsub('%c','') +end) diff --git a/hash.lua b/hash.lua index 06139dc..1ce4142 100644 --- a/hash.lua +++ b/hash.lua @@ -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, "^#(.-) (.*)") diff --git a/hooks.lua b/hooks.lua index d6c3c8b..15dd964 100644 --- a/hooks.lua +++ b/hooks.lua @@ -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)) diff --git a/init.lua b/init.lua index 96e4e08..6081776 100644 --- a/init.lua +++ b/init.lua @@ -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