1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
local player_name = "cheapie"
local highlight_color = "#4E9A06"
local send_nick_color = "#A40000"
local send_message_color = "#888A85"
local nick_colors = {
"#4E9A06", --19
"#CC0000", --20
"#5C3566", --22
"#C4A000", --24
"#73D216", --25
"#11A879", --26
"#58A19D", --27
"#57799E", --28
"#A04265", --29
}
local function get_nick_color(nick)
local username,extra = string.match(nick,"^(.*)@(.*)$")
if extra then nick = username end
local color = 0
for i=1,string.len(nick),1 do
color = color + string.byte(nick,i,i)
end
color = color % #nick_colors
return(nick_colors[color+1])
end
minetest.register_on_receiving_chat_messages(function(message)
local msgtype
local user
local text
if string.sub(message,1,1) == "<" then
msgtype = "channel"
user,text = string.match(message,"^<(%g*)> (.*)$")
if not user then
msgtype = "special"
text = message
end
if user == player_name then
msgtype = "sent_channel"
elseif string.find(text,player_name) then
msgtype = "highlight_channel"
end
elseif string.sub(message,1,3) == "***" then
user,msgtype,text = string.match(message,"^*** (%g*) (%g*) the game. ?(.*)$")
if not text or text == "" then
text = "(Client Quit)"
end
elseif string.sub(message,1,1) == "*" then
msgtype = "action"
user,text = string.match(message,"^* (%g*) (.*)$")
if not user then
msgtype = "special"
text = message
end
if user == player_name then
msgtype = "sent_action"
elseif string.find(text,player_name) then
msgtype = "highlight_action"
end
else
msgtype = "special"
text = message
end
if msgtype == "special" then
minetest.display_chat_message(text)
elseif msgtype == "joined" then
local coloredmsg = minetest.colorize("#CE5C00",string.format("* %s has joined",user))
minetest.display_chat_message(coloredmsg)
elseif msgtype == "left" then
local coloredmsg = minetest.colorize("#C4A000",string.format("* %s has quit %s",user,text))
minetest.display_chat_message(coloredmsg)
elseif msgtype == "channel" then
local colorednick = minetest.colorize(get_nick_color(user),user)
minetest.display_chat_message(string.format("<%s> %s",colorednick,text))
elseif msgtype == "action" then
local colorednick = minetest.colorize(get_nick_color(user),user)
minetest.display_chat_message(string.format("* %s %s",colorednick,text))
elseif msgtype == "sent_channel" then
local colorednick = minetest.colorize(send_nick_color,user)
local coloredtext = minetest.colorize(send_message_color,text)
minetest.display_chat_message(string.format("<%s> %s",colorednick,coloredtext))
elseif msgtype == "sent_action" then
local colorednick = minetest.colorize(send_nick_color,user)
local coloredtext = minetest.colorize(send_message_color,text)
minetest.display_chat_message(string.format("* %s %s",colorednick,coloredtext))
elseif msgtype == "highlight_channel" then
minetest.display_chat_message(minetest.colorize(highlight_color,string.format("<%s> %s",user,text)))
elseif msgtype == "highlight_action" then
minetest.display_chat_message(minetest.colorize(highlight_color,string.format("* %s %s",user,text)))
end
return true
end)
|