Skip to content

Commit

Permalink
Allow colorizing chat messages on selected channels (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
S-S-X committed Apr 6, 2021
1 parent 616ce49 commit 560311a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ if minetest.settings:get_bool("enable_beerchat_integration_test") then
dofile(MP.."/integration_test.lua")
end

dofile(MP.."/plugin/colorize.lua")

print("[OK] beerchat")

6 changes: 4 additions & 2 deletions message.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ beerchat.send_on_channel = function(name, channel_name, message)
end

beerchat.register_callback("on_send_on_channel", function(msg, target)
return beerchat.is_player_subscribed_to_channel(target, msg.channel)
and not beerchat.has_player_muted_player(target, msg.name)
if not beerchat.is_player_subscribed_to_channel(target, msg.channel)
or beerchat.has_player_muted_player(target, msg.name) then
return false
end
end)

minetest.register_on_chat_message(function(name, message)
Expand Down
20 changes: 20 additions & 0 deletions plugin/colorize.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

local colorize_channels = minetest.settings:get("beerchat.colorize_channels")

if colorize_channels then

local channels = string.gmatch(colorize_channels, "[^%s,]+")
local allowed_channels = {}
for channel in channels do
allowed_channels[channel] = true
end

if next(allowed_channels) then
beerchat.register_callback('on_send_on_channel', function(msg_data)
if msg_data.channel and allowed_channels[msg_data.channel] then
msg_data.message = msg_data.message:gsub('%((%#%x%x%x)%)', string.char(0x1B) .. '(c@%1)')
end
end)
end

end

0 comments on commit 560311a

Please sign in to comment.