minetest-chat_highlights/init.lua

902 lines
25 KiB
Lua
Raw Permalink Normal View History

2022-07-30 12:09:47 -07:00
local register_on_receive = minetest.register_on_receiving_chat_message or minetest.register_on_receiving_chat_messages
if not register_on_receive then
return
end
local colorize = minetest.colorize
2019-04-24 16:15:35 -07:00
local mod_name = minetest.get_current_modname()
2022-07-30 12:09:47 -07:00
local function log(level, messagefmt, ...)
minetest.log(level, ("[%s] %s"):format(mod_name, messagefmt:format(...)))
2019-04-24 16:15:35 -07:00
end
2022-07-30 12:09:47 -07:00
log("action", "CSM loading...")
2019-04-24 16:15:35 -07:00
2019-04-21 19:20:33 -07:00
-- configurable values --
2022-07-30 12:09:47 -07:00
local ignore_messages = {
"Not chiselable",
"You are now a human",
"You are now a werewolf",
--"Werewolves only can eat raw meat!",
"You missed the snake",
"Nothing to replace.",
"Node replacement tool set to:",
"Your hit glanced off of the protection and turned you around. The protection deals you 1 damage.",
"Error: \"nothing\" is not a node.",
">>> You missed <<<",
}
local function escape_regex(x)
return (x:gsub("%%", "%%%%")
:gsub("^%^", "%%^")
:gsub("%$$", "%%$")
:gsub("%(", "%%(")
:gsub("%)", "%%)")
:gsub("%.", "%%.")
:gsub("%[", "%%[")
:gsub("%]", "%%]")
:gsub("%*", "%%*")
:gsub("%+", "%%+")
:gsub("%-", "%%-")
:gsub("%?", "%%?"))
end
local function should_ignore(text)
for _, ignore_message in ipairs(ignore_messages) do
local match, _ = text:match("(" .. escape_regex(ignore_message) .. ")")
if match and match ~= "" then
return true
end
end
return false
end
2019-04-24 16:15:35 -07:00
local PER_SERVER = true -- set to false if you want to use the same player statuses on all servers
local AUTO_ALERT_ON_NAME = true -- set to false if you don't want messages that mention you to highlight automatically
2019-04-27 22:44:17 -07:00
local COLOR_BY_STATUS = {
2022-07-30 12:09:47 -07:00
default="#888888", -- don't remove or change the name of this status!
server="#FF9900", -- don't remove or change the name of this status!
self="#FF8888", -- don't remove or change the name of this status!
2019-04-27 22:44:17 -07:00
-- these can be changed to your liking.
-- TODO: make these configurable in game?
2022-07-30 12:09:47 -07:00
secretz="#000000",
admin="#88FFFF",
privileged="#00FFFF",
poweruser="#55FFAA",
ally="#00FF55",
friend="#00FF00",
acquaintance="#55FF00",
contact="#AAFF00",
noob="#FFFF00",
trouble="#FF0000",
rival="#FF0088",
other="#FF00FF",
2019-04-20 16:51:07 -07:00
}
2019-04-27 22:44:17 -07:00
local LIGHTEN_TEXT_BY = .8 -- 0 == same color as status; 1 == pure white.
2019-04-21 19:20:33 -07:00
2022-07-30 12:09:47 -07:00
local DATE_FORMAT = "%Y%m%dT%H%M%S"
2019-04-21 19:20:33 -07:00
-- END configurable values --
-- general functions --
2019-04-20 16:51:07 -07:00
2019-04-20 20:48:20 -07:00
local function safe(func)
2019-04-24 16:15:35 -07:00
-- wrap a function w/ logic to avoid crashing the game
local f = function(...)
2019-04-20 16:51:07 -07:00
local status, out = pcall(func, ...)
if status then
return out
else
2022-07-30 12:09:47 -07:00
log("warning", "Error (func): " .. out)
2019-04-20 16:51:07 -07:00
return nil
end
end
2019-04-24 16:15:35 -07:00
return f
2019-04-20 16:51:07 -07:00
end
2019-04-20 20:48:20 -07:00
local function lc_cmp(a, b)
return a:lower() < b:lower()
end
local function pairsByKeys(t, f)
2019-04-20 16:51:07 -07:00
local a = {}
2019-04-24 16:15:35 -07:00
for n in pairs(t) do
table.insert(a, n)
end
2019-04-20 16:51:07 -07:00
table.sort(a, f)
local i = 0
return function()
i = i + 1
if a[i] == nil then
return nil
else
return a[i], t[a[i]]
end
end
end
2019-04-27 22:44:17 -07:00
local function round(x)
-- approved by kahan
if x % 2 ~= 0.5 then
return math.floor(x+0.5)
else
return x - 0.5
end
end
local function bound(min, val, max)
return math.min(max, math.max(min, val))
end
local function lighten(hex_color, percent)
-- lighten a hexcolor (#XXXXXX) by a percent (0.0=none, 1.0=full white)
local r = tonumber(hex_color:sub(2,3), 16)
local g = tonumber(hex_color:sub(4,5), 16)
local b = tonumber(hex_color:sub(6,7), 16)
r = bound(0, round(((1 - percent) * r) + (percent * 255)), 255)
g = bound(0, round(((1 - percent) * g) + (percent * 255)), 255)
b = bound(0, round(((1 - percent) * b) + (percent * 255)), 255)
2022-07-30 12:09:47 -07:00
return ("#%02x%02x%02x"):format(r, g, b)
end
local function get_date_string()
return os.date(DATE_FORMAT, os.time())
2019-04-27 22:44:17 -07:00
end
2019-04-21 19:20:33 -07:00
-- END general functions --
-- mod_storage access --
2019-04-20 16:51:07 -07:00
2019-04-27 22:44:17 -07:00
local mod_storage = minetest.get_mod_storage()
2019-04-24 16:15:35 -07:00
local server_id
if PER_SERVER then
local server_info = minetest.get_server_info()
2022-07-30 12:09:47 -07:00
server_id = server_info.address .. ":" .. server_info.port
2019-04-24 16:15:35 -07:00
else
2022-07-30 12:09:47 -07:00
server_id = ""
2019-04-24 16:15:35 -07:00
end
2019-04-27 22:44:17 -07:00
-- -- mod_storage: status_by_name -- --
2019-04-20 16:51:07 -07:00
2019-04-24 16:15:35 -07:00
local status_by_name
2019-04-20 16:51:07 -07:00
2019-04-24 16:15:35 -07:00
local function load_status_by_name()
local serialized_storage = mod_storage:get_string(server_id)
2022-07-30 12:09:47 -07:00
if string.find(serialized_storage, "return") then
2019-04-24 16:15:35 -07:00
return minetest.deserialize(serialized_storage)
2019-04-21 19:20:33 -07:00
else
2019-04-24 16:15:35 -07:00
mod_storage:set_string(server_id, minetest.serialize({}))
return {}
2019-04-21 19:20:33 -07:00
end
2019-04-20 16:51:07 -07:00
end
2019-04-24 16:15:35 -07:00
local function save_status_by_name()
mod_storage:set_string(server_id, minetest.serialize(status_by_name))
end
status_by_name = load_status_by_name()
local function get_name_status(name)
2022-07-30 12:09:47 -07:00
return status_by_name[name] or "default"
2019-04-20 16:51:07 -07:00
end
2019-04-24 16:15:35 -07:00
local function set_name_status(name, status)
status_by_name = load_status_by_name()
status_by_name[name] = status
save_status_by_name()
end
2019-04-27 22:44:17 -07:00
-- -- END mod_storage: status_by_name -- --
-- -- mod_storage: alert_patterns -- --
2019-04-24 16:15:35 -07:00
local alert_patterns
local function load_alert_patterns()
2022-07-30 12:09:47 -07:00
local serialized_storage = mod_storage:get_string(("%s:alert_patterns"):format(server_id))
if string.find(serialized_storage, "return") then
2019-04-24 16:15:35 -07:00
return minetest.deserialize(serialized_storage)
2019-04-21 19:20:33 -07:00
else
2022-07-30 12:09:47 -07:00
mod_storage:set_string(("%s:alert_patterns"):format(server_id), minetest.serialize({}))
2019-04-24 16:15:35 -07:00
return {}
2019-04-21 19:20:33 -07:00
end
end
2019-04-24 16:15:35 -07:00
local function save_alert_patterns()
2022-07-30 12:09:47 -07:00
mod_storage:set_string(("%s:alert_patterns"):format(server_id), minetest.serialize(alert_patterns))
2019-04-24 16:15:35 -07:00
end
alert_patterns = load_alert_patterns()
local function add_alert_pattern(pattern)
alert_patterns = load_alert_patterns()
alert_patterns[pattern] = true
save_alert_patterns()
end
local function remove_alert_pattern(pattern)
alert_patterns = load_alert_patterns()
alert_patterns[pattern] = nil
save_alert_patterns()
end
2019-04-27 22:44:17 -07:00
-- -- END mod_storage: alert_patterns -- --
-- -- mod_storage: disabled_servers -- --
local disabled_servers
local function load_disabled_servers()
2022-07-30 12:09:47 -07:00
local serialized_storage = mod_storage:get_string("disabled_servers")
if string.find(serialized_storage, "return") then
2019-04-27 22:44:17 -07:00
return minetest.deserialize(serialized_storage)
else
2022-07-30 12:09:47 -07:00
local ds = {["94.16.121.151:2500"] = true } -- disable on IFS by default
mod_storage:set_string("disabled_servers", minetest.serialize(ds))
2019-04-27 22:44:17 -07:00
return ds
end
end
2019-04-21 19:20:33 -07:00
2019-04-27 22:44:17 -07:00
local function save_disabled_servers()
2022-07-30 12:09:47 -07:00
mod_storage:set_string("disabled_servers", minetest.serialize(disabled_servers))
2019-04-27 22:44:17 -07:00
end
disabled_servers = load_disabled_servers()
local function toggle_disable_this_server()
local current_status
disabled_servers = load_disabled_servers()
if disabled_servers[server_id] then
disabled_servers[server_id] = nil
current_status = false
else
disabled_servers[server_id] = true
current_status = true
end
save_disabled_servers()
return current_status
end
-- -- END mod_storage: disabled_servers -- --
2019-04-24 16:15:35 -07:00
-- END mod_storage access --
-- initalization --
2019-04-21 19:20:33 -07:00
2020-06-03 16:19:01 -07:00
local set_my_name_tries = 0
local function set_my_name()
2019-04-27 22:44:17 -07:00
local name
if minetest.localplayer then
name = minetest.localplayer:get_name()
2022-07-30 12:09:47 -07:00
log("action", ("you are %s"):format(name))
set_name_status(name, "self")
2019-04-24 16:15:35 -07:00
if AUTO_ALERT_ON_NAME then
add_alert_pattern(name)
end
2020-06-03 16:19:01 -07:00
elseif set_my_name_tries < 20 then
set_my_name_tries = set_my_name_tries + 1
minetest.after(1, set_my_name)
2019-04-27 22:44:17 -07:00
else
2022-07-30 12:09:47 -07:00
log("warning", "could not determine name!")
2019-04-20 16:51:07 -07:00
end
2020-06-03 16:19:01 -07:00
end
2019-04-20 16:51:07 -07:00
if minetest.register_on_connect then
2019-04-24 16:15:35 -07:00
minetest.register_on_connect(set_my_name)
elseif minetest.register_on_mods_loaded then
minetest.register_on_mods_loaded(set_my_name)
else
2019-05-03 13:48:57 -07:00
minetest.after(1, set_my_name)
2019-04-20 16:51:07 -07:00
end
2019-04-21 19:20:33 -07:00
-- END initalization --
-- chat commands --
2019-04-20 16:51:07 -07:00
2022-07-30 12:09:47 -07:00
minetest.register_chatcommand("ch_toggle", {
description = ("turn %s on/off for this server"):format(mod_name),
2019-04-27 22:44:17 -07:00
func = safe(function()
local current_status = toggle_disable_this_server()
if current_status then
2022-07-30 12:09:47 -07:00
current_status = "off"
2019-04-27 22:44:17 -07:00
else
2022-07-30 12:09:47 -07:00
current_status = "on"
2019-04-27 22:44:17 -07:00
end
2022-07-30 12:09:47 -07:00
minetest.display_chat_message(("%s is now %s for server "%s""):format(mod_name, current_status, server_id))
2019-04-27 22:44:17 -07:00
end),
})
2022-07-30 12:09:47 -07:00
minetest.register_chatcommand("ch_statuses", {
description = "list statuses",
2019-04-20 16:51:07 -07:00
func = safe(function()
2019-04-27 22:44:17 -07:00
for name, color in pairsByKeys(COLOR_BY_STATUS) do
2019-04-20 16:51:07 -07:00
if name and color then
2022-07-30 12:09:47 -07:00
minetest.display_chat_message(colorize(color, ("%s: %s"):format(name, color)))
2019-04-20 16:51:07 -07:00
end
end
end),
})
2022-07-30 12:09:47 -07:00
minetest.register_chatcommand("ch_set", {
params = "<name> <status>",
description = "associate a name w/ a status",
2019-04-20 16:51:07 -07:00
func = safe(function(param)
2022-07-30 12:09:47 -07:00
local name, status = param:match("^(%S+)%s+(%S+)$")
2019-04-20 16:51:07 -07:00
if name ~= nil then
2019-04-27 22:44:17 -07:00
if not COLOR_BY_STATUS[status] then
2022-07-30 12:09:47 -07:00
minetest.display_chat_message(colorize("#FF0000", ("unknown status \"%s\""):format(status)))
2019-04-20 16:51:07 -07:00
return false
end
2019-04-24 16:15:35 -07:00
set_name_status(name, status)
2022-07-30 12:09:47 -07:00
minetest.display_chat_message(colorize(COLOR_BY_STATUS[status], ("%s is now %s"):format(name, status)))
2019-04-20 16:51:07 -07:00
return true
else
2022-07-30 12:09:47 -07:00
minetest.display_chat_message(colorize("#FF0000", "invalid syntax"))
2019-04-20 16:51:07 -07:00
return false
end
end),
})
2022-07-30 12:09:47 -07:00
minetest.register_chatcommand("ch_unset", {
params = "<name>",
description = "unregister a name",
2019-04-20 20:48:20 -07:00
func = safe(function(name)
2019-04-24 16:15:35 -07:00
set_name_status(name, nil)
2022-07-30 12:09:47 -07:00
minetest.display_chat_message(colorize(COLOR_BY_STATUS.server, ("unregistered %s"):format(name)))
2019-04-20 16:51:07 -07:00
end),
})
2022-07-30 12:09:47 -07:00
minetest.register_chatcommand("ch_list", {
description = "list all statuses",
2019-04-20 16:51:07 -07:00
func = safe(function()
2019-04-24 16:15:35 -07:00
for name, status in pairsByKeys(status_by_name, lc_cmp) do
2019-04-27 22:44:17 -07:00
local color = COLOR_BY_STATUS[status] or COLOR_BY_STATUS.default
2022-07-30 12:09:47 -07:00
minetest.display_chat_message(colorize(color, ("%s: %s"):format(name, status)))
2019-04-20 16:51:07 -07:00
end
end),
})
2019-04-24 16:15:35 -07:00
2022-07-30 12:09:47 -07:00
minetest.register_chatcommand("ch_alert_list", {
description = "list all alert patterns",
2019-04-24 16:15:35 -07:00
func = safe(function()
for pattern, _ in pairsByKeys(alert_patterns, lc_cmp) do
2022-07-30 12:09:47 -07:00
minetest.display_chat_message(colorize(COLOR_BY_STATUS.server, pattern))
2019-04-24 16:15:35 -07:00
end
end),
})
2022-07-30 12:09:47 -07:00
minetest.register_chatcommand("ch_alert_set", {
params = "<pattern>",
description = "alert on a given pattern",
2019-04-24 16:15:35 -07:00
func = safe(function(pattern)
add_alert_pattern(pattern)
end),
})
2022-07-30 12:09:47 -07:00
minetest.register_chatcommand("ch_alert_unset", {
params = "<pattern>",
description = "no longer alert on a given pattern",
2019-04-24 16:15:35 -07:00
func = safe(function(pattern)
remove_alert_pattern(pattern)
end),
})
2019-04-21 19:20:33 -07:00
-- END chat commands --
2019-04-20 16:51:07 -07:00
local function clean_android(msg)
2019-04-24 16:15:35 -07:00
-- supposedly, android surrounds messages with (c@#ffffff)
2022-07-30 12:09:47 -07:00
if msg:sub(1, 4) == "(c@#" then -- strip preceeding
msg = msg:sub(msg:find(")") + 1, -1)
if msg:sub(-11, -8) == "(c@#" then -- strip trailing
2019-04-20 16:51:07 -07:00
msg = msg:sub(-11)
end
end
return msg
end
2022-07-30 12:09:47 -07:00
local function clean_weird_crap(msg)
-- client side translation stuff in 5.5?
msg = msg:gsub("\27%(T@[^%)]+%)", "")
msg = msg:gsub("\27.", "")
return msg
end
2019-04-20 16:51:07 -07:00
local function get_color_by_name(name)
2019-04-20 20:48:20 -07:00
local _
2022-07-30 12:09:47 -07:00
name, _ = name:match("^([^@]+).*$") -- strip @... from IRC users
name, _ = name:match("^([^[]+).*$") -- strip [m] from matrix users
2019-04-20 16:51:07 -07:00
2019-04-24 16:15:35 -07:00
local status = get_name_status(name)
2019-04-27 22:44:17 -07:00
return COLOR_BY_STATUS[status] or COLOR_BY_STATUS.default
2019-04-20 16:51:07 -07:00
end
2019-04-20 20:48:20 -07:00
local function color_name(name)
local color = get_color_by_name(name)
2022-07-30 12:09:47 -07:00
return colorize(color, name)
2019-04-20 20:48:20 -07:00
end
local function color_names(names, delim)
local sorted_names = {}
2022-07-30 12:09:47 -07:00
for name in names:gmatch("[%w_%-]+") do
2019-04-20 20:48:20 -07:00
table.insert(sorted_names, name)
end
table.sort(sorted_names, lc_cmp)
2019-04-24 16:15:35 -07:00
for i, name in ipairs(sorted_names) do
sorted_names[i] = color_name(name)
2019-04-20 20:48:20 -07:00
end
2019-04-24 16:15:35 -07:00
return table.concat(sorted_names, delim)
2019-04-20 20:48:20 -07:00
end
2019-04-27 22:44:17 -07:00
local function color_text(name, text)
2019-04-24 16:15:35 -07:00
for pattern, _ in pairs(alert_patterns) do
if text:lower():match(pattern:lower()) then
2022-07-30 12:09:47 -07:00
minetest.sound_play("default_dug_metal")
return colorize(COLOR_BY_STATUS.self, text)
2019-04-24 16:15:35 -07:00
end
end
2019-04-20 16:51:07 -07:00
2019-04-27 22:44:17 -07:00
local color = get_color_by_name(name)
2019-04-24 16:15:35 -07:00
2019-04-27 22:44:17 -07:00
if color == COLOR_BY_STATUS.default then
2022-07-30 12:09:47 -07:00
return colorize(COLOR_BY_STATUS.default, text)
2019-04-27 22:44:17 -07:00
else
color = lighten(color, LIGHTEN_TEXT_BY)
2022-07-30 12:09:47 -07:00
return colorize(color, text)
2019-04-27 22:44:17 -07:00
end
2019-04-20 16:51:07 -07:00
end
2019-05-14 16:14:21 -07:00
local function idiv(a, b)
return (a - (a % b)) / b
end
local function seconds_to_interval(time)
local s = time % 60; time = idiv(time, 60)
local m = time % 60; time = idiv(time, 60)
local h = time % 24; time = idiv(time, 24)
if time ~= 0 then
2022-07-30 12:09:47 -07:00
return ("%d days %02d:%02d:%02d"):format(time, h, m, s)
2019-05-14 16:14:21 -07:00
elseif h ~= 0 then
2022-07-30 12:09:47 -07:00
return ("%02d:%02d:%02d"):format(h, m, s)
2019-05-14 16:14:21 -07:00
elseif m ~= 0 then
2022-07-30 12:09:47 -07:00
return ("%02d:%02d"):format(m, s)
2019-05-14 16:14:21 -07:00
else
2022-07-30 12:09:47 -07:00
return ("%d seconds"):format(s)
2019-05-14 16:14:21 -07:00
end
end
2022-07-30 12:09:47 -07:00
local function sort_privs(text)
local sorted_privs = {}
2019-05-14 16:14:21 -07:00
2022-07-30 12:09:47 -07:00
for priv in text:gmatch("[%w_%-]+") do
table.insert(sorted_privs, priv)
end
2019-04-24 16:15:35 -07:00
2022-07-30 12:09:47 -07:00
table.sort(sorted_privs, lc_cmp)
2019-04-24 16:15:35 -07:00
2022-07-30 12:09:47 -07:00
return table.concat(sorted_privs, ", ")
end
2019-04-27 22:44:17 -07:00
2022-07-30 12:09:47 -07:00
local t = {
-- SORT PRIVILEGES
{"^Privileges of ([^:]+): (.*)$", function(name, text)
return ("%s%s%s%s"):format(
color_text(name, "Privileges of "),
color_name(name),
color_text(name, ": "),
color_text(name, sort_privs(text))
)
end},
2019-04-20 16:51:07 -07:00
-- join/part messages
2022-07-30 12:09:47 -07:00
{"^%*%*%* (%S+) (.*)$", function(name, text)
return ("%s %s %s"):format(
color_text(name, "***"),
2019-04-27 22:44:17 -07:00
color_name(name),
color_text(name, text)
2022-07-30 12:09:47 -07:00
)
end},
-- yl discord messages
{"^<([^|%s]+)|([^>%s]+)>%s+(.*)$", function(source, name, text)
return ("%s%s%s%s%s %s"):format(
color_text(name, "<"),
color_text(name, source),
color_text(name, "|"),
color_name(name),
color_text(name, ">"),
color_text(name, text)
)
end},
2019-04-20 16:51:07 -07:00
-- normal messages
2022-07-30 12:09:47 -07:00
{"^<([^>%s]+)>%s+(.*)$", function(name, text)
return ("%s%s%s %s"):format(
color_text(name, "<"),
2019-04-27 22:44:17 -07:00
color_name(name),
2022-07-30 12:09:47 -07:00
color_text(name, ">"),
2019-09-10 18:26:22 -07:00
color_text(name, text)
2022-07-30 12:09:47 -07:00
)
end},
-- YL chatroom stuff
-- {"^\[([^@]+}@([^\]]+)\] (.*)$", function(name, channel, text)
-- return ("%s%s%s %s"):format(
-- color_text(name, "["),
-- color_name(name),
-- color_text(name, "@"),
-- color_name(channel),
-- color_text(name, "]"),
-- color_text(name, text)
-- )
-- end},
-- YL announce
{"^(%[[^%]]+%])%s(.*)$", function(t1, t2)
return ("%s %s"):format(
colorize(COLOR_BY_STATUS.server, t1),
colorize(COLOR_BY_STATUS.server, t2)
)
end},
2019-09-10 18:26:22 -07:00
-- prefixed messages
2022-07-30 12:09:47 -07:00
{"^(%S+)%s+<([^>]+)>%s+(.*)$", function(prefix, name, text)
return ("%s %s%s%s %s"):format(
2019-09-10 18:26:22 -07:00
color_text(name, prefix),
2022-07-30 12:09:47 -07:00
color_text(name, "<"),
2019-09-10 18:26:22 -07:00
color_name(name),
2022-07-30 12:09:47 -07:00
color_text(name, ">"),
2019-09-29 21:07:18 -07:00
color_text(name, text)
2022-07-30 12:09:47 -07:00
)
end},
2019-09-29 21:07:18 -07:00
-- Empire of Legends messages
2022-07-30 12:09:47 -07:00
{"^<(%S+)%s+([^>]+)>%s+(.*)$", function(prefix, name, text)
return ("%s%s %s%s %s"):format(
color_text(name, "<"),
2019-09-29 21:07:18 -07:00
color_text(name, prefix),
color_name(name),
2022-07-30 12:09:47 -07:00
color_text(name, ">"),
2019-04-27 22:44:17 -07:00
color_text(name, text)
2022-07-30 12:09:47 -07:00
)
end},
2019-04-20 16:51:07 -07:00
-- /me messages
2022-07-30 12:09:47 -07:00
{"^%* (%S+) (.*)$", function(name, text)
return ("%s %s %s"):format(
color_text(name, "*"),
2019-04-27 22:44:17 -07:00
color_name(name),
color_text(name, text)
2022-07-30 12:09:47 -07:00
)
end},
2019-04-20 16:51:07 -07:00
2020-04-12 11:04:35 -07:00
-- /msg messages
2022-07-30 12:09:47 -07:00
{"^[DP]M from (%S+): (.*)$", function(name, text)
minetest.sound_play("default_place_node_metal")
return ("%s%s%s%s"):format(
colorize(COLOR_BY_STATUS.server, "DM from "),
2020-04-12 11:04:35 -07:00
color_name(name),
2022-07-30 12:09:47 -07:00
colorize(COLOR_BY_STATUS.server, ": "),
colorize(COLOR_BY_STATUS.self, text)
)
end},
2020-04-12 11:04:35 -07:00
2019-04-20 16:51:07 -07:00
-- /tell messages
2022-07-30 12:09:47 -07:00
{"^(%S+) whispers: (.*)$", function(name, text)
minetest.sound_play("default_place_node_metal")
return ("%s%s%s%s"):format(
2019-04-24 16:15:35 -07:00
color_name(name),
2022-07-30 12:09:47 -07:00
colorize(COLOR_BY_STATUS.server, " whispers: "),
colorize(COLOR_BY_STATUS.self, text)
)
end},
2019-04-20 16:51:07 -07:00
2019-04-20 20:48:20 -07:00
-- /who
2022-07-30 12:09:47 -07:00
{"^Players in channel: (.*)$", function(names)
return ("%s%s"):format(
colorize(COLOR_BY_STATUS.server, "Players in channel: "),
color_names(names, ", ")
)
end},
2019-04-20 20:48:20 -07:00
-- /status
2022-07-30 12:09:47 -07:00
{"^# Server: (.*) clients={([^}]*)}(.*)", function(text, names, lastbit)
return ("%s%s%s%s%s%s"):format(
colorize(COLOR_BY_STATUS.server, "# Server: "),
colorize(COLOR_BY_STATUS.server, text),
colorize(COLOR_BY_STATUS.server, " clients={"),
color_names(names, ", "),
colorize(COLOR_BY_STATUS.server, "}"),
colorize(COLOR_BY_STATUS.server, lastbit)
)
end},
-- /status on YL
{"^# Server: (.*) clients: (.*)", function(text, names)
return ("%s%s%s%s"):format(
colorize(COLOR_BY_STATUS.server, "# Server: "),
colorize(COLOR_BY_STATUS.server, text),
colorize(COLOR_BY_STATUS.server, " clients: "),
color_names(names, ", ")
)
end},
2019-04-27 22:44:17 -07:00
-- IRC join messages
2022-07-30 12:09:47 -07:00
{"^%-!%- ([%w_%-]+) joined (.*)$", function(name, rest)
return ("%s%s%s%s"):format(
color_text(name, "-!- "),
2019-04-27 22:44:17 -07:00
color_name(name),
2022-07-30 12:09:47 -07:00
color_text(name, " joined "),
2019-04-27 22:44:17 -07:00
color_text(name, rest)
2022-07-30 12:09:47 -07:00
)
end},
2019-04-27 22:44:17 -07:00
-- IRC part messages
2022-07-30 12:09:47 -07:00
{"^%-!%- ([%w_%-]+) has quit (.*)$", function(name, rest)
return ("%s%s%s%s"):format(
color_text(name, "-!- "),
2019-04-27 22:44:17 -07:00
color_name(name),
2022-07-30 12:09:47 -07:00
color_text(name, " has quit "),
2019-04-27 22:44:17 -07:00
color_text(name, rest)
2022-07-30 12:09:47 -07:00
)
end},
2019-04-27 22:44:17 -07:00
-- IRC part messages
2022-07-30 12:09:47 -07:00
{"^%-!%- ([%w_%-]+) has left (.*)$", function(name, rest)
return ("%s%s%s%s"):format(
color_text(name, "-!- "),
2019-04-27 22:44:17 -07:00
color_name(name),
2022-07-30 12:09:47 -07:00
color_text(name, " has left "),
2019-04-27 22:44:17 -07:00
color_text(name, rest)
2022-07-30 12:09:47 -07:00
)
end},
2019-04-27 22:44:17 -07:00
-- IRC mode messages
2022-07-30 12:09:47 -07:00
{"^%-!%- mode/(.*)$", function(rest)
return colorize(COLOR_BY_STATUS.default, ("^%-!%- mode/%s$"):format(rest))
end},
2019-04-27 22:44:17 -07:00
-- IRC /nick messages
2022-07-30 12:09:47 -07:00
{"^%-!%- (.*) is now known as (.*)$", function(name1, name2)
return ("%s%s%s%s"):format(
color_text(name1, "-!- "),
2019-04-27 22:44:17 -07:00
color_name(name1),
2022-07-30 12:09:47 -07:00
color_text(name2, " is now know as "),
2019-04-27 22:44:17 -07:00
color_name(name2)
2022-07-30 12:09:47 -07:00
)
end},
-- DM sent
{"^[DP]M to (%S+): (.*)$", function(name, text)
return ("%s%s%s%s"):format(
colorize(COLOR_BY_STATUS.server, "DM to "),
color_name(name),
colorize(COLOR_BY_STATUS.server, ": "),
colorize(COLOR_BY_STATUS.server, text)
)
end},
2019-04-24 16:15:35 -07:00
-- BlS moderator PM snooping
2022-07-30 12:09:47 -07:00
{"^([%w_%-]+) to ([%w_%-]+): (.*)$", function(name1, name2, text)
return ("%s%s%s%s%s"):format(
2019-04-24 16:15:35 -07:00
color_name(name1),
2022-07-30 12:09:47 -07:00
colorize(COLOR_BY_STATUS.server, " to "),
2019-04-24 16:15:35 -07:00
color_name(name2),
2022-07-30 12:09:47 -07:00
colorize(COLOR_BY_STATUS.server, ": "),
colorize(COLOR_BY_STATUS.server, text)
)
end},
2019-04-27 22:44:17 -07:00
-- BlS unverified player notice
2022-07-30 12:09:47 -07:00
{"^Player ([%w_%-]+) is unverified%.$", function(name)
minetest.sound_play("default_dug_metal")
return colorize("#FF0000", ("Player %s is unverified."):format(name))
end},
2019-04-27 22:44:17 -07:00
-- BlS unverified player chat
2022-07-30 12:09:47 -07:00
{"^%[unverified] <([^>]+)>%s+(.*)$", function(name, text)
minetest.sound_play("default_dug_metal")
return colorize("#FF0000", ("[unverified] <%s> (%s)$"):format(name, text))
end},
2019-04-27 22:44:17 -07:00
-- BlS cloaked chat
2022-07-30 12:09:47 -07:00
{"^%-Cloaked%-%s+<([^>]+)>%s+(.*)$", function(name, text)
return ("%s%s%s%s %s"):format(
colorize(COLOR_BY_STATUS.server, "-Cloaked- "),
color_text(name, "<"),
2019-04-27 22:44:17 -07:00
color_name(name),
2022-07-30 12:09:47 -07:00
color_text(name, ">"),
2019-04-27 22:44:17 -07:00
color_text(name, text)
2022-07-30 12:09:47 -07:00
)
end},
-- death messages
{"^(%S+) was killed by (%S+), using (.+), near (.+)$", function(victim, killer, weapon, location)
return ("%s%s%s%s%s%s%s"):format(
color_name(victim),
color_text(victim, " was killed by "),
color_name(killer),
color_text(killer, ", using "),
color_text(killer, weapon),
color_text(victim, ", near "),
color_text(victim, location)
)
end},
{"^(%S+) was killed by (.*)$", function(name, text)
return ("%s%s%s"):format(
color_name(name),
color_text(name, " was killed by "),
color_text(name, text)
)
end},
{"^(%S+) should not play with ([^,]+), near ([^%.]+)%.", function(name, what, where)
return ("%s%s%s%s%s%s"):format(
color_name(name),
color_text(name, " should not play with "),
color_text(name, what),
color_text(name, ", near "),
color_text(name, where),
color_text(name, ".")
)
end},
{"^(%S+) shouldn't play with (.*)$", function(name, text)
return ("%s%s%s"):format(
color_name(name),
color_text(name, " shouldn't play with "),
color_text(name, text)
)
end},
{"^(%S+) was killed near (.*)$", function(name, text)
return ("%s%s%s"):format(
color_name(name),
color_text(name, " was killed near "),
color_text(name, text)
)
end},
{"^(%S+) has fallen near (.*)$", function(name, text)
return ("%s%s%s"):format(
color_name(name),
color_text(name, " has fallen near "),
color_text(name, text)
)
end},
{"^(%S+) has drown in ([^,]+), near ([^%.]+)%.", function(name, what, where)
return ("%s%s%s%s%s%s"):format(
color_name(name),
color_text(name, " has drown in "),
color_text(name, what),
color_text(name, ", near "),
color_text(name, where),
color_text(name, ".")
)
end},
{"^(%S+) has drown in (.*)", function(name, what)
return ("%s%s%s%s%s%s"):format(
color_name(name),
color_text(name, " has drown in "),
color_text(name, what),
color_text(name, ", near "),
color_text(name, where),
color_text(name, ".")
)
end},
2019-04-20 20:48:20 -07:00
2019-08-06 18:56:41 -07:00
-- rollback_check messages
2022-07-30 12:09:47 -07:00
{"%((%-?%d+,%-?%d+,%-?%d+)%) player:(%S+) (%S*) %-> (%S*) (%d+) seconds ago%.", function(pos, name, item1, item2, time)
if item1 == "air" then
item1 = colorize("#FF0000", item1)
else
item1 = colorize(COLOR_BY_STATUS.server, item1)
end
if item2 == "air" then
item2 = colorize("#FF0000", item2)
else
item2 = colorize(COLOR_BY_STATUS.server, item2)
end
2019-05-14 16:14:21 -07:00
2022-07-30 12:09:47 -07:00
return ("(%s) player:%s %s -> %s %s ago."):format(
colorize(COLOR_BY_STATUS.server, pos),
2019-05-14 16:14:21 -07:00
color_name(name),
item1,
item2,
seconds_to_interval(tonumber(time))
2022-07-30 12:09:47 -07:00
)
end},
-- YL thankyous
{"^Adventurer (%S+) received a 'Thank you' from (%S+)$", function(name1, name2)
return ("%s%s%s%s"):format(
colorize(COLOR_BY_STATUS.server, "Adventurer "),
color_name(name1),
colorize(COLOR_BY_STATUS.server, " received a 'Thank you' from "),
color_name(name2)
)
end},
-- YL levels
{"^Congratulations, (%S+) reached L(%d+)$", function(name, level)
return ("%s%s%s%s"):format(
colorize(COLOR_BY_STATUS.server, "Congratulations "),
color_name(name),
colorize(COLOR_BY_STATUS.server, " reached L"),
color_text(name, level)
)
end},
}
local last_message = ""
register_on_receive(safe(function(message)
if disabled_servers[server_id] then
return false
end
if message == last_message then
return true
else
last_message = message
end
local msg = minetest.gettext(message)
msg = minetest.strip_colors(msg)
msg = clean_android(msg)
msg = clean_weird_crap(msg)
--log("action", "%q", msg)
if should_ignore(msg) then
2019-05-14 16:14:21 -07:00
return true
end
2022-07-30 12:09:47 -07:00
local date = get_date_string()
for _, stuff in ipairs(t) do
local key, fun = unpack(stuff)
local parts = {msg:match(key)}
if #parts > 0 then
local fmsg = fun(unpack(parts))
if fmsg then
minetest.display_chat_message(("%s %s"):format(date, fmsg))
return true
end
end
end
2019-04-20 16:51:07 -07:00
end))