-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
163 lines (155 loc) · 5.45 KB
/
Core.lua
File metadata and controls
163 lines (155 loc) · 5.45 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
local ADDON_NAME, ns = ...
local GuildMute = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceEvent-3.0", "AceConsole-3.0")
ns.Addon = GuildMute
local defaults = {
realm = {
targetGuild = nil, -- must be set by the user via /gm guild <Name>
enabled = true,
scanIntervalMin = 30, -- 0 disables periodic /who scans
historyEnabled = true, -- in-memory only; cleared on /reload
muted = {}, -- [normalizedName] = true
learnedAt = {}, -- [normalizedName] = unix timestamp
},
}
function GuildMute:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("GuildMuteDB", defaults, true)
self:RegisterChatCommand("guildmute", "HandleSlashCommand")
self:RegisterChatCommand("gm", "HandleSlashCommand")
ns.Roster:Initialize(self)
ns.History:Initialize(self)
ns.Filter:Initialize(self)
ns.IO:Initialize(self)
end
function GuildMute:OnEnable()
local count = 0
for _ in pairs(self.db.realm.muted) do
count = count + 1
end
local guild = self.db.realm.targetGuild
if not guild or guild == "" then
self:Print("ready. No target guild set yet. Use: /gm guild <GuildName>")
else
self:Print(("ready. %d muted on this realm. Target guild: %s. /gm help for commands."):format(count, guild))
end
-- Start the auto-scan ticker; the PLAYER_ENTERING_WORLD handler also restarts it on /reload.
ns.Roster:StartAutoScan()
end
local function help(self)
self:Print("commands:")
self:Print(" /gm guild <Name> set the guild whose chatter to hide (required)")
self:Print(" /gm refresh run a /who scan now to populate the list")
self:Print(" /gm interval <min> set auto-scan interval (0 = off; default: 30)")
self:Print(" /gm export open a window with the list, ready to copy")
self:Print(" /gm import paste a list from another character to merge")
self:Print(" /gm history [N|all|clear|on|off] show what was filtered this session")
self:Print(" /gm add <Charname> add a name manually")
self:Print(" /gm remove <Charname> remove a name from the list")
self:Print(" /gm list show all muted names")
self:Print(" /gm clear empty the mute list")
self:Print(" /gm toggle enable/disable filtering")
self:Print(" /gm status show summary")
end
function GuildMute:HandleSlashCommand(input)
input = (input or ""):trim()
local cmd, rest = input:match("^(%S*)%s*(.-)$")
cmd = (cmd or ""):lower()
if cmd == "guild" then
if rest == "" then
self:Print("target guild: " .. (self.db.realm.targetGuild or "<not set>"))
return
end
self.db.realm.targetGuild = rest
self:Print("target guild set: " .. rest)
ns.Roster:StartAutoScan()
elseif cmd == "refresh" or cmd == "scan" then
ns.Roster:RequestWhoScan()
elseif cmd == "interval" then
if rest == "" then
self:Print("auto-scan interval: " .. self.db.realm.scanIntervalMin .. " min (0 = off)")
return
end
local n = tonumber(rest)
if not n or n < 0 then
self:Print("usage: /gm interval <minutes> (0 disables)")
return
end
self.db.realm.scanIntervalMin = math.floor(n)
ns.Roster:StartAutoScan()
self:Print("auto-scan interval: " .. self.db.realm.scanIntervalMin .. " min")
elseif cmd == "export" then
ns.IO:ShowExport()
elseif cmd == "import" then
ns.IO:ShowImport()
elseif cmd == "history" or cmd == "log" then
local arg = (rest or ""):lower()
if arg == "" then
ns.History:PrintRecent(20)
elseif arg == "all" then
ns.IO:ShowText(
"GuildMute — History",
("Filtered this session: %d entries (cleared on /reload)."):format(ns.History:Count()),
ns.History:BuildText()
)
elseif arg == "clear" then
ns.History:Clear()
self:Print("history cleared")
elseif arg == "on" then
self.db.realm.historyEnabled = true
self:Print("history: ON")
elseif arg == "off" then
self.db.realm.historyEnabled = false
ns.History:Clear()
self:Print("history: OFF (buffer cleared)")
else
local n = tonumber(arg)
if n and n > 0 then
ns.History:PrintRecent(math.floor(n))
else
self:Print("usage: /gm history [N|all|clear|on|off]")
end
end
elseif cmd == "add" then
if rest == "" then
self:Print("usage: /gm add <Charname>")
return
end
if ns.Roster:Add(rest, "manual") then
self:Print("added: " .. rest)
else
self:Print("already muted: " .. rest)
end
elseif cmd == "remove" or cmd == "rm" or cmd == "del" then
if rest == "" then
self:Print("usage: /gm remove <Charname>")
return
end
if ns.Roster:Remove(rest) then
self:Print("removed: " .. rest)
else
self:Print("not in list: " .. rest)
end
elseif cmd == "list" then
ns.Roster:PrintList()
elseif cmd == "clear" then
ns.Roster:Clear()
self:Print("mute list cleared")
elseif cmd == "toggle" then
self.db.realm.enabled = not self.db.realm.enabled
self:Print("filtering: " .. (self.db.realm.enabled and "ON" or "OFF"))
elseif cmd == "status" then
local count = 0
for _ in pairs(self.db.realm.muted) do
count = count + 1
end
self:Print(
("guild=%s | muted=%d | filter=%s | autoscan=%s"):format(
self.db.realm.targetGuild or "<not set>",
count,
self.db.realm.enabled and "ON" or "OFF",
self.db.realm.scanIntervalMin > 0 and (self.db.realm.scanIntervalMin .. "min") or "off"
)
)
else
help(self)
end
end