1 -- Backwards compatibility for 0.4.x
2 if not core.register_on_receiving_chat_message then
3 core.register_on_receiving_chat_message = core.register_on_receiving_chat_messages
6 local color_reset = "\x1b(c@#FFF)"
7 local c_pattern = "\x1b%(c@#[0-9a-fA-F]+%)"
9 core.register_on_receiving_chat_message(function(line)
10 local myname_l = "~[CAPSĀ£"
11 if core.localplayer then
12 myname_l = core.localplayer:get_name():lower()
15 -- Detect color to still do the name mentioning effect
16 local color, line_nc = line:match("^(" .. c_pattern .. ")(.*)")
17 line = line_nc or line
20 local chat_line = false
22 local name, color_end, message = line:match("^%<(%S+)%>%s*(" .. c_pattern .. ")%s*(.*)")
24 name, message = line:match("^%<(%S+)%> (.*)")
26 name = name:gsub(c_pattern, "")
31 -- To keep the <Name> notation
34 -- Server messages, actions
35 prefix, name, message = line:match("^(%*+ )(%S+) (.*)")
39 prefix, name, message = line:match("^(.* )%<(%S+)%> (.*)")
40 if color and message and prefix:len() > 0 then
41 prefix = color .. prefix .. color_reset
47 -- Skip unknown chat line
52 local name_wrap = name
54 -- No color yet? We need color.
56 local color = core.sha1(name, true)
57 local R = color:byte( 1) % 0x10
58 local G = color:byte(10) % 0x10
59 local B = color:byte(20) % 0x10
60 if R + G + B < 24 then
66 name_wrap = "<" .. name .. ">"
68 name_wrap = minetest.colorize(string.format("#%X%X%X", R, G, B), name_wrap)
70 name_wrap = "<" .. name .. ">"
73 if (chat_line or prefix == "* ") and name:lower() ~= myname_l
74 and message:lower():find(myname_l) then
75 prefix = minetest.colorize("#F33", "[!] ") .. prefix
78 return minetest.display_chat_message(prefix .. (color or "")
79 .. name_wrap .. (color_end or "") .. " " .. message)