-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathformat_message.lua
49 lines (40 loc) · 1.15 KB
/
format_message.lua
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
local function format_string(s, tab)
return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end))
end
-- Expose format_string to public
beerchat.format_string = format_string
local function colorize_target_name(s, target)
if not target or not s then
return s
end
return s:gsub(target, minetest.colorize("#ff0000", target))
end
beerchat.format_message = function(s, tab)
local owner
local password
local color = beerchat.default_channel_color
local channel_name = tab.channel_name or ""
if beerchat.channels[channel_name] then
owner = beerchat.channels[channel_name].owner
password = beerchat.channels[channel_name].password
color = beerchat.channels[channel_name].color
end
if tab.color then
color = tab.color
end
if tab.colorize_all then
s = minetest.colorize(color, s)
else
channel_name = minetest.colorize(color, channel_name)
end
local params = {
channel_name = channel_name,
channel_owner = owner,
channel_password = password,
from_player = tab.from_player,
to_player = tab.to_player,
message = colorize_target_name(tab.message, tab.to_player),
time = os.date("%X")
}
return format_string(s, params)
end