-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathurlcopy.lua
137 lines (128 loc) · 6.45 KB
/
urlcopy.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
--[[ URLCopy Module ]]--
local _, BCM = ...
BCM.modules[#BCM.modules+1] = function()
if bcmDB.BCM_URLCopy then return end
local gsub = string.gsub
local one = "|cffffffff|Hgarrmission:BCMuc:|h[%1]|h|r"
local two = "%1|cffffffff|Hgarrmission:BCMuc:|h[%2]|h|r"
-- This functionality used to be stricter and more complex, but with the introduction
-- of gTLDs of any form or language, we can now reduce the amount of patterns.
-- Sentences like "I wish.For someone" will become URLs now "[wish.For]", and although they seem
-- like false positives, they can be genuine.
-- Easily readable, right? :D
-- We're converting anything in the form of "word.word" to a URL,
-- but we're adding a list of excluded symbols such as {}[]` that aren't a valid address, to prevent possible false positives.
-- Also note that the only difference between the 1st and 2nd section of the pattern is that the 2nd has a few extra
-- valid (but invalid in their location) things ".", "/", "," to prevent words like "lol...", "true./" and "yes.," becoming a URL.
-- As of the introduction of the S.E.L.F.I.E camera we now require at least 2 valid letters for example: yo.hi
local filterFunc = function(_, _, msg, ...)
-- [ ]url://a.b.cc.dd/e
local newMsg, found = gsub(msg,
"( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %p%c%d][^ %p%c%d]+/[^ \"%^`{}%[%]\\|<>]+)",
two
)
if found > 0 then return false, newMsg, ... end
-- ^url://a.b.cc.dd/e
newMsg, found = gsub(msg,
"^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %p%c%d][^ %p%c%d]+/[^ \"%^`{}%[%]\\|<>]+",
one
)
if found > 0 then return false, newMsg, ... end
-- [ ]url://a.bb.cc/d
newMsg, found = gsub(msg,
"( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %p%c%d][^ %p%c%d]+/[^ \"%^`{}%[%]\\|<>]+)",
two
)
if found > 0 then return false, newMsg, ... end
-- ^url://a.bb.cc/d
newMsg, found = gsub(msg,
"^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %p%c%d][^ %p%c%d]+/[^ \"%^`{}%[%]\\|<>]+",
one
)
if found > 0 then return false, newMsg, ... end
-- [ ]url://aa.bb/c
newMsg, found = gsub(msg,
"( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %p%c%d][^ %p%c%d]+/[^ \"%^`{}%[%]\\|<>]+)",
two
)
if found > 0 then return false, newMsg, ... end
-- ^url://aa.bb/c
newMsg, found = gsub(msg,
"^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %p%c%d][^ %p%c%d]+/[^ \"%^`{}%[%]\\|<>]+",
one
)
if found > 0 then return false, newMsg, ... end
-- [ ]url://a.b.cc.dd
newMsg, found = gsub(msg,
"( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %p%c%d][^ %p%c%d]+)",
two
)
if found > 0 then return false, newMsg, ... end
-- ^url://a.b.cc.dd
newMsg, found = gsub(msg,
"^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %p%c%d][^ %p%c%d]+",
one
)
-- [ ]url://a.bb.cc
newMsg, found = gsub(msg,
"( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %p%c%d][^ %p%c%d]+)",
two
)
if found > 0 then return false, newMsg, ... end
-- ^url://a.bb.cc
newMsg, found = gsub(msg,
"^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+%.[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %p%c%d][^ %p%c%d]+",
one
)
-- [ ]url://aa.bb
newMsg, found = gsub(msg,
"( )([^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %p%c%d][^ %p%c%d]+)",
two
)
if found > 0 then return false, newMsg, ... end
-- ^url://aa.bb
newMsg, found = gsub(msg,
"^[^ %%'=%.,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~]+[^ %%'=%./,\"%^`{}%[%]\\|<>%(%)%*!%?_%+#&;~:]%.[^ %p%c%d][^ %p%c%d]+",
one
)
if found > 0 then return false, newMsg, ... end
newMsg, found = gsub(msg,
-- Numbers are banned from the first pattern to prevent false positives like "5.5k" etc.
-- This is our IPv4/v6 pattern at the beggining of a sentence.
"^%x+[%.:]%x+[%.:]%x+[%.:]%x+[^ \"%^`{}%[%]\\|<>]*",
one
)
if found > 0 then return false, newMsg, ... end
newMsg, found = gsub(msg,
-- This is our mid-sentence IPv4/v6 pattern, we separate the IP patterns into 2 to prevent
-- false positives with linking items, spells, etc.
"( )(%x+[%.:]%x+[%.:]%x+[%.:]%x+[^ \"%^`{}%[%]\\|<>]*)",
two
)
if found > 0 then return false, newMsg, ... end
end
ChatFrame_AddMessageEventFilter("CHAT_MSG_CHANNEL", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_YELL", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_GUILD", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_OFFICER", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY_LEADER", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_LEADER", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_WARNING", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_INSTANCE_CHAT", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_INSTANCE_CHAT_LEADER", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_SAY", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_WHISPER", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_WHISPER_INFORM", filterFunc)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_INLINE_TOAST_BROADCAST", filterFunc)
hooksecurefunc("SetItemRef", function(link, text)
local _, bcm = strsplit(":", link)
if bcm == "BCMuc" then
text = gsub(text, "^[^%[]+%[(.+)%]|h|r$", "%1")
BCM:Popup(text)
end
end)
end