Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable /rfilter #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ Version 1.4.0
- Cleaned up some of the server listings
- Reflect changes in the datacentre merges
- New colour scheme (feedback wanted for this)

Version 1.5.2
- Slash command '/rfilter' to remove groups from outside your region.
2 changes: 1 addition & 1 deletion RegionFilter.toc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Interface: 90105
## Title: Region Filter
## Notes: Tags groups in the native LFG search if they are from your server and data-centre
## Version: 1.5.0
## Version: 1.5.2

utils.lua
servers.lua
Expand Down
95 changes: 59 additions & 36 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local RF = select(2, ...)
local servers = RF.servers
local posts = RF.posts
RF.version = "1.5.0"
RF.version = "1.5.2"
RF.togRemove = false

local spaced_realm = string.gsub(GetRealmName(), "%s+", "")
Expand All @@ -24,30 +24,53 @@ if RF.region == 'OC' then RF.postType = posts.oc_post end
if RF.region == 'LA' then RF.postType = posts.la_post end
if RF.region == 'BR' then RF.postType = posts.br_post end
---- Removing Enrties when togRemove is enabled
-- function RF.removeEntries(results)
-- if RF.togRemove then
-- for i=1, #results do
-- local resultID = results[i]
-- local searchResults = C_LFGList.GetSearchResultInfo(resultID)
function RF.removeEntries(results)
local isLocal = {}
if RF.togRemove then
local localCount = 0
local originalResultCount = #results
for i=originalResultCount, 1, -1 do
local resultID = results[i]
isLocal[resultID] = false
local searchResults = C_LFGList.GetSearchResultInfo(resultID)

-- local leaderName = searchResults.leaderName
local leaderName = searchResults.leaderName

-- if leaderName ~= nil then -- Filter out nil entries from LFG Pane
-- local name, realm = RF:sanitiseName(leaderName)
-- local info = servers[realm]
-- if info ~= nil then
-- local region = info[1]
-- if RF.region ~= region then
-- table.remove(results, i)
-- end
-- end
-- end
-- end
-- end
-- table.sort(results)
-- LFGListFrame.SearchPanel.totalResults = #results
-- return true
-- end
if leaderName ~= nil then -- Filter out nil entries from LFG Pane
local name, realm = RF:sanitiseName(leaderName)
local info = servers[realm]
if info ~= nil then
local region = info[1]
if RF.region ~= region then
table.remove(results, i)
else
localCount = localCount + 1
isLocal[resultID] = true
end
end
end
end

local function sortCompFunc(searchResultID1, searchResultID2)
if (isLocal[searchResultID1]) then
if (not isLocal[searchResultID2]) then
return true
end
else
if (isLocal[searchResultID2]) then
return false
end
end
return searchResultID1>searchResultID2
end

table.sort(results, sortCompFunc)
else
table.sort(results)
end
LFGListFrame.SearchPanel.totalResults = #results
return true
end

---- Updating the text of entries
function RF.updateEntries(results)
Expand Down Expand Up @@ -81,17 +104,17 @@ function RF.updateEntries(results)
end


-- SLASH_RFILTER1 = "/rfilter"
-- SlashCmdList["RFILTER"] = function(msg)
-- if RF.togRemove then
-- print('|cff00ffff[Region Filter]: |cffFF6EB4 Not filtering outside regions')
-- else
-- print('|cff00ffff[Region Filter]: |cffFF6EB4 Filtering outside regions')
-- end
-- RF.togRemove = not RF.togRemove
-- LFGListSearchPanel_UpdateResultList (LFGListFrame.SearchPanel)
-- LFGListSearchPanel_UpdateResults (LFGListFrame.SearchPanel)
-- end
SLASH_RFILTER1 = "/rfilter"
SlashCmdList["RFILTER"] = function(msg)
if RF.togRemove then
print('|cff00ffff[Region Filter]: |cffFF6EB4 Not filtering outside regions')
else
print('|cff00ffff[Region Filter]: |cffFF6EB4 Filtering outside regions')
end
RF.togRemove = not RF.togRemove
LFGListSearchPanel_UpdateResultList (LFGListFrame.SearchPanel)
LFGListSearchPanel_UpdateResults (LFGListFrame.SearchPanel)
end

---- Print When Loaded ----
local welcomePrompt = CreateFrame("Frame")
Expand All @@ -103,5 +126,5 @@ welcomePrompt:SetScript("OnEvent", function(_, event)
end
end)

-- hooksecurefunc("LFGListUtil_SortSearchResults", RF.sortEntries)
hooksecurefunc("LFGListSearchEntry_Update", RF.updateEntries)
hooksecurefunc("LFGListSearchEntry_Update", RF.updateEntries)
hooksecurefunc("LFGListUtil_SortSearchResults", RF.removeEntries)