-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.lua
More file actions
executable file
·270 lines (237 loc) · 8.98 KB
/
core.lua
File metadata and controls
executable file
·270 lines (237 loc) · 8.98 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
local addonName, ns = ...
---------------------------------------------------------------------------
-- Core — Entry point, event dispatch, slash commands, and combat hiding
--
-- Sets up the main event frame that routes WoW events to handler functions
-- on the addon namespace (ns). Initializes saved variables, registers
-- whisper events, builds the UI, and defines all /ichat slash commands.
---------------------------------------------------------------------------
-- Version read from TOC at load time (set in ADDON_LOADED)
ns.version = "?"
ns.playerName = nil
ns.activeConversation = nil
-- Keybinding support — header and handler for WoW Key Bindings UI
BINDING_HEADER_ICHAT = "iChat"
BINDING_NAME_ICHAT_TOGGLE = "Toggle iChat Window"
function iChatToggle()
if ns.ToggleWindow then
ns.ToggleWindow()
end
end
-- Event frame
local frame = CreateFrame("Frame", "iChatEventFrame", UIParent)
frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("PLAYER_LOGIN")
frame:SetScript("OnEvent", function(self, event, ...)
if ns[event] then
ns[event](ns, ...)
end
end)
function ns:ADDON_LOADED(loadedName)
if loadedName ~= addonName then return end
frame:UnregisterEvent("ADDON_LOADED")
ns.InitDB()
local GetMeta = C_AddOns and C_AddOns.GetAddOnMetadata or GetAddOnMetadata
ns.version = GetMeta and GetMeta(addonName, "Version") or "?"
ns.playerName = UnitName("player")
-- Register whisper events
frame:RegisterEvent("CHAT_MSG_WHISPER")
frame:RegisterEvent("CHAT_MSG_WHISPER_INFORM")
frame:RegisterEvent("CHAT_MSG_BN_WHISPER")
frame:RegisterEvent("CHAT_MSG_BN_WHISPER_INFORM")
frame:RegisterEvent("CHAT_MSG_AFK")
frame:RegisterEvent("CHAT_MSG_DND")
frame:RegisterEvent("FRIENDLIST_UPDATE")
frame:RegisterEvent("IGNORELIST_UPDATE")
frame:RegisterEvent("GUILD_ROSTER_UPDATE")
frame:RegisterEvent("BN_FRIEND_LIST_SIZE_CHANGED")
frame:RegisterEvent("BN_FRIEND_INFO_CHANGED")
frame:RegisterEvent("CHAT_MSG_SYSTEM")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("PLAYER_STARTED_MOVING")
frame:RegisterEvent("PLAYER_STOPPED_MOVING")
-- Build the UI (hidden by default)
ns.CreateMainWindow()
-- Suppress whispers from default chat if enabled
if ns.db.settings.suppressDefault then
ns.RegisterChatFilters()
end
-- Create minimap button
if ns.CreateMinimapButton then
ns.CreateMinimapButton()
end
-- Hook typing indicator
if ns.HookTypingIndicator then
-- Delayed: input box is created in CreateMainWindow
C_Timer.After(0.1, function()
ns.HookTypingIndicator()
end)
end
-- Register guild roster event
if IsInGuild() then
if C_GuildInfo and C_GuildInfo.GuildRoster then
C_GuildInfo.GuildRoster()
elseif GuildRoster then
GuildRoster()
end
end
-- Apply ElvUI skin if available
if ns.db.settings.elvuiSkin and ns.ApplyElvUISkin then
C_Timer.After(1, function()
ns.ApplyElvUISkin()
end)
end
-- Slash commands
SLASH_ICHAT1 = "/ichat"
SlashCmdList["ICHAT"] = function(msg)
ns.SlashHandler(msg)
end
end
function ns:PLAYER_LOGIN()
ns.playerName = UnitName("player")
local function RequestFriendInfo()
if C_FriendList and C_FriendList.ShowFriends then
C_FriendList.ShowFriends()
elseif ShowFriends then
ShowFriends()
end
end
RequestFriendInfo()
frame:UnregisterEvent("PLAYER_LOGIN")
-- Poll friend list every 60s to keep online status current
C_Timer.NewTicker(60, RequestFriendInfo)
-- Initial player info scans
C_Timer.After(2, function()
if ns.ScanFriendList then
ns.ScanFriendList()
end
if ns.ScanGuildRoster then
ns.ScanGuildRoster()
end
end)
end
-- Friend list updated - scan for player info
-- MOVED TO messages.lua to avoid conflict
-- Guild roster updated - scan for player info
-- MOVED TO social.lua to avoid conflict
-- BNet Friend list updated
function ns:BN_FRIEND_LIST_SIZE_CHANGED()
if ns.RefreshConversationList then
ns.RefreshConversationList()
end
end
function ns:BN_FRIEND_INFO_CHANGED()
if ns.RefreshConversationList then
ns.RefreshConversationList()
end
end
-- Hide window on combat start, restore on combat end
ns.wasShownBeforeCombat = false
function ns:PLAYER_REGEN_DISABLED()
if not ns.db.settings.hideInCombat then return end
if ns.mainWindow and ns.mainWindow:IsShown() then
ns.wasShownBeforeCombat = true
ns.mainWindow:Hide()
end
end
function ns:PLAYER_REGEN_ENABLED()
if not ns.db.settings.hideInCombat then return end
if ns.wasShownBeforeCombat and ns.mainWindow then
ns.mainWindow:Show()
ns.wasShownBeforeCombat = false
end
end
-- Fade window when player starts moving
function ns:PLAYER_STARTED_MOVING()
if not ns.db.settings.fadeWhileMoving then return end
if ns.mainWindow and ns.mainWindow:IsShown() then
UIFrameFadeOut(ns.mainWindow, 0.3, ns.mainWindow:GetAlpha(), 0.25)
ns.isMoveFaded = true
end
end
function ns:PLAYER_STOPPED_MOVING()
if not ns.db.settings.fadeWhileMoving then return end
if ns.isMoveFaded and ns.mainWindow then
UIFrameFadeIn(ns.mainWindow, 0.15, ns.mainWindow:GetAlpha(), 1.0)
ns.isMoveFaded = false
end
end
function ns.SlashHandler(msg)
msg = (msg or ""):lower():match("^%s*(.-)%s*$") or ""
if msg == "" then
ns.ToggleWindow()
elseif msg == "clear" then
if ns.activeConversation and ns.db.conversations[ns.activeConversation] then
wipe(ns.db.conversations[ns.activeConversation].messages)
ns.db.conversations[ns.activeConversation].unread = 0
ns.RebuildBubbles(ns.activeConversation)
ns.RefreshConversationList()
DEFAULT_CHAT_FRAME:AddMessage("|cff007AFFiChat:|r Cleared conversation with " .. ns.activeConversation)
else
DEFAULT_CHAT_FRAME:AddMessage("|cff007AFFiChat:|r No active conversation to clear.")
end
elseif msg == "emoji" then
if ns.PrintEmojiList then
ns.PrintEmojiList()
else
DEFAULT_CHAT_FRAME:AddMessage("|cff007AFFiChat:|r Emoji module not loaded.")
end
elseif msg:match("^scale%s+") then
local s = tonumber(msg:match("^scale%s+(.+)"))
if s and s >= 0.5 and s <= 2.0 then
ns.db.settings.scale = s
if ns.mainWindow then
ns.mainWindow:SetScale(s)
end
DEFAULT_CHAT_FRAME:AddMessage("|cff007AFFiChat:|r Scale set to " .. s)
else
DEFAULT_CHAT_FRAME:AddMessage("|cff007AFFiChat:|r Scale must be between 0.5 and 2.0")
end
elseif msg == "autoreply" then
ns.db.settings.autoReplyEnabled = not ns.db.settings.autoReplyEnabled
if ns.db.settings.autoReplyEnabled then
ns.autoRepliedTo = {}
DEFAULT_CHAT_FRAME:AddMessage("|cff007AFFiChat:|r Auto-reply |cff00ff00enabled|r: " .. (ns.db.settings.autoReplyMessage or ""))
else
DEFAULT_CHAT_FRAME:AddMessage("|cff007AFFiChat:|r Auto-reply |cffff4444disabled|r")
end
elseif msg == "export" then
if ns.ExportConversation then
ns.ExportConversation()
else
DEFAULT_CHAT_FRAME:AddMessage("|cff007AFFiChat:|r Export not available.")
end
elseif msg == "version" or msg == "ver" then
DEFAULT_CHAT_FRAME:AddMessage("|cff007AFFiChat|r v" .. ns.version .. (ns.IsSharedAccount() and " (account-wide)" or " (per-character)"))
elseif msg:match("^search%s+") then
local query = msg:match("^search%s+(.+)")
if query and ns.searchBox then
if ns.mainWindow and not ns.mainWindow:IsShown() then
ns.mainWindow:Show()
end
ns.searchBox:SetText(query)
ns.searchBox:SetFocus()
end
else
DEFAULT_CHAT_FRAME:AddMessage("|cff007AFFiChat|r v" .. ns.version .. " — commands:")
DEFAULT_CHAT_FRAME:AddMessage(" /ichat - Toggle window")
DEFAULT_CHAT_FRAME:AddMessage(" /ichat clear - Clear current conversation")
DEFAULT_CHAT_FRAME:AddMessage(" /ichat export - Export current conversation to text")
DEFAULT_CHAT_FRAME:AddMessage(" /ichat scale <n> - Set scale (0.5-2.0)")
DEFAULT_CHAT_FRAME:AddMessage(" /ichat emoji - Show available emoji shortcodes")
DEFAULT_CHAT_FRAME:AddMessage(" /ichat autoreply - Toggle auto-reply")
DEFAULT_CHAT_FRAME:AddMessage(" /ichat search <text> - Search conversations")
DEFAULT_CHAT_FRAME:AddMessage(" /ichat version - Show version info")
end
end
function ns.ToggleWindow()
if ns.mainWindow then
if ns.mainWindow:IsShown() then
ns.mainWindow:Hide()
else
ns.mainWindow:Show()
ns.RefreshConversationList()
end
end
end