-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExaltedInactive.lua
More file actions
183 lines (149 loc) · 6.19 KB
/
ExaltedInactive.lua
File metadata and controls
183 lines (149 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
-- ExaltedInactive
-- Automatically moves Exalted reputations to the Inactive tab.
local ADDON_NAME = "ExaltedInactive"
local EXALTED = 8
ExaltedInactiveDB = ExaltedInactiveDB or {}
local defaults = {
enabled = true,
autoOnOpen = true,
verbose = false,
ignoredFactions = {},
}
-- ── Helpers ───────────────────────────────────────────────────────────────────
local function chat(msg)
DEFAULT_CHAT_FRAME:AddMessage("|cff00ccff[ExaltedInactive]|r " .. tostring(msg))
end
local function vprint(msg)
if ExaltedInactiveDB.verbose then chat(msg) end
end
local function db()
for k, v in pairs(defaults) do
if ExaltedInactiveDB[k] == nil then
ExaltedInactiveDB[k] = v
end
end
return ExaltedInactiveDB
end
local function IsIgnored(factionID)
return factionID and db().ignoredFactions[tostring(factionID)] == true
end
-- ── Core ──────────────────────────────────────────────────────────────────────
local isRunning = false -- re-entrancy guard
local function MoveExaltedToInactive()
if not db().enabled then return 0 end
if isRunning then return 0 end
isRunning = true
local moved = 0
local total = GetNumFactions()
-- Iterate backwards so that removing an entry doesn't shift
-- the indices of items not yet processed.
for i = total, 1, -1 do
local name, _, standingID, _, _, _, _, _, isHeader, _, _, _, _, factionID =
GetFactionInfo(i)
if not isHeader and standingID == EXALTED and not IsIgnored(factionID) then
SetFactionInactive(i)
moved = moved + 1
vprint("Moved to Inactive: " .. (name or "?"))
end
end
if ReputationFrame and ReputationFrame:IsShown() then
ReputationFrame_Update()
end
isRunning = false
return moved
end
-- ── Slash Commands ────────────────────────────────────────────────────────────
local function HandleSlash(msg)
msg = strtrim(msg:lower())
if msg == "" or msg == "help" then
chat("Commands:")
chat(" /ei run - move all exalted factions to Inactive now")
chat(" /ei toggle - enable / disable")
chat(" /ei auto - toggle auto-run when Reputation panel opens")
chat(" /ei verbose - toggle verbose output")
chat(" /ei status - show current settings")
chat(" /ei list - list ignored faction IDs")
chat(" /ei unignore <id> - stop ignoring a faction by ID")
elseif msg == "run" then
local n = MoveExaltedToInactive()
chat(("Done. Moved %d exalted faction(s) to Inactive."):format(n))
elseif msg == "toggle" then
db().enabled = not db().enabled
chat("Addon " .. (db().enabled and "|cff00ff00enabled|r" or "|cffff4444disabled|r") .. ".")
elseif msg == "auto" then
db().autoOnOpen = not db().autoOnOpen
chat("Auto-run on open: " .. (db().autoOnOpen and "|cff00ff00ON|r" or "|cffff4444OFF|r"))
elseif msg == "verbose" then
db().verbose = not db().verbose
chat("Verbose: " .. (db().verbose and "|cff00ff00ON|r" or "|cffff4444OFF|r"))
elseif msg == "status" then
chat(("Enabled: %s | Auto: %s | Verbose: %s"):format(
db().enabled and "|cff00ff00yes|r" or "|cffff4444no|r",
db().autoOnOpen and "|cff00ff00yes|r" or "|cffff4444no|r",
db().verbose and "|cff00ff00yes|r" or "|cffff4444no|r"))
elseif msg == "list" then
local n = 0
for id in pairs(db().ignoredFactions) do
chat(" Ignored ID: " .. id)
n = n + 1
end
if n == 0 then chat("No factions are ignored.") end
elseif msg:sub(1, 8) == "unignore" then
local id = strtrim(msg:sub(9))
if id ~= "" then
db().ignoredFactions[id] = nil
chat("Removed ignore for ID: " .. id)
else
chat("Usage: /ei unignore <factionID>")
end
else
chat('Unknown command. Try /ei help')
end
end
SLASH_EXALTEDINACTIVE1 = "/exaltedinactive"
SLASH_EXALTEDINACTIVE2 = "/ei"
SlashCmdList["EXALTEDINACTIVE"] = HandleSlash
-- ── Event Frame ───────────────────────────────────────────────────────────────
local frame = CreateFrame("Frame", ADDON_NAME .. "Frame")
frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("PLAYER_LOGIN")
-- UPDATE_FACTION fires when SetFactionInactive is called, which would
-- re-trigger ourselves. We avoid this entirely and only run on:
-- 1. Reputation panel opening (OnShow hook)
-- 2. Manual /ei run
-- 3. PLAYER_LOGIN (once, on load)
local hooked = false
local function HookReputationFrame()
if hooked or not ReputationFrame then return end
ReputationFrame:HookScript("OnShow", function()
if db().enabled and db().autoOnOpen then
C_Timer.After(0.2, function()
local n = MoveExaltedToInactive()
if n > 0 then
vprint(("Auto-moved %d exalted faction(s) to Inactive."):format(n))
end
end)
end
end)
hooked = true
vprint("Hooked ReputationFrame.")
end
frame:SetScript("OnEvent", function(self, event, arg1)
if event == "ADDON_LOADED" then
if arg1 == ADDON_NAME then
db()
chat("Loaded. Type /ei help for commands.")
end
HookReputationFrame()
elseif event == "PLAYER_LOGIN" then
db()
HookReputationFrame()
-- Run once on login to catch anything already exalted
C_Timer.After(1, function()
local n = MoveExaltedToInactive()
if n > 0 then
chat(("Login: moved %d exalted faction(s) to Inactive."):format(n))
end
end)
end
end)