mirror of
https://github.com/Earu/EasyChat.git
synced 2025-03-04 03:13:20 -05:00
Add a way to block words in the chat
This commit is contained in:
parent
62418df935
commit
dc8241ad31
@ -143,6 +143,49 @@ local function create_default_settings()
|
||||
build_blocked_players_list()
|
||||
end
|
||||
|
||||
local setting_blocked_strings = settings:AddSetting(category_name, "list", "Blocked Words")
|
||||
local blocked_strings_list = setting_blocked_strings.List
|
||||
blocked_strings_list:SetMultiSelect(true)
|
||||
blocked_strings_list:AddColumn("Id")
|
||||
blocked_strings_list:AddColumn("Content")
|
||||
blocked_strings_list:AddColumn("Pattern")
|
||||
|
||||
local function build_blocked_strings_list()
|
||||
blocked_strings_list:Clear()
|
||||
for i = 1, #EasyChat.BlockedStrings do
|
||||
local blocked_str = EasyChat.BlockedStrings[i]
|
||||
blocked_strings_list:AddLine(tostring(i), blocked_str.Content, tostring(blocked_str.IsPattern))
|
||||
end
|
||||
end
|
||||
|
||||
build_blocked_strings_list()
|
||||
|
||||
local setting_block_string = settings:AddSetting(category_name, "action", "Block Word")
|
||||
setting_block_string.DoClick = function()
|
||||
local frame
|
||||
frame = EasyChat.AskForInput("Block a word", function(str)
|
||||
EasyChat.BlockString(str, frame.IsPattern:GetChecked())
|
||||
build_blocked_strings_list()
|
||||
end, false)
|
||||
|
||||
frame:SetTall(125)
|
||||
frame.IsPattern = frame:Add("DCheckBoxLabel")
|
||||
frame.IsPattern:SetText("Pattern")
|
||||
frame.IsPattern:Dock(FILL)
|
||||
end
|
||||
|
||||
local setting_unblock_string = settings:AddSetting(category_name, "action", "Unblock Word")
|
||||
setting_unblock_string.DoClick = function()
|
||||
local lines = blocked_strings_list:GetSelected()
|
||||
for _, line in pairs(lines) do
|
||||
local id = tonumber(line:GetColumnText(1))
|
||||
if not id then continue end
|
||||
EasyChat.UnblockString(id)
|
||||
end
|
||||
|
||||
build_blocked_strings_list()
|
||||
end
|
||||
|
||||
settings:AddSpacer(category_name)
|
||||
|
||||
local setting_secondary_mode = settings:AddConvarSetting(category_name, "string", EC_SECONDARY, "Secondary Message Mode")
|
||||
|
@ -422,7 +422,7 @@ function SETTINGS:AddCategory(category_name, icon)
|
||||
if not EasyChat.UseDermaSkin then
|
||||
panel.Paint = function() end
|
||||
|
||||
local scrollbar = panel:GetVBar()
|
||||
--[[local scrollbar = panel:GetVBar()
|
||||
scrollbar:SetHideButtons(true)
|
||||
scrollbar.Paint = function(self, w, h)
|
||||
surface.SetDrawColor(EasyChat.OutlayColor)
|
||||
@ -433,7 +433,7 @@ function SETTINGS:AddCategory(category_name, icon)
|
||||
local outlay_col = EasyChat.OutlayColor
|
||||
surface.SetDrawColor(outlay_col.r, outlay_col.g, outlay_col.b, 150)
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
end
|
||||
end]]--
|
||||
end
|
||||
|
||||
local new_category = self.Categories:AddSheet(category_name, panel)
|
||||
|
@ -283,6 +283,7 @@ end
|
||||
|
||||
if CLIENT then
|
||||
local BLOCKED_PLAYERS_PATH = "easychat/blocked_players.json"
|
||||
local BLOCKED_STRINGS_PATH = "easychat/BLOCKED_STRINGS.json"
|
||||
|
||||
-- translation
|
||||
local EC_TRANSLATE_INC_MSG = CreateConVar("easychat_translate_inc_msg", "0", FCVAR_ARCHIVE, "Translates incoming chat messages")
|
||||
@ -302,6 +303,48 @@ if CLIENT then
|
||||
return false
|
||||
end
|
||||
|
||||
local BLOCKED_STRINGS = file.Read(BLOCKED_STRINGS_PATH, "DATA") or ""
|
||||
EasyChat.BlockedStrings = util.JSONToTable(BLOCKED_STRINGS) or {}
|
||||
|
||||
function EasyChat.BlockString(word, is_pattern)
|
||||
table.insert(EasyChat.BlockedStrings, {
|
||||
Content = word,
|
||||
IsPattern = is_pattern or false
|
||||
})
|
||||
|
||||
file.Write(BLOCKED_STRINGS_PATH, util.TableToJSON(EasyChat.BlockedStrings))
|
||||
end
|
||||
|
||||
function EasyChat.UnblockString(id)
|
||||
table.remove(EasyChat.BlockedStrings, id)
|
||||
file.Write(BLOCKED_STRINGS_PATH, util.TableToJSON(EasyChat.BlockedStrings))
|
||||
end
|
||||
|
||||
function EasyChat.FilterString(str)
|
||||
local original_str = str
|
||||
local _, original_count = str:gsub("%*", "*")
|
||||
|
||||
str = util.FilterText(ec_markup.GetText(str)) -- respect the Steam filter settings
|
||||
|
||||
for _, blocked_str in ipairs(EasyChat.BlockedStrings) do
|
||||
local content = blocked_str.Content
|
||||
if not blocked_str.IsPattern then
|
||||
content = blocked_str.Content:PatternSafe()
|
||||
end
|
||||
|
||||
str = str:gsub(content, function(match)
|
||||
return ("*"):rep(#match)
|
||||
end)
|
||||
end
|
||||
|
||||
local _, final_count = str:gsub("%*", "*")
|
||||
if final_count ~= original_count then
|
||||
return str
|
||||
end
|
||||
|
||||
return original_str
|
||||
end
|
||||
|
||||
function EasyChat.ReceiveGlobalMessage(ply, msg, is_dead, is_team, is_local)
|
||||
if EasyChat.IsBlockedPlayer(ply) then return end
|
||||
|
||||
@ -313,6 +356,8 @@ if CLIENT then
|
||||
local only_local = GetConVar("easychat_only_local")
|
||||
if only_local and only_local:GetBool() and not is_local then return end
|
||||
|
||||
msg = EasyChat.FilterString(msg)
|
||||
|
||||
local source_lang, target_lang =
|
||||
EC_TRANSLATE_INC_SRC_LANG:GetString(),
|
||||
EC_TRANSLATE_INC_TARGET_LANG:GetString()
|
||||
|
Loading…
Reference in New Issue
Block a user