-
Notifications
You must be signed in to change notification settings - Fork 3
/
chat.lua
281 lines (254 loc) · 7.55 KB
/
chat.lua
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
271
272
273
274
275
276
277
278
279
280
281
--[[
Configuration
]]
-- Timestamps
local timeStampFormat = "%X"
local timeStampOutput = "|cFFFFFFFF%s|||r %s"
local timeStampsEnabled = {
true, -- [1]
true, -- [2]
true, -- [3]
true, -- [4]
true, -- [5]
true, -- [6]
true -- [7]
}
-- Sticky
local stickyTypes = {
SAY = true,
WHISPER = false,
YELL = false,
PARTY = true,
GUILD = true,
OFFICER = true,
RAID = true,
RAID_WARNING = true,
INSTANCE_CHAT = true,
CHANNEL = true,
EMOTE = false
}
-- Channel Names
local channelNamePattern = {
["%[Guild%]"] = "(G)",
["%[Party%]"] = "(P)",
["%[Raid%]"] = "(R)",
["%[Party Leader%]"] = "(PL)",
["%[Dungeon Guide%]"] = "(DG)",
["%[Instance%]"] = "(I)",
["%[Instance Leader%]"] = "|cffff3399(|rIL|cffff3399)|r",
["%[Raid Leader%]"] = "|cffff3399(|rRL|cffff3399)|r",
["%[Raid Warning%]"] = "|cffff0000(|rRW|cffff0000)|r",
["%[Officer%]"] = "(O)",
["%[Battleground%]"] = "|cffff3399(|rBG|cffff3399)|r",
["%[Battleground Leader%]"] = "|cffff0000(|rBGL|cffff0000)|r",
["%[%d+%.%s(%w*)%]"] = "|cff990066(|r%1|cff990066)|r",
}
-- Mouse Scroll
local scrollLines = 1
-- UrlCopy
local urlStyle = " |cffffffff|Hgarrmission:nevurl:%1$s|h[%1$s]|h|r "
local urlPatterns = {
-- X://Y url
{ "^(%a[%w%.+-]+://%S+)", "%s"},
{ "%f[%S](%a[%w%.+-]+://%S+)", "%s"},
-- www.X.Y url
{ "^(www%.[-%w_%%]+%.%S+)", "%s"},
{ "%f[%S](www%.[-%w_%%]+%.%S+)", "%s"},
-- "W X"@Y.Z email (this is seriously a valid email)
--{ pattern = '^(%"[^%"]+%"@[-%w_%%%.]+%.(%a%a+))', matchfunc=Link_TLD},
--{ pattern = '%f[%S](%"[^%"]+%"@[-%w_%%%.]+%.(%a%a+))', matchfunc=Link_TLD},
-- [email protected] email
{ "(%S+@[-%w_%%%.]+%.(%a%a+))", "%s"},
-- XXX.YYY.ZZZ.WWW:VVVV/UUUUU IPv4 address with port and path
{ "^([0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d:[0-6]?%d?%d?%d?%d/%S+)", "%s"},
{ "%f[%S]([0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d:[0-6]?%d?%d?%d?%d/%S+)", "%s"},
-- XXX.YYY.ZZZ.WWW:VVVV IPv4 address with port (IP of ts server for example)
{ "^([0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d:[0-6]?%d?%d?%d?%d)%f[%D]", "%s"},
{ "%f[%S]([0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d:[0-6]?%d?%d?%d?%d)%f[%D]", "%s"},
-- XXX.YYY.ZZZ.WWW/VVVVV IPv4 address with path
{ "^([0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d%/%S+)", "%s"},
{ "%f[%S]([0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d%/%S+)", "%s"},
-- XXX.YYY.ZZZ.WWW IPv4 address
{ "^([0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d%)%f[%D]", "%s"},
{ "%f[%S]([0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d%.[0-2]?%d?%d%)%f[%D]", "%s"},
-- X.Y.Z:WWWW/VVVVV url with port and path
{ "^([-%w_%%%.]+[-%w_%%]%.(%a%a+):[0-6]?%d?%d?%d?%d/%S+)", "%s"},
{ "%f[%S]([-%w_%%%.]+[-%w_%%]%.(%a%a+):[0-6]?%d?%d?%d?%d/%S+)", "%s"},
-- X.Y.Z:WWWW url with port (ts server for example)
{ "^([-%w_%%%.]+[-%w_%%]%.(%a%a+):[0-6]?%d?%d?%d?%d)%f[%D]", "%s"},
{ "%f[%S]([-%w_%%%.]+[-%w_%%]%.(%a%a+):[0-6]?%d?%d?%d?%d)%f[%D]", "%s"},
-- X.Y.Z/WWWWW url with path
{ "^([-%w_%%%.]+[-%w_%%]%.(%a%a+)/%S+)", "%s"},
{ "%f[%S]([-%w_%%%.]+[-%w_%%]%.(%a%a+)/%S+)", "%s"},
-- X.Y.Z url
--{ "^([-%w_%%]+%.[-%w_%%]+%.%S+)", "%s"},
--{ "%f[%S]([-%w_%%]+%.[-%w_%%]+%.%S+)", "%s"},
}
--[[
-------------------------------------------------------------
Code
]]
local _G = _G
local format, gsub, strlen, strsub, strfind = string.format, string.gsub, string.len, string.sub, string.find
local pairs, type, date = pairs, type, date
-- Timestamps + Channel Names + UrlCopy (AddMessage hooks)
do
local orig = {}
local function AddMessageHook(frame, text, ...)
if type(text) == "string" then
-- Channel Names
for k, v in pairs(channelNamePattern) do
text = gsub(text, k, v)
end
-- url copy
if strlen(text) > 7 then
for i = 1, #urlPatterns do
local v = urlPatterns[i]
text = gsub(text, v[1], function(str) if strfind(str:lower(), ".blp:", 1, true) or strfind(str:lower(), ".tga:", 1, true) then return str else return format(urlStyle, str) end end)
end
end
-- Time Stamp
text = format(timeStampOutput, date(timeStampFormat), text)
end
return orig[frame](frame, text, ...)
end
for i = 1, NUM_CHAT_WINDOWS do
local c = _G["ChatFrame"..i]
orig[c] = c.AddMessage
c.AddMessage = AddMessageHook
end
local currentLink
hooksecurefunc("SetItemRef", function(link)
if strsub(link, 1, 19) == "garrmission:nevurl:" then
currentLink = strsub(link, 20)
StaticPopup_Show("SCMUrlCopyDialog")
end
end)
StaticPopupDialogs["SCMUrlCopyDialog"] = {
text = "URL",
button2 = CLOSE,
hasEditBox = 1,
hasWideEditBox = 1,
showAlert = 1,
OnShow = function(this)
local editBox = _G[this:GetName().."EditBox"]
if editBox then
editBox:SetText(currentLink)
editBox:SetFocus()
editBox:HighlightText(0)
end
local button = _G[this:GetName().."Button2"]
if button then
button:ClearAllPoints()
button:SetWidth(200)
button:SetPoint("CENTER", editBox, "CENTER", 0, -30)
end
local icon = _G[this:GetName().."AlertIcon"]
if icon then
icon:Hide()
end
end,
EditBoxOnEscapePressed = function(this) this:GetParent():Hide() end,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
}
end
-- Sticky
for k, v in pairs(stickyTypes) do
ChatTypeInfo[k].sticky = v and 1 or 0
end
-- Buttons
local FixChatButtons
do
-- Hide the chat shortcut button for emotes/languages/etc
ChatFrameMenuButton.Show = ChatFrameMenuButton.Hide
ChatFrameMenuButton:Hide()
-- Hide the quick join toast button
if QuickJoinToastButton then
QuickJoinToastButton.Show = QuickJoinToastButton.Hide
QuickJoinToastButton:Hide()
end
-- Hide the Chat Channel button
ChatFrameChannelButton.Show = ChatFrameChannelButton.Hide
ChatFrameChannelButton:Hide()
function FixChatButtons(i)
local f = _G[format("ChatFrame%dButtonFrame", i)]
-- Hide the button container
f.Show = f.Hide
f:Hide()
_G[format("ChatFrame%d", i)]:SetClampRectInsets(0,0,0,0) --Allow the chat frame to move to the end of the screen
end
for i = 1, NUM_CHAT_WINDOWS do
FixChatButtons(i)
end
if ChatFrame1.UpdateClampOffsets then
hooksecurefunc(ChatFrame1, "UpdateClampOffsets", function(frame) frame:SetClampRectInsets(0,0,0,0) end)
end
end
-- Editbox
local FixEditBox
do
function FixEditBox(i)
local eb = _G[format("%s%d%s", "ChatFrame", i, "EditBox")]
local cf = _G[format("%s%d", "ChatFrame", i)]
eb:ClearAllPoints()
eb:SetPoint("BOTTOMLEFT", cf, "TOPLEFT", -5, 0)
eb:SetPoint("BOTTOMRIGHT", cf, "TOPRIGHT", 5, 0)
eb:SetAltArrowKeyMode(false)
end
for i =1, NUM_CHAT_WINDOWS do
FixEditBox(i)
end
end
-- Scroll
local FixScroll
do
local function scroll(self, arg1)
if arg1 > 0 then
if IsShiftKeyDown() then
self:ScrollToTop()
elseif IsControlKeyDown() then
self:PageUp()
else
for i = 1, scrollLines do
self:ScrollUp()
end
end
elseif arg1 < 0 then
if IsShiftKeyDown() then
self:ScrollToBottom()
elseif IsControlKeyDown() then
self:PageDown()
else
for i = 1, scrollLines do
self:ScrollDown()
end
end
end
end
function FixScroll(i)
local cf = _G["ChatFrame"..i]
cf:SetScript("OnMouseWheel", scroll)
cf:EnableMouseWheel(true)
end
for i = 1, NUM_CHAT_WINDOWS do
FixScroll(i)
end
end
for i = 1, NUM_CHAT_WINDOWS do
_G["ChatFrame"..i].isNevModAugmented = true
end
hooksecurefunc("FCF_OpenTemporaryWindow", function()
for id, frame in pairs(CHAT_FRAMES) do
local cf = _G[frame]
if not cf.isNevModAugmented then
FixChatButtons(id)
FixEditBox(id)
FixScroll(id)
cf.isNevModAugmented = true
end
end
end)
-- disable timestamps
setfenv(ChatFrame_MessageEventHandler, setmetatable({CHAT_TIMESTAMP_FORMAT = false, GetChatTimestampFormat = function() end}, {__index = _G}))