From f2ae36db6cbd7986a7ad6fb87ce6e0061a3110b6 Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Sat, 30 Jul 2022 12:09:47 -0700 Subject: [PATCH] many updates --- depends.txt | 2 - init.lua | 839 ++++++++++++++++++++++++++++++++-------------------- mod.conf | 2 + 3 files changed, 528 insertions(+), 315 deletions(-) delete mode 100644 depends.txt create mode 100644 mod.conf diff --git a/depends.txt b/depends.txt deleted file mode 100644 index 58ed39d..0000000 --- a/depends.txt +++ /dev/null @@ -1,2 +0,0 @@ -chatlog? -bls_tools? diff --git a/init.lua b/init.lua index fe73fe5..9a6349d 100644 --- a/init.lua +++ b/init.lua @@ -1,31 +1,86 @@ -local mod_name = minetest.get_current_modname() +local register_on_receive = minetest.register_on_receiving_chat_message or minetest.register_on_receiving_chat_messages -local function log(level, message) - minetest.log(level, ('[%s] %s'):format(mod_name, message)) +if not register_on_receive then + return end -log('action', 'CSM loading...') +local colorize = minetest.colorize + +local mod_name = minetest.get_current_modname() + +local function log(level, messagefmt, ...) + minetest.log(level, ("[%s] %s"):format(mod_name, messagefmt:format(...))) +end + +log("action", "CSM loading...") -- configurable values -- +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 + 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 local COLOR_BY_STATUS = { - 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! + 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! -- these can be changed to your liking. -- TODO: make these configurable in game? - admin='#00FFFF', - privileged='#FFFF00', - friend='#00FF00', - contact='#4444FF', - other='#FF00FF', - trouble='#FF0000', + secretz="#000000", + + admin="#88FFFF", + privileged="#00FFFF", + poweruser="#55FFAA", + ally="#00FF55", + friend="#00FF00", + acquaintance="#55FF00", + contact="#AAFF00", + noob="#FFFF00", + trouble="#FF0000", + rival="#FF0088", + other="#FF00FF", } local LIGHTEN_TEXT_BY = .8 -- 0 == same color as status; 1 == pure white. +local DATE_FORMAT = "%Y%m%dT%H%M%S" + -- END configurable values -- -- general functions -- @@ -36,7 +91,7 @@ local function safe(func) if status then return out else - log('warning', 'Error (func): ' .. out) + log("warning", "Error (func): " .. out) return nil end end @@ -92,7 +147,11 @@ local function lighten(hex_color, percent) g = bound(0, round(((1 - percent) * g) + (percent * 255)), 255) b = bound(0, round(((1 - percent) * b) + (percent * 255)), 255) - return ('#%02x%02x%02x'):format(r, g, b) + return ("#%02x%02x%02x"):format(r, g, b) +end + +local function get_date_string() + return os.date(DATE_FORMAT, os.time()) end -- END general functions -- @@ -103,9 +162,9 @@ local mod_storage = minetest.get_mod_storage() local server_id if PER_SERVER then local server_info = minetest.get_server_info() - server_id = server_info.address .. ':' .. server_info.port + server_id = server_info.address .. ":" .. server_info.port else - server_id = '' + server_id = "" end -- -- mod_storage: status_by_name -- -- @@ -115,7 +174,7 @@ local status_by_name local function load_status_by_name() local serialized_storage = mod_storage:get_string(server_id) - if string.find(serialized_storage, 'return') then + if string.find(serialized_storage, "return") then return minetest.deserialize(serialized_storage) else mod_storage:set_string(server_id, minetest.serialize({})) @@ -133,7 +192,7 @@ status_by_name = load_status_by_name() local function get_name_status(name) - return status_by_name[name] or 'default' + return status_by_name[name] or "default" end @@ -150,18 +209,18 @@ local alert_patterns local function load_alert_patterns() - local serialized_storage = mod_storage:get_string(('%s:alert_patterns'):format(server_id)) - if string.find(serialized_storage, 'return') then + local serialized_storage = mod_storage:get_string(("%s:alert_patterns"):format(server_id)) + if string.find(serialized_storage, "return") then return minetest.deserialize(serialized_storage) else - mod_storage:set_string(('%s:alert_patterns'):format(server_id), minetest.serialize({})) + mod_storage:set_string(("%s:alert_patterns"):format(server_id), minetest.serialize({})) return {} end end local function save_alert_patterns() - mod_storage:set_string(('%s:alert_patterns'):format(server_id), minetest.serialize(alert_patterns)) + mod_storage:set_string(("%s:alert_patterns"):format(server_id), minetest.serialize(alert_patterns)) end @@ -188,19 +247,19 @@ local disabled_servers local function load_disabled_servers() - local serialized_storage = mod_storage:get_string('disabled_servers') - if string.find(serialized_storage, 'return') then + local serialized_storage = mod_storage:get_string("disabled_servers") + if string.find(serialized_storage, "return") then return minetest.deserialize(serialized_storage) else - local ds = {['94.16.121.151:2500'] = true } -- disable on IFS by default - mod_storage:set_string('disabled_servers', minetest.serialize(ds)) + local ds = {["94.16.121.151:2500"] = true } -- disable on IFS by default + mod_storage:set_string("disabled_servers", minetest.serialize(ds)) return ds end end local function save_disabled_servers() - mod_storage:set_string('disabled_servers', minetest.serialize(disabled_servers)) + mod_storage:set_string("disabled_servers", minetest.serialize(disabled_servers)) end @@ -230,8 +289,8 @@ local function set_my_name() local name if minetest.localplayer then name = minetest.localplayer:get_name() - log('action', ('you are %s'):format(name)) - set_name_status(name, 'self') + log("action", ("you are %s"):format(name)) + set_name_status(name, "self") if AUTO_ALERT_ON_NAME then add_alert_pattern(name) end @@ -239,7 +298,7 @@ local function set_my_name() set_my_name_tries = set_my_name_tries + 1 minetest.after(1, set_my_name) else - log('warning', 'could not determine name!') + log("warning", "could not determine name!") end end @@ -254,96 +313,96 @@ end -- END initalization -- -- chat commands -- -minetest.register_chatcommand('ch_toggle', { - description = ('turn %s on/off for this server'):format(mod_name), +minetest.register_chatcommand("ch_toggle", { + description = ("turn %s on/off for this server"):format(mod_name), func = safe(function() local current_status = toggle_disable_this_server() if current_status then - current_status = 'off' + current_status = "off" else - current_status = 'on' + current_status = "on" end - minetest.display_chat_message(('%s is now %s for server "%s"'):format(mod_name, current_status, server_id)) + minetest.display_chat_message(("%s is now %s for server "%s""):format(mod_name, current_status, server_id)) end), }) -minetest.register_chatcommand('ch_statuses', { - description = 'list statuses', +minetest.register_chatcommand("ch_statuses", { + description = "list statuses", func = safe(function() for name, color in pairsByKeys(COLOR_BY_STATUS) do if name and color then - minetest.display_chat_message(minetest.colorize(color, ('%s: %s'):format(name, color))) + minetest.display_chat_message(colorize(color, ("%s: %s"):format(name, color))) end end end), }) -minetest.register_chatcommand('ch_set', { - params = ' ', - description = 'associate a name w/ a status', +minetest.register_chatcommand("ch_set", { + params = " ", + description = "associate a name w/ a status", func = safe(function(param) - local name, status = param:match('^(%S+)%s+(%S+)$') + local name, status = param:match("^(%S+)%s+(%S+)$") if name ~= nil then if not COLOR_BY_STATUS[status] then - minetest.display_chat_message(minetest.colorize('#FF0000', ('unknown status "%s"'):format(status))) + minetest.display_chat_message(colorize("#FF0000", ("unknown status \"%s\""):format(status))) return false end set_name_status(name, status) - minetest.display_chat_message(minetest.colorize(COLOR_BY_STATUS[status], ('%s is now %s'):format(name, status))) + minetest.display_chat_message(colorize(COLOR_BY_STATUS[status], ("%s is now %s"):format(name, status))) return true else - minetest.display_chat_message(minetest.colorize('#FF0000', 'invalid syntax')) + minetest.display_chat_message(colorize("#FF0000", "invalid syntax")) return false end end), }) -minetest.register_chatcommand('ch_unset', { - params = '', - description = 'unregister a name', +minetest.register_chatcommand("ch_unset", { + params = "", + description = "unregister a name", func = safe(function(name) set_name_status(name, nil) - minetest.display_chat_message(minetest.colorize(COLOR_BY_STATUS.server, ('unregistered %s'):format(name))) + minetest.display_chat_message(colorize(COLOR_BY_STATUS.server, ("unregistered %s"):format(name))) end), }) -minetest.register_chatcommand('ch_list', { - description = 'list all statuses', +minetest.register_chatcommand("ch_list", { + description = "list all statuses", func = safe(function() for name, status in pairsByKeys(status_by_name, lc_cmp) do local color = COLOR_BY_STATUS[status] or COLOR_BY_STATUS.default - minetest.display_chat_message(minetest.colorize(color, ('%s: %s'):format(name, status))) + minetest.display_chat_message(colorize(color, ("%s: %s"):format(name, status))) end end), }) -minetest.register_chatcommand('ch_alert_list', { - description = 'list all alert patterns', +minetest.register_chatcommand("ch_alert_list", { + description = "list all alert patterns", func = safe(function() for pattern, _ in pairsByKeys(alert_patterns, lc_cmp) do - minetest.display_chat_message(minetest.colorize(COLOR_BY_STATUS.server, pattern)) + minetest.display_chat_message(colorize(COLOR_BY_STATUS.server, pattern)) end end), }) -minetest.register_chatcommand('ch_alert_set', { - params = '', - description = 'alert on a given pattern', +minetest.register_chatcommand("ch_alert_set", { + params = "", + description = "alert on a given pattern", func = safe(function(pattern) add_alert_pattern(pattern) end), }) -minetest.register_chatcommand('ch_alert_unset', { - params = '', - description = 'no longer alert on a given pattern', +minetest.register_chatcommand("ch_alert_unset", { + params = "", + description = "no longer alert on a given pattern", func = safe(function(pattern) remove_alert_pattern(pattern) end), @@ -354,20 +413,27 @@ minetest.register_chatcommand('ch_alert_unset', { local function clean_android(msg) -- supposedly, android surrounds messages with (c@#ffffff) - 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 + 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 msg = msg:sub(-11) end end return msg end +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 local function get_color_by_name(name) local _ - name, _ = name:match('^([^@]+).*$') -- strip @... from IRC users - name, _ = name:match('^([^[]+).*$') -- strip [m] from matrix users + name, _ = name:match("^([^@]+).*$") -- strip @... from IRC users + name, _ = name:match("^([^[]+).*$") -- strip [m] from matrix users local status = get_name_status(name) return COLOR_BY_STATUS[status] or COLOR_BY_STATUS.default @@ -376,15 +442,14 @@ end local function color_name(name) local color = get_color_by_name(name) - return minetest.colorize(color, name) + return colorize(color, name) end local function color_names(names, delim) - local text = '' local sorted_names = {} - for name in names:gmatch('[%w_%-]+') do + for name in names:gmatch("[%w_%-]+") do table.insert(sorted_names, name) end @@ -401,18 +466,18 @@ end local function color_text(name, text) for pattern, _ in pairs(alert_patterns) do if text:lower():match(pattern:lower()) then - minetest.sound_play('default_dug_metal') - return minetest.colorize(COLOR_BY_STATUS.self, text) + minetest.sound_play("default_dug_metal") + return colorize(COLOR_BY_STATUS.self, text) end end local color = get_color_by_name(name) if color == COLOR_BY_STATUS.default then - return minetest.colorize(COLOR_BY_STATUS.default, text) + return colorize(COLOR_BY_STATUS.default, text) else color = lighten(color, LIGHTEN_TEXT_BY) - return minetest.colorize(color, text) + return colorize(color, text) end end @@ -427,262 +492,410 @@ local function seconds_to_interval(time) local m = time % 60; time = idiv(time, 60) local h = time % 24; time = idiv(time, 24) if time ~= 0 then - return ('%d days %02d:%02d:%02d'):format(time, h, m, s) + return ("%d days %02d:%02d:%02d"):format(time, h, m, s) elseif h ~= 0 then - return ('%02d:%02d:%02d'):format(h, m, s) + return ("%02d:%02d:%02d"):format(h, m, s) elseif m ~= 0 then - return ('%02d:%02d'):format(m, s) + return ("%02d:%02d"):format(m, s) else - return ('%d seconds'):format(s) + return ("%d seconds"):format(s) end end +local function sort_privs(text) + local sorted_privs = {} -local register_on_receive = minetest.register_on_receiving_chat_message or minetest.register_on_receiving_chat_messages + for priv in text:gmatch("[%w_%-]+") do + table.insert(sorted_privs, priv) + end + table.sort(sorted_privs, lc_cmp) + + return table.concat(sorted_privs, ", ") +end + +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}, + + -- join/part messages + {"^%*%*%* (%S+) (.*)$", function(name, text) + return ("%s %s %s"):format( + color_text(name, "***"), + color_name(name), + color_text(name, text) + ) + 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}, + + -- normal messages + {"^<([^>%s]+)>%s+(.*)$", function(name, text) + return ("%s%s%s %s"):format( + color_text(name, "<"), + color_name(name), + color_text(name, ">"), + color_text(name, text) + ) + 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}, + + -- prefixed messages + {"^(%S+)%s+<([^>]+)>%s+(.*)$", function(prefix, name, text) + return ("%s %s%s%s %s"):format( + color_text(name, prefix), + color_text(name, "<"), + color_name(name), + color_text(name, ">"), + color_text(name, text) + ) + end}, + + -- Empire of Legends messages + {"^<(%S+)%s+([^>]+)>%s+(.*)$", function(prefix, name, text) + return ("%s%s %s%s %s"):format( + color_text(name, "<"), + color_text(name, prefix), + color_name(name), + color_text(name, ">"), + color_text(name, text) + ) + end}, + + -- /me messages + {"^%* (%S+) (.*)$", function(name, text) + return ("%s %s %s"):format( + color_text(name, "*"), + color_name(name), + color_text(name, text) + ) + end}, + + -- /msg messages + {"^[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 "), + color_name(name), + colorize(COLOR_BY_STATUS.server, ": "), + colorize(COLOR_BY_STATUS.self, text) + ) + end}, + + -- /tell messages + {"^(%S+) whispers: (.*)$", function(name, text) + minetest.sound_play("default_place_node_metal") + return ("%s%s%s%s"):format( + color_name(name), + colorize(COLOR_BY_STATUS.server, " whispers: "), + colorize(COLOR_BY_STATUS.self, text) + ) + end}, + + -- /who + {"^Players in channel: (.*)$", function(names) + return ("%s%s"):format( + colorize(COLOR_BY_STATUS.server, "Players in channel: "), + color_names(names, ", ") + ) + end}, + + -- /status + {"^# 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}, + + -- IRC join messages + {"^%-!%- ([%w_%-]+) joined (.*)$", function(name, rest) + return ("%s%s%s%s"):format( + color_text(name, "-!- "), + color_name(name), + color_text(name, " joined "), + color_text(name, rest) + ) + end}, + + -- IRC part messages + {"^%-!%- ([%w_%-]+) has quit (.*)$", function(name, rest) + return ("%s%s%s%s"):format( + color_text(name, "-!- "), + color_name(name), + color_text(name, " has quit "), + color_text(name, rest) + ) + end}, + + -- IRC part messages + {"^%-!%- ([%w_%-]+) has left (.*)$", function(name, rest) + return ("%s%s%s%s"):format( + color_text(name, "-!- "), + color_name(name), + color_text(name, " has left "), + color_text(name, rest) + ) + end}, + + -- IRC mode messages + {"^%-!%- mode/(.*)$", function(rest) + return colorize(COLOR_BY_STATUS.default, ("^%-!%- mode/%s$"):format(rest)) + end}, + + -- IRC /nick messages + {"^%-!%- (.*) is now known as (.*)$", function(name1, name2) + return ("%s%s%s%s"):format( + color_text(name1, "-!- "), + color_name(name1), + color_text(name2, " is now know as "), + color_name(name2) + ) + 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}, + + -- BlS moderator PM snooping + {"^([%w_%-]+) to ([%w_%-]+): (.*)$", function(name1, name2, text) + return ("%s%s%s%s%s"):format( + color_name(name1), + colorize(COLOR_BY_STATUS.server, " to "), + color_name(name2), + colorize(COLOR_BY_STATUS.server, ": "), + colorize(COLOR_BY_STATUS.server, text) + ) + end}, + + -- BlS unverified player notice + {"^Player ([%w_%-]+) is unverified%.$", function(name) + minetest.sound_play("default_dug_metal") + return colorize("#FF0000", ("Player %s is unverified."):format(name)) + end}, + + -- BlS unverified player chat + {"^%[unverified] <([^>]+)>%s+(.*)$", function(name, text) + minetest.sound_play("default_dug_metal") + return colorize("#FF0000", ("[unverified] <%s> (%s)$"):format(name, text)) + end}, + + -- BlS cloaked chat + {"^%-Cloaked%-%s+<([^>]+)>%s+(.*)$", function(name, text) + return ("%s%s%s%s %s"):format( + colorize(COLOR_BY_STATUS.server, "-Cloaked- "), + color_text(name, "<"), + color_name(name), + color_text(name, ">"), + color_text(name, text) + ) + 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}, + + -- rollback_check messages + {"%((%-?%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 + + return ("(%s) player:%s %s -> %s %s ago."):format( + colorize(COLOR_BY_STATUS.server, pos), + color_name(name), + item1, + item2, + seconds_to_interval(tonumber(time)) + ) + 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 = "" -if register_on_receive then register_on_receive(safe(function(message) if disabled_servers[server_id] then return false end - local msg = clean_android(minetest.strip_colors(message)) + if message == last_message then + return true + else + last_message = message + end - -- join/part messages - local name, text = msg:match('^%*%*%* (%S+) (.*)$') - if name and text then - minetest.display_chat_message(('%s %s %s'):format( - color_text(name, '***'), - color_name(name), - color_text(name, text) - )) + 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 return true end - -- normal messages - local name, text = msg:match('^<([^>%s]+)>%s+(.*)$') - if name and text then - minetest.display_chat_message(('%s%s%s %s'):format( - color_text(name, '<'), - color_name(name), - color_text(name, '>'), - color_text(name, text) - )) - return true + 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 - - -- prefixed messages - local prefix, name, text = msg:match('^(%S+)%s+<([^>]+)>%s+(.*)$') - if name and text then - minetest.display_chat_message(('%s %s%s%s %s'):format( - color_text(name, prefix), - color_text(name, '<'), - color_name(name), - color_text(name, '>'), - color_text(name, text) - )) - return true - end - - -- Empire of Legends messages - local prefix, name, text = msg:match('^<(%S+)%s+([^>]+)>%s+(.*)$') - if name and text then - minetest.display_chat_message(('%s%s %s%s %s'):format( - color_text(name, '<'), - color_text(name, prefix), - color_name(name), - color_text(name, '>'), - color_text(name, text) - )) - return true - end - - -- /me messages - local name, text = msg:match('^%* (%S+) (.*)$') - if name and text then - minetest.display_chat_message(('%s %s %s'):format( - color_text(name, '*'), - color_name(name), - color_text(name, text) - )) - return true - end - - -- /msg messages - local name, text = msg:match('^PM from (%S+): (.*)$') - if name and text then - minetest.display_chat_message(('%s%s%s%s'):format( - minetest.colorize(COLOR_BY_STATUS.server, 'PM from '), - color_name(name), - minetest.colorize(COLOR_BY_STATUS.server, ': '), - minetest.colorize(COLOR_BY_STATUS.self, text) - )) - minetest.sound_play('default_place_node_metal') - return true - end - - -- /msg messages - local name, text = msg:match('^DM from (%S+): (.*)$') - if name and text then - minetest.display_chat_message(('%s%s%s%s'):format( - minetest.colorize(COLOR_BY_STATUS.server, 'DM from '), - color_name(name), - minetest.colorize(COLOR_BY_STATUS.server, ': '), - minetest.colorize(COLOR_BY_STATUS.self, text) - )) - minetest.sound_play('default_place_node_metal') - return true - end - - -- /tell messages - local name, text = msg:match('^(%S+) whispers: (.*)$') - if name and text then - minetest.display_chat_message(('%s%s%s%s'):format( - color_name(name), - minetest.colorize(COLOR_BY_STATUS.server, ' whispers: '), - minetest.colorize(COLOR_BY_STATUS.self, text) - )) - minetest.sound_play('default_place_node_metal') - return true - end - - -- /who - local names = msg:match('^Players in channel: (.*)$') - if names then - minetest.display_chat_message(('%s%s'):format( - minetest.colorize(COLOR_BY_STATUS.server, 'Players in channel: '), - color_names(names, ', ') - )) - return true - end - - -- /status - local text, names, lastbit = msg:match('^# Server: (.*) clients={([^}]*)}(.*)') - if text and names then - minetest.display_chat_message(('%s%s%s%s%s%s'):format( - minetest.colorize(COLOR_BY_STATUS.server, '# Server: '), - minetest.colorize(COLOR_BY_STATUS.server, text), - minetest.colorize(COLOR_BY_STATUS.server, ' clients={'), - color_names(names, ', '), - minetest.colorize(COLOR_BY_STATUS.server, '}'), - minetest.colorize(COLOR_BY_STATUS.server, lastbit) - )) - return true - end - - -- IRC join messages - local name, rest = msg:match('^%-!%- ([%w_%-]+) joined (.*)$') - if name and rest then - minetest.display_chat_message(('%s%s%s%s'):format( - color_text(name, '-!- '), - color_name(name), - color_text(name, ' joined '), - color_text(name, rest) - )) - return true - end - - -- IRC part messages - local name, rest = msg:match('^%-!%- ([%w_%-]+) has quit (.*)$') - if name and rest then - minetest.display_chat_message(('%s%s%s%s'):format( - color_text(name, '-!- '), - color_name(name), - color_text(name, ' has quit '), - color_text(name, rest) - )) - return true - end - - -- IRC part messages - local name, rest = msg:match('^%-!%- ([%w_%-]+) has left (.*)$') - if name and rest then - minetest.display_chat_message(('%s%s%s%s'):format( - color_text(name, '-!- '), - color_name(name), - color_text(name, ' has left '), - color_text(name, rest) - )) - return true - end - - -- IRC mode messages - local rest = msg:match('^%-!%- mode/(.*)$') - if rest then - minetest.display_chat_message(minetest.colorize(COLOR_BY_STATUS.default, msg)) - return true - end - - -- IRC /nick messages - local name1, name2 = msg:match('^%-!%- (.*) is now known as (.*)$') - if name1 and name2 then - minetest.display_chat_message(('%s%s%s%s'):format( - color_text(name1, '-!- '), - color_name(name1), - color_text(name2, ' is now know as '), - color_name(name2) - )) - return true - end - - -- BlS moderator PM snooping - local name1, name2, text = msg:match('^([%w_%-]+) to ([%w_%-]+): (.*)$') - if name1 and name2 and text then - minetest.display_chat_message(('%s%s%s%s%s'):format( - color_name(name1), - minetest.colorize(COLOR_BY_STATUS.server, ' to '), - color_name(name2), - minetest.colorize(COLOR_BY_STATUS.server, ': '), - minetest.colorize(COLOR_BY_STATUS.server, text) - )) - return true - end - - -- BlS unverified player notice - local name = msg:match('^Player ([%w_%-]+) is unverified%.$') - if name then - minetest.display_chat_message(minetest.colorize('#FF0000', msg)) - minetest.sound_play('default_dug_metal') - return true - end - - -- BlS unverified player chat - local name, text = msg:match('^%[unverified] <([^>]+)>%s+(.*)$') - if name and text then - minetest.display_chat_message(minetest.colorize('#FF0000', msg)) - minetest.sound_play('default_dug_metal') - return true - end - - -- BlS cloaked chat - local name, text = msg:match('^%-Cloaked%-%s+<([^>]+)>%s+(.*)$') - if name and text then - minetest.display_chat_message(('%s%s%s%s %s'):format( - minetest.colorize(COLOR_BY_STATUS.server, '-Cloaked- '), - color_text(name, '<'), - color_name(name), - color_text(name, '>'), - color_text(name, text) - )) - return true - end - - -- rollback_check messages - local pos, name, item1, item2, time = msg:match('%((%-?%d+,%-?%d+,%-?%d+)%) player:(%S+) (%S*) %-> (%S*) (%d+) seconds ago%.') - if pos and name and item1 and item2 and time then - if item1 == 'air' then item1 = minetest.colorize('#FF0000', item1) else item1 = minetest.colorize(COLOR_BY_STATUS.server, item1) end - if item2 == 'air' then item2 = minetest.colorize('#FF0000', item2) else item2 = minetest.colorize(COLOR_BY_STATUS.server, item2) end - - minetest.display_chat_message(('(%s) player:%s %s -> %s %s ago.'):format( - minetest.colorize(COLOR_BY_STATUS.server, pos), - color_name(name), - item1, - item2, - seconds_to_interval(tonumber(time)) - )) - return true - end - end)) -end diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..04fd720 --- /dev/null +++ b/mod.conf @@ -0,0 +1,2 @@ +name = chat_highlights +option_depends = chatlog