From 41bc1562ff64b9a66d7e52286a2e262e7eb28e80 Mon Sep 17 00:00:00 2001 From: cron Date: Tue, 6 Oct 2020 02:48:02 +0000 Subject: [PATCH] hignore: create highlight/ignore player messages clientmod --- clientmods/hignore/init.lua | 147 ++++++++++++++++++++++++++++++++++++ clientmods/hignore/mod.conf | 2 + clientmods/mods.conf | 1 + 3 files changed, 150 insertions(+) create mode 100644 clientmods/hignore/init.lua create mode 100644 clientmods/hignore/mod.conf diff --git a/clientmods/hignore/init.lua b/clientmods/hignore/init.lua new file mode 100644 index 000000000..80e393d03 --- /dev/null +++ b/clientmods/hignore/init.lua @@ -0,0 +1,147 @@ +-- CC0/Unlicense system32 2020 + +local storage = minetest.get_mod_storage() + +local function storage_init_table(key) + minetest.log("init key: " .. key .. " value: " .. storage:get_string(key)) + if storage:get(key) == nil or storage:get(key) == "null" then + storage:set_string(key, "{}") + end + + return minetest.parse_json(storage:get_string(key)) +end + +local function storage_save_json(key, value) + minetest.log("get key: " .. key .. " value: " .. storage:get_string(key)) + storage:set_string(key, minetest.write_json(value)) + minetest.log("save key: " .. key .. " value: " .. storage:get_string(key)) +end + + +-- public interface +hignore = {} + +-- name: color +hignore.highlight = storage_init_table("hignore_highlight") + +-- name: mode +hignore.ignore = storage_init_table("hignore_ignore") + + +function hignore.save() + storage_save_json("hignore_highlight", hignore.higlight) + storage_save_json("hignore_ignore", hignore.ignore) +end + + +local function localize_player(player) + local info = minetest.get_server_info() + + local name = info.ip + if info.address ~= "" then + name = info.address + end + + return player .. "@" .. info.ip .. ":" .. info.port +end + + +minetest.register_on_receiving_chat_message(function(message) + local dm = message:match(".*rom (.*): .*") + local pub = message:match("<(.*)>.*") + + local player = dm or pub + + if player then + player = localize_player(dm or pub) + end + + if hignore.ignore[player] then + if hignore.ignore[player] == "summarize" then + minetest.display_chat_message(player .. " sent a message.") + end + return true + elseif hignore.highlight[player] then + minetest.display_chat_message(minetest.colorize(hignore.highlight[player], message)) + return true + end +end) + + +local function noplayer() + minetest.display_chat_message("No player specified.") +end + +local function string_table(t) + local out = "" + for k, v in pairs(t) do + if out ~= "" then + out = out .. ", " .. tostring(k) .. ": " .. tostring(v) + else + out = tostring(k) .. ": " .. tostring(v) + end + end + + if out == "" then + return "Empty" + else + return out + end +end + + +minetest.register_chatcommand("ignore", { + params = " ", + description = "Ignore a player's messages, mode can be omitted (hide) or hide/summarize/none (stops ignoring).", + func = function(params) + local plist = string.split(params, " ") + if plist[1] == nil then + noplayer() + return + end + + local player = localize_player(plist[1]) + local val = plist[2] + + -- hide/summarize are already set + if plist[2] == nil then + val = "hide" + elseif plist[2] == "none" then + val = nil + end + + hignore.ignore[player] = val + hignore.save() + end +}) + +minetest.register_chatcommand("ignore_list", { + description = "List ignored players.", + func = function(params) + minetest.display_chat_message(string_table(hignore.ignore)) + end +}) + +minetest.register_chatcommand("highlight", { + params = " ", + description = "Highlight a player's messages, omit color to stop highlighting. Supports CSS and RGBA hex colors.", + func = function(params) + local plist = string.split(params, " ") + if plist[1] == nil then + noplayer() + return + end + + local player = localize_player(plist[1]) + + hignore.highlight[player] = plist[2] + hignore.save() + end +}) + +minetest.register_chatcommand("highlight_list", { + description = "List highlighted players.", + func = function(params) + minetest.display_chat_message(string_table(hignore.highlight)) + end +}) diff --git a/clientmods/hignore/mod.conf b/clientmods/hignore/mod.conf new file mode 100644 index 000000000..13c802484 --- /dev/null +++ b/clientmods/hignore/mod.conf @@ -0,0 +1,2 @@ +name = hignore +description = Highlight/ignore player chat messages and DMs. diff --git a/clientmods/mods.conf b/clientmods/mods.conf index d3906fa2b..bf21688ab 100644 --- a/clientmods/mods.conf +++ b/clientmods/mods.conf @@ -23,3 +23,4 @@ load_mod_itemcount = false load_mod_pathfinding = true load_mod_autoeat = true load_mod_perlin = true +load_mod_hignore = true