From 9b5c78e90c4bf3503ceff697a380cd0ca3f5885d Mon Sep 17 00:00:00 2001 From: "Erik L. Vonderscheer" Date: Thu, 16 Jul 2009 02:35:12 +0000 Subject: [PATCH] Rewrite on DB functions, Repeat Function and Friends functions Show repeat count with ability to reset count Ability to enable/disable Black and White list checking Debug: Black and White list debugging messages contain whitespaces Debug: Black and White list debugging messages now show what they matched in your pattern list Debug: Option to strip "Checking for Match" when debugging --- Docs/main.txt | 20 +++-- TradeFilter3.lua | 183 +++++++++++++++++++++++++++++------------- TradeFilter3Options.lua | 203 ++++++++++++++++++++++++++++------------------- 3 files changed, 265 insertions(+), 141 deletions(-) diff --git a/Docs/main.txt b/Docs/main.txt index 2e6abdc..2240e39 100644 --- a/Docs/main.txt +++ b/Docs/main.txt @@ -47,8 +47,15 @@ The filtering priorities are as follows: Add-on is ON -> is NOT friend -> is NO Nothing planned ==== ChangeLog +*r145 +**++Rewrite on DB functions, Repeat Function and Friends functions++\\ +**++Show repeat count with ability to reset count++\\ +**++Ability to enable/disable Black and White list checking++\\ +**++Debug: Black and White list debugging messages contain whitespaces++\\ +**++Debug: Black and White list debugging messages now show what they matched in your pattern list++\\ +**++Debug: Option to strip "Checking for Match" when debugging++\\ *r144 -**++Further Debug output cleanup++\\ +**++Debug: Further Debug output cleanup++\\ **++Better repeat detection++\\ **++Whitelisted strings still have to pass repeat test++\\ **++Whitelisted strings also needs to pass Blacklist++\\ @@ -56,7 +63,7 @@ Nothing planned **++Typo causing reset buttons to error out fixed++\\ **++Added all strings to locale++\\ **++Keys are no longer necessary when adding filter or list patterns++\\ -**++Cleaned up debugging output, will now show what pattern that was matched to allow it to not be filtered++\\ +**++Debug: Cleaned up debugging output, will now show what pattern that was matched to allow it to not be filtered++\\ *r131 **++Repeat filtration++\\ **++Configurable number of repeats before filtered++\\ @@ -73,7 +80,8 @@ Nothing planned === Supported Translations //Please help localize this project// [[http://www.wowace.com/projects/trade-filter/localization/|HERE]]\\ -German - 93.3%\\ -Simplified Chinese - 46.7%\\ -Traditional Chinese - 24.8%\\ -French - 27.6% +German - 92.1%\\ +French - 64.9%\\ +Simplified Chinese - 43%\\ +Traditional Chinese - 22.8%\\ +Korean - 19.3%\\ diff --git a/TradeFilter3.lua b/TradeFilter3.lua index 97c7a87..be19047 100644 --- a/TradeFilter3.lua +++ b/TradeFilter3.lua @@ -74,7 +74,10 @@ defaults = { filterTrade = true, editfilter_enable = false, editlists_enable = false, - repeat_enable = false, + blacklist_enable = true, + whitelist_enable = true, + redirect_blacklist = false, + repeat_enable = true, num_repeats = "2", time_repeats = "30", repeats_blocked = 0, @@ -139,36 +142,54 @@ function TF3:IsLoggedIn() friends.RegisterCallback(self, "Added") friends.RegisterCallback(self, "Removed") self:UnregisterEvent("PLAYER_LOGIN") - self:UnregisterEvent("FRIENDLIST_UPDATE") end ---[[ Friends Functions - Borrowed from AuldLangSyne Sync module ]]-- +--[[ DB Functions ]]-- +function TF3:WipeTable(tbl) + if tbl ~= nil and type(tbl) == "table" then + wipe(tbl) + end +end + +function TF3:CopyTable(tbl) + local new_tbl = {} + for k, v in pairs(tbl) do + if (type(v) == "table") then + new_tbl[k] = copyTable(v) + else + new_tbl[k] = v + end + end + return new_tbl +end + +--[[ Friends Functions ]]-- function TF3:GetFriends() - local friends = self.db.profile.friendslist + local friends = TF3.db.profile.friendslist local numFriends = GetNumFriends() - if #friendCache ~= numFriends then + if (#friends ~= numFriends) then + print(L["TFFR"]) + TF3:WipeTable(friends) for i=1, numFriends do local name = GetFriendInfo(i) if name then - friends[name] = true - print(name .. " " .. L["FADD"]) + friends[i] = name + if (TF3.db.profile.debug) then + print("|cFFFFFF80" .. name .. " " .. L["FADD"] .. "|r") + end end end end - self:StopGet() -end - -function TF3:StopGet() - for name in pairs(friendCache) do - friendCache[name] = nil - end - currentFriend = nil + self:UnregisterEvent("FRIENDLIST_UPDATE") end function TF3:Added(event, name) + local friends = TF3.db.profile.friendslist if name ~= UnitName("player") then - self.db.profile.friendslist[name] = true - print(name .. " " .. L["FADD"]) + friends[#friends + 1] = name + if (TF3.db.profile.debug) then + print("|cFFFFFF80" .. name .. " " .. L["FADD"] .. "|r") + end end if currentFriend then self:GetFriends() @@ -176,9 +197,16 @@ function TF3:Added(event, name) end function TF3:Removed(event, name) - if self.db.profile.friendslist[name] ~= nil then - self.db.profile.friendslist[name] = nil - print(name .. " " .. L["FREM"]) + local friends = TF3.db.profile.friendslist + if friends ~= nil then + for k,v in ipairs(friends) do + if find(name,v) then + friends[k] = nil + if (TF3.db.profile.debug) then + print("|cFFFFFF80" .. name .. " " .. L["FREM"] .. "|r") + end + end + end end if currentFriend then self:GetFriends() @@ -188,7 +216,7 @@ end --[[ IsFriend Func ]]-- function TF3:IsFriend(userID) local friends = self.db.profile.friendslist - for name in pairs(friends) do + for _,name in ipairs(friends) do if find(userID,name) then return true end @@ -197,22 +225,33 @@ function TF3:IsFriend(userID) end --[[ BlackList Func ]]-- ---[[ Base blacklist words borrowed from BadBoy(Funkydude) ]]-- +--[[ Base blacklist words from BadBoy(Funkydude) ]]-- function TF3:BlackList(msg, userID, msgID) local blword = self.db.profile.blacklist local msg = lower(msg) - local msg = sub(msg, " ", "") - for _,word in pairs(blword) do - if (find(msg,word)) then - --@alpha@ - if (TF3.db.profile.debug) then - if (msgID ~= lastmsgID) then - TF3:FindFrame(debugFrame, "|cFFFF0000[" .. L["bLists"] .. "]|r |cFFD9D9D9[" .. userID .. "]:|r |cFFC08080" .. msg .. "|r") - lastmsgID = msgID + if (TF3.db.profile.blacklist_enable) then + for _,word in pairs(blword) do + if (find(msg,word)) then + --@alpha@ + if (TF3.db.profile.debug) then + if (msgID ~= lastmsgID) then + TF3:FindFrame(debugFrame, "|cFFFF0000[" .. L["bLists"] .. "]|r |cFFD9D9D9[" .. userID .. "]:|r |cFFC08080" .. msg .. "|r") + TF3:FindFrame(debugFrame, L["MATCHED"] .. " |cFFFF0000" .. word .. "|r") + if not (TF3.db.profile.redirect_blacklist) then + lastmsgID = msgID + end + end end + --@end-alpha@ + if (TF3.db.profile.redirect_blacklist) then + if (msgID ~= lastmsgID) then + TF3:FindFrame(redirectFrame, "|cFFFF0000[" .. L["bLists"] .. "]|r |cFFD9D9D9[" .. userID .. "]:|r |cFFC08080" .. msg .. "|r") + TF3:FindFrame(redirectFrame, L["MATCHED"] .. " |cFFFF0000" .. word .. "|r") + lastmsgID = msgID + end + end + return true end - --@end-alpha@ - return true end end return false @@ -222,18 +261,20 @@ end function TF3:WhiteList(msg, userID, msgID) local wlword = self.db.profile.whitelist local msg = lower(msg) - local msg = sub(msg, " ", "") - for _,word in pairs(wlword) do - if (find(msg,word) and TF3:FindRepeat(msg, userID, msgID) == false and TF3:BlackList(msg, userID, msgID) == false) then - --@alpha@ - if (TF3.db.profile.debug) then - if (msgID ~= lastmsgID) then - TF3:FindFrame(debugFrame, "|cFFFFFF80[" .. L["wLists"] .. "]|r |cFFD9D9D9[" .. userID .. "]:|r |cFFC08080" .. msg .. "|r") - lastmsgID = msgID + if (TF3.db.profile.whitelist_enable) then + for _,word in pairs(wlword) do + if (find(msg,word) and TF3:FindRepeat(msg, userID, msgID) == false and TF3:BlackList(msg, userID, msgID) == false) then + --@alpha@ + if (TF3.db.profile.debug) then + if (msgID ~= lastmsgID) then + TF3:FindFrame(debugFrame, "|cFFFFFF80[" .. L["wLists"] .. "]|r |cFFD9D9D9[" .. userID .. "]:|r |cFFC08080" .. msg .. "|r") + TF3:FindFrame(debugFrame, L["MATCHED"] .. " |cFFFFFF80" .. word .. "|r") + lastmsgID = msgID + end end + --@end-alpha@ + return true end - --@end-alpha@ - return true end end return false @@ -257,7 +298,7 @@ function TF3:FindRepeat(msg, userID, msgID) return true end elseif (msg ~= repeatdata[userID].lastmsg) then - repeatdata[userID].repeats = 0 + repeatdata[userID].repeats = 1 end repeatdata[userID].lastmsg = msg repeatdata[userID].lastmsgID = msgID @@ -344,9 +385,18 @@ local function PreFilterFunc_Yell(self, event, ...) repeatdata[userID].repeats = 1 end if (event == "CHAT_MSG_YELL" and TF3.db.profile.filterYELL and TF3:IsFriend(userID) == false) then - if (userID == UnitName("Player") and TF3.db.profile.filterSELF == false or TF3:WhiteList(msg, userID) == true) then + if (userID == UnitName("Player") and TF3.db.profile.filterSELF == false) then filtered = false - elseif (TF3:BlackList(msg, userID) == true) then + elseif (TF3:WhiteList(msg, userID, msgID) == true) then + if (TF3.db.profile.repeat_enable) then + if (TF3:FindRepeat(msg, userID, msgID) == true) then + filtered = true + else + filtered = false + end + end + filtered = false + elseif (TF3:BlackList(msg, userID, msgID) == true) then filtered = true elseif (TF3.db.profile.repeat_enable) then if (TF3:FindRepeat(msg, userID, msgID) == true) then @@ -380,9 +430,18 @@ local function PreFilterFunc(self, event, ...) end --[[ Check for Trade Channel and User setting ]]-- if (zoneID == 2 and TF3.db.profile.filtertrade and TF3:IsFriend(userID) == false) then - if (userID == UnitName("Player") and TF3.db.profile.filterSELF == false or TF3:WhiteList(msg, userID) == true) then + if (userID == UnitName("Player") and TF3.db.profile.filterSELF == false) then + filtered = false + elseif (TF3:WhiteList(msg, userID, msgID) == true) then + if (TF3.db.profile.repeat_enable) then + if (TF3:FindRepeat(msg, userID, msgID) == true) then + filtered = true + else + filtered = false + end + end filtered = false - elseif (TF3:BlackList(msg, userID) == true) then + elseif (TF3:BlackList(msg, userID, msgID) == true) then filtered = true elseif (TF3.db.profile.repeat_enable) then if (TF3:FindRepeat(msg, userID, msgID) == true) then @@ -398,9 +457,18 @@ local function PreFilterFunc(self, event, ...) end --[[ Check for General Channel and User setting ]]-- if (chanID == 1 and TF3.db.profile.filtergeneral and TF3:IsFriend(userID) == false) then - if (userID == UnitName("Player") and TF3.db.profile.filterSELF == false or TF3:WhiteList(msg, userID) == true) then + if (userID == UnitName("Player") and TF3.db.profile.filterSELF == false) then + filtered = false + elseif (TF3:WhiteList(msg, userID, msgID) == true) then + if (TF3.db.profile.repeat_enable) then + if (TF3:FindRepeat(msg, userID, msgID) == true) then + filtered = true + else + filtered = false + end + end filtered = false - elseif (TF3:BlackList(msg, userID) == true) then + elseif (TF3:BlackList(msg, userID, msgID) == true) then filtered = true elseif (TF3.db.profile.repeat_enable) then if (TF3:FindRepeat(msg, userID, msgID) == true) then @@ -416,9 +484,18 @@ local function PreFilterFunc(self, event, ...) end --[[ Check for LFG Channel and User setting ]]-- if (zoneID == 26 and TF3.db.profile.filterLFG and TF3:IsFriend(userID) == false) then - if (userID == UnitName("Player") and TF3.db.profile.filterSELF == false or TF3:WhiteList(msg, userID) == true) then + if (userID == UnitName("Player") and TF3.db.profile.filterSELF == false) then filtered = false - elseif (TF3:BlackList(msg, userID) == true) then + elseif (TF3:WhiteList(msg, userID, msgID) == true) then + if (TF3.db.profile.repeat_enable) then + if (TF3:FindRepeat(msg, userID, msgID) == true) then + filtered = true + else + filtered = false + end + end + filtered = false + elseif (TF3:BlackList(msg, userID, msgID) == true) then filtered = true elseif (TF3.db.profile.repeat_enable) then if (TF3:FindRepeat(msg, userID, msgID) == true) then @@ -464,7 +541,7 @@ function TF3:FilterFunc(...) if (zoneID == 2) then for i,v in pairs(TF3.db.profile.filters.TRADE) do --@alpha@ - if (TF3.db.profile.debug) then + if (TF3.db.profile.debug and not TF3.db.profile.debug_checking) then if (lastmsg ~= msg or lastuserID ~= userID) then TF3:FindFrame(debugFrame, L["CFM"] .. " " .. v) end @@ -485,7 +562,7 @@ function TF3:FilterFunc(...) else for i,v in pairs(TF3.db.profile.filters.BASE) do --@alpha@ - if (TF3.db.profile.debug) then + if (TF3.db.profile.debug and not TF3.db.profile.debug_checking) then if (lastmsg ~= msg or lastuserID ~= userID) then TF3:FindFrame(debugFrame, L["CFM"] .. " " .. v) end diff --git a/TradeFilter3Options.lua b/TradeFilter3Options.lua index e213713..024394e 100644 --- a/TradeFilter3Options.lua +++ b/TradeFilter3Options.lua @@ -7,46 +7,6 @@ local TradeFilter3 = LibStub("AceAddon-3.0"):GetAddon("TradeFilter3") local L = LibStub("AceLocale-3.0"):GetLocale("TradeFilter3") local TF3 = TradeFilter3 ---[[ DB Functions ]]-- -function TF3:Del(t) - wipe(t) - setmetatable(t, nil) - pool[t] = true - return nil -end - -function TF3:ClearTable(t, recursive) - if t ~= nil and type(t) == 'table' then - if not recursive then - wipe(t) - else - for k, v in pairs(t) do - if type(v) == 'table' then - TF3:ClearTable(v, true) - t[k] = TF3:Del(v) - else - t[k] = nil - end - end - end - return t - else - return {} - end -end - -function TF3:CopyTable(t, recursive) - local ret = {} - for k, v in pairs(t) do - if (type(v) == "table") and recursive and not v.GetObjectType then - ret[k] = copyTable(v) - else - ret[k] = v - end - end - return ret -end - --[[ Options Table ]]-- options = { type="group", @@ -166,13 +126,21 @@ options = { get = function() return TF3.db.profile.addfilter_enable end, set = function() TF3.db.profile.addfilter_enable = not TF3.db.profile.addfilter_enable end, }, + optionsHeader2a = { + type = "header", + order = 3, + name = L["BTF"], + }, reset_tradefilters = { type = 'execute', - order = 3, + disabled = function() + return not TF3.db.profile.addfilter_enable + end, + order = 4, width = "double", name = L["RTF"], desc = L["RTF"], - func = function() TF3.db.profile.filters.TRADE = TF3:CopyTable(L.FILTERS.TRADE, true) end, + func = function() TF3.db.profile.filters.TRADE = TF3:CopyTable(L.FILTERS.TRADE) end, }, tradefilters = { type = 'input', @@ -180,7 +148,7 @@ options = { return not TF3.db.profile.addfilter_enable end, multiline = 8, - order = 4, + order = 5, width = "double", name = L["BTF"], --~ desc = L["BTF"], @@ -196,7 +164,7 @@ options = { return ret end, set = function(info, value) - TF3:ClearTable(TF3.db.profile.filters.TRADE) + TF3:WipeTable(TF3.db.profile.filters.TRADE) local tbl = { strsplit("\n", value) } for k, v in pairs(tbl) do key = "FILTER" @@ -204,13 +172,21 @@ options = { end end, }, + optionsHeader2b = { + type = "header", + order = 6, + name = L["BCF"], + }, reset_basefilters = { type = 'execute', - order = 5, + disabled = function() + return not TF3.db.profile.addfilter_enable + end, + order = 7, width = "double", name = L["RBF"], desc = L["RBF"], - func = function() TF3.db.profile.filters.BASE = TF3:CopyTable(L.FILTERS.BASE, true) end, + func = function() TF3.db.profile.filters.BASE = TF3:CopyTable(L.FILTERS.BASE) end, }, basefilters = { @@ -219,7 +195,7 @@ options = { return not TF3.db.profile.addfilter_enable end, multiline = 8, - order = 6, + order = 8, width = "double", name = L["BCF"], desc = L["BCFD"], @@ -235,7 +211,7 @@ options = { return ret end, set = function(info, value) - TF3:ClearTable(TF3.db.profile.filters.BASE) + TF3:WipeTable(TF3.db.profile.filters.BASE) local tbl = { strsplit("\n", value) } for k, v in pairs(tbl) do key = "FILTER" @@ -269,13 +245,39 @@ options = { get = function() return TF3.db.profile.editlists_enable end, set = function() TF3.db.profile.editlists_enable = not TF3.db.profile.editlists_enable end, }, - reset_lists = { - type = 'execute', + blacklist_enable = { + type = 'toggle', order = 3, width = "double", - name = L["RLS"], - desc = L["RLS"], - func = function() TF3.db.profile.blacklist = TF3:CopyTable(L.BLACKLIST, true); TF3.db.profile.whitelist = TF3:CopyTable(L.WHITELIST, true) end, + name = L["BLE"], + desc = L["BLE"], + get = function() return TF3.db.profile.blacklist_enable end, + set = function() TF3.db.profile.blacklist_enable = not TF3.db.profile.blacklist_enable end, + }, + whitelist_enable = { + type = 'toggle', + order = 4, + width = "double", + name = L["WLE"], + desc = L["WLE"], + get = function() return TF3.db.profile.whitelist_enable end, + set = function() TF3.db.profile.whitelist_enable = not TF3.db.profile.whitelist_enable end, + }, + optionsHeader3a = { + type = "header", + order = 5, + name = L["bLists"], + }, + reset_blist = { + type = 'execute', + disabled = function() + return not TF3.db.profile.editlists_enable + end, + order = 6, + width = "double", + name = L["RBLS"], + desc = L["RBLS"], + func = function() TF3.db.profile.blacklist = TF3:CopyTable(L.BLACKLIST) end, }, blist = { type = 'input', @@ -283,23 +285,22 @@ options = { return not TF3.db.profile.editlists_enable end, multiline = 8, - order = 4, + order = 7, width = "double", name = L["bLists"], ---~ desc = L["bLists"], get = function(info) local ret = "" - for k, v in pairs(TF3.db.profile.blacklist) do - if ret == "" then - ret = v - else - ret = ret .. "\n" .. v - end + for k, v in pairs(TF3.db.profile.blacklist) do + if ret == "" then + ret = v + else + ret = ret .. "\n" .. v end - return ret - end, + end + return ret + end, set = function(info, value) - TF3:ClearTable(TF3.db.profile.blacklist) + TF3:WipeTable(TF3.db.profile.blacklist) local tbl = { strsplit("\n", value) } for k, v in pairs(tbl) do key = "BLIST" @@ -307,29 +308,44 @@ options = { end end, }, + optionsHeader3b = { + type = "header", + order = 8, + name = L["wLists"], + }, + reset_wlist = { + type = 'execute', + disabled = function() + return not TF3.db.profile.editlists_enable + end, + order = 9, + width = "double", + name = L["RWLS"], + desc = L["RWLS"], + func = function() TF3.db.profile.whitelist = TF3:CopyTable(L.WHITELIST) end, + }, wlist = { type = 'input', disabled = function() return not TF3.db.profile.editlists_enable end, multiline = 8, - order = 5, + order = 10, width = "double", name = L["wLists"], ---~ desc = L["wLists"], get = function(info) local ret = "" - for k, v in pairs(TF3.db.profile.whitelist) do - if ret == "" then - ret = v - else - ret = ret .. "\n" .. v - end + for k, v in pairs(TF3.db.profile.whitelist) do + if ret == "" then + ret = v + else + ret = ret .. "\n" .. v end - return ret - end, + end + return ret + end, set = function(info, value) - TF3:ClearTable(TF3.db.profile.whitelist) + TF3:WipeTable(TF3.db.profile.whitelist) local tbl = { strsplit("\n", value) } for k, v in pairs(tbl) do key = "WLIST" @@ -349,11 +365,10 @@ options = { name = L["REPEAT"], desc = L["REPEAT"], args = { - optionsHeader3 = { + optionsHeader4 = { type = "header", order = 1, name = L["REPEAT"], - desc = L["REPEAT"], }, repeat_enable = { type = 'toggle', @@ -421,11 +436,10 @@ options = { name = L["OUTPUT"], desc = L["OUTPUT"], args = { - optionsHeader3 = { + optionsHeader5 = { type = "header", order = 1, name = L["OUTPUT"], - desc = L["OUTPUT"], }, redirect = { type = 'toggle', @@ -436,10 +450,24 @@ options = { get = function() return TF3.db.profile.redirect end, set = function() TF3.db.profile.redirect = not TF3.db.profile.redirect end, }, + redirect_blacklist = { + type = 'toggle', + order = 3, + width = "full", + name = L["RedirBL"], + desc = L["RedirDesc"], + get = function() return TF3.db.profile.redirect_blacklist end, + set = function() TF3.db.profile.redirect_blacklist = not TF3.db.profile.redirect_blacklist end, + }, --@alpha@ + optionsHeader6 = { + type = "header", + order = 4, + name = L["DEBUGGING"], + }, debug = { type = 'toggle', - order = 3, + order = 5, width = "full", disabled = false, hidden = false, @@ -448,16 +476,27 @@ options = { get = function() return TF3.db.profile.debug end, set = function() TF3.db.profile.debug = not TF3.db.profile.debug end, }, + debug_checking = { + type = 'toggle', + order = 6, + width = "full", + disabled = false, + hidden = false, + name = L["DebugChecking"], + desc = L["DebugCheckingD"], + get = function() return TF3.db.profile.debug_checking end, + set = function() TF3.db.profile.debug_checking = not TF3.db.profile.debug_checking end, + }, --@end-alpha@ optionsHeader4 = { type = "header", - order = 4, + order = 7, name = L["FSELF"], desc = L["FSELFD"], }, filterSELF = { type = 'toggle', - order = 5, + order = 8, width = "double", disabled = false, name = L["FSELF"], -- 1.7.9.5