Repository navigation
Expand file tree
/
Copy pathChatHelper.lua
More file actions
144 lines (119 loc) · 4.5 KB
/
Copy pathChatHelper.lua
File metadata and controls
144 lines (119 loc) · 4.5 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
SLASH_RELOADUI1 = "/r" -- a shorter command for faster reloading of the interface
SlashCmdList.RELOADUI = ReloadUI
local white = "|cFFFFFFFF"
local yellow = "|cFFFFFF00"
local function LoadedAddOn(self, event, name)
if name == "ChatHelper" then
print(yellow.."ChatHelper: "..white.."Use "..yellow.."/ch"..white.." to open the menu")
end
end
local start = CreateFrame("Frame")
start:RegisterEvent("ADDON_LOADED")
start:SetScript("OnEvent", LoadedAddOn)
---------------------------------------------------------------------------------
UIConfig = CreateFrame("Frame", "ChatHelperFrame", UIParent, "UIPanelDialogTemplate")
UIConfig:SetSize(200,230)
UIConfig:SetPoint("CENTER", UIParent, "CENTER")
UIConfig:Hide()
-- Window Flexibility
UIConfig:EnableMouse(true)
UIConfig:SetMovable(true)
UIConfig:SetResizable(true)
UIConfig:SetMinResize(185,215)
UIConfig:SetMaxResize(210,240)
-- Dragging
UIConfig:RegisterForDrag("LeftButton")
UIConfig:SetScript("OnDragStart", UIConfig.StartMoving)
UIConfig:SetScript("OnDragStop", UIConfig.StopMovingOrSizing)
-- Resize Button
UIConfig.resizeBtn = CreateFrame("Button", nil, UIConfig)
UIConfig.resizeBtn:SetSize(16, 16)
UIConfig.resizeBtn:SetPoint("BOTTOMRIGHT",-4,7)
UIConfig.resizeBtn:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
UIConfig.resizeBtn:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
UIConfig.resizeBtn:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
UIConfig.resizeBtn:SetScript("OnMouseDown", function(self, button)
self:GetParent():StartSizing("BOTTOMRIGHT")
end)
UIConfig.resizeBtn:SetScript("OnMouseUp", function(self, button)
self:GetParent():StopMovingOrSizing()
end)
-- Title
UIConfig.title = UIConfig:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
UIConfig.title:SetPoint("CENTER", UIConfig, "TOP", 0, -15)
UIConfig.title:SetText("ChatHelper")
-- Text Input for the keywords
UIConfig.editBox = CreateFrame("EditBox", "InputBox", UIConfig, "InputBoxTemplate")
UIConfig.editBox:SetPoint("TOP", UIConfig.title, "TOP", 0, -60)
UIConfig.editBox:SetSize(115, 30)
UIConfig.editBox:SetAutoFocus(false)
UIConfig.editBox:SetMultiLine(false)
local placeholder = "Key words"
local function SetPlaceholder()
UIConfig.editBox:SetText(placeholder)
UIConfig.editBox:SetTextColor(0.5, 0.5, 0.5)
UIConfig.editBox:EnableMouse(true)
end
SetPlaceholder()
UIConfig.editBox:SetScript("OnEditFocusGained", function(self) self:SetText("") self:SetTextColor(1, 1, 1) end)
UIConfig.editBox:SetScript("OnEditFocusLost", function(self)
if self:GetText() == "" then
SetPlaceholder()
end
end)
UIConfig.editBox:SetScript("OnTextChanged", function(self, userinput)
if self:GetText() ~= placeholder then
if #self:GetText() > 0 then
UIConfig.startBtn:Enable()
else
UIConfig.startBtn:Disable()
UIConfig.stopBtn:Disable()
end
else
UIConfig.startBtn:Disable()
UIConfig.stopBtn:Disable()
end
end)
-- Start Button
UIConfig.startBtn = CreateFrame("Button", nil, UIConfig, "GameMenuButtonTemplate")
UIConfig.startBtn:Enable()
UIConfig.startBtn:Disable()
UIConfig.startBtn:SetPoint("CENTER", UIConfig, "CENTER", 0, -10)
UIConfig.startBtn:SetSize(100,30)
UIConfig.startBtn:SetText("Start Searching")
local words
local searching
UIConfig.startBtn:SetScript("OnClick", function(self)
searching = true
UIConfig.stopBtn:Enable()
UIConfig.editBox:EnableMouse(false)
UIConfig.editBox:ClearFocus()
words = UIConfig.editBox:GetText()
-- Track messages
chattracking = CreateFrame("Frame")
chattracking:RegisterEvent("CHAT_MSG_CHANNEL")
chattracking:SetScript("OnEvent", function(self, event, text, playername, languagename, channelname)
if not searching then
return
end
for word in string.gmatch(words, "%S+") do
if string.find(string.lower(text), string.lower(word)) then
message(white.."Found "..yellow..word..white.." in "..yellow..channelname..white.."\nSent From: "..yellow..playername)
return
end
end
end)
end)
-- Stop Button
UIConfig.stopBtn = CreateFrame("Button", nil, UIConfig, "GameMenuButtonTemplate")
UIConfig.stopBtn:Enable()
UIConfig.stopBtn:Disable()
UIConfig.stopBtn:SetPoint("CENTER", UIConfig, "CENTER", 0, -40)
UIConfig.stopBtn:SetSize(100,30)
UIConfig.stopBtn:SetText("Stop")
UIConfig.stopBtn:SetScript("OnClick", function(self) searching = false SetPlaceholder() end)
function OpenMenu()
UIConfig:Show()
end
SLASH_OPENMENU1 = "/ch" -- Main command for displaying the menu
SlashCmdList.OPENMENU = OpenMenu