-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGINVITER.lua
More file actions
332 lines (287 loc) · 10.2 KB
/
GINVITER.lua
File metadata and controls
332 lines (287 loc) · 10.2 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
-- Search mode "zone" or "class"
local SearchMode = "class"
-- Add or remove zones to search here
local SearchZone = { "Dalaran", "The Ruby Sanctum" }
-- Add or remove classes to search here
local SearchClass = { "Warrior", "Paladin", "Hunter", "Rogue", "Priest", "Death Knight", "Shaman", "Mage", "Warlock", "Druid" }
-- Loop interval in seconds
local loopInterval = 90
-- What level to search
local level = 80
-- Maximum number of invites before excluding a player
local maxInvites = 2
-- Add your desired zones to be excluded
local excludedZones = { "Dalaran Arena", "Nagrand Arena", "Blade's Edge Arena", "Ruins of Lordaeron" }
local initialSearchZone = { unpack(SearchZone) }
local initialSearchClass = { unpack(SearchClass) }
local searching = false
local searchStarted = false
local lastSearchTime = 0
local timeLeft = 0
local currentZone = 1
local currentClass = 1
local excludeList = {}
-- UI frame
local frame = CreateFrame("Frame", "GINVITERFrame", UIParent)
frame:SetSize(145, 135)
frame:SetPoint("CENTER")
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
frame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
local titleBar = CreateFrame("Frame", nil, frame)
titleBar:SetSize(frame:GetWidth(), 25)
titleBar:SetPoint("TOP", 0, 0)
titleBar:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
titleBar:SetBackdropColor(0.5, 0, 0.1, 1)
local titleText = titleBar:CreateFontString(nil, "ARTWORK", "GameFontNormal")
titleText:SetPoint("CENTER", titleBar, "CENTER")
titleText:SetText("GInviter")
titleText:SetTextColor(1, 1, 1)
local minimizeButton = CreateFrame("Button", nil, frame)
minimizeButton:SetSize(25, 25)
minimizeButton:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, 0)
minimizeButton:SetNormalTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Up")
minimizeButton:SetHighlightTexture("Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight")
minimizeButton:SetScript("OnClick", function() frame:Hide() end)
local statusText = frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
statusText:SetPoint("TOP", titleBar, "BOTTOM", 0, -10)
statusText:SetJustifyH("CENTER")
statusText:SetText("Stopped")
local timeText = frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
timeText:SetPoint("TOP", statusText, "BOTTOM", 0, -10)
timeText:SetJustifyH("CENTER")
timeText:SetText("Time left:")
local timeValue = frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
timeValue:SetPoint("TOP", timeText, "BOTTOM", 0, -5)
timeValue:SetJustifyH("CENTER")
timeValue:SetText("-")
local errorText = frame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
errorText:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -10, 10)
errorText:SetJustifyH("RIGHT")
errorText:SetText("")
local startButton = CreateFrame("Button", "GINVITERStartButton", frame, "UIPanelButtonTemplate")
startButton:SetSize(60, 20)
startButton:SetPoint("BOTTOMLEFT", 10, 10)
startButton:SetText("Start")
if searchStarted then
startButton:Disable()
else
startButton:Enable()
end
startButton:SetScript("OnClick", function() GINVITER_StartSearch() end)
local stopButton = CreateFrame("Button", "GINVITERStopButton", frame, "UIPanelButtonTemplate")
stopButton:SetSize(60, 20)
stopButton:SetPoint("BOTTOMLEFT", startButton, "BOTTOMRIGHT", 5, 0)
stopButton:SetText("Stop")
if not searchStarted then
stopButton:Disable()
else
stopButton:Enable()
end
stopButton:SetScript("OnClick", function() GINVITER_StopSearch() end)
-- Add to exclusion list
local function GINVITER_AddToExcludeList(playerName)
excludeList[playerName] = (excludeList[playerName] or 0) + 1
end
-- Excluded list
local function GINVITER_IsExcluded(playerName)
return excludeList[playerName] and excludeList[playerName] >= maxInvites
end
-- Slash Cmds
local function GINVITER_Command(args)
if (args == "show") then
frame:Show()
elseif (args == "hide") then
frame:Hide()
else
print("Usage: /ginviter [show/hide]")
end
end
-- Function to start the search
function GINVITER_StartSearch()
if CanGuildInvite() then
searching = true
lastSearchTime = time()
GINVITER_SendSearch()
timeLeft = 0
currentZone = 1
currentClass = 1
startButton:Disable()
stopButton:Enable()
print("|cffffff00GInviter:|r Starting..")
else
GINVITER_StopSearch()
print("|cffffff00GInviter:|r We are not in a guild. Join a guild to use GInviter.")
end
end
-- Function to stop the search
function GINVITER_StopSearch()
searching = false
statusText:SetText("Stopped")
timeValue:SetText("-")
startButton:Enable()
stopButton:Disable()
timeLeft = 0
currentZone = 1
currentClass = 1
SearchZone = table.clone(initialSearchZone)
SearchClass = table.clone(initialSearchClass)
print("|cffffff00GInviter:|r Stopped.")
end
-- Function to restart the search
function GINVITER_RestartSearch()
if CanGuildInvite() then
searching = true
lastSearchTime = time()
GINVITER_SendSearch()
timeLeft = 0
currentZone = 1
currentClass = 1
startButton:Disable()
stopButton:Enable()
print("|cffffff00GInviter:|r Restarting..")
else
GINVITER_StopSearch()
print("|cffffff00GInviter:|r We are not in a guild. Join a guild to use GInviter.")
end
end
-- Function to check guild member count
function GINVITER_CheckGuildMemberCount()
GuildRoster()
local numMembers = GetNumGuildMembers(true)
if numMembers >= 1000 then
GINVITER_StopSearch()
print("|cffffff00GInviter:|r Guild Full.")
return true
end
return false
end
-- Table clone
function table.clone(...)
local clones = {...}
local result = {}
for i, clone in ipairs(clones) do
for key, value in pairs(clone) do
if type(value) == "table" then
result[key] = table.clone(value)
else
result[key] = value
end
end
end
return result
end
-- Function to send the search query
function GINVITER_SendSearch()
if GINVITER_CheckGuildMemberCount() then
return
end
SetWhoToUI(1)
FriendsFrame:UnregisterEvent("WHO_LIST_UPDATE")
local whoString = ""
if SearchMode == "zone" then
if #SearchZone == 0 then
if #SearchClass == 0 then
GINVITER_RestartSearch()
return
end
SearchZone = table.clone(initialSearchZone)
end
local zoneIndex = math.random(1, #SearchZone)
local zone = table.remove(SearchZone, zoneIndex)
whoString = "g-\"\" " .. level .. " z-\"" .. zone .. "\""
statusText:SetText("Searching in\n" .. zone)
elseif SearchMode == "class" then
if #SearchClass == 0 then
if #SearchZone == 0 then
GINVITER_RestartSearch()
return
end
SearchClass = table.clone(initialSearchClass)
end
local classIndex = math.random(1, #SearchClass)
local class = table.remove(SearchClass, classIndex)
whoString = "g-\"\" " .. level .. " c-\"" .. class .. "\""
statusText:SetText("Searching for\n" .. class)
end
lastSearchTime = time()
SendWho(whoString)
end
-- Function to handle the update
local function GINVITER_OnUpdate(args)
if searching then
local timeLeft = lastSearchTime + loopInterval - time()
if timeLeft < 0 then
if CanGuildInvite() then
GINVITER_SendSearch()
else
GINVITER_StopSearch()
print("|cffffff00GInviter:|r We don't have /ginvite privileges. Ask the Guild Master or an Officer.")
end
else
timeValue:SetText(string.format("%.0f", timeLeft))
errorText:SetText("")
end
else
if #SearchZone == 0 or #SearchClass == 0 then
if #SearchZone == 0 then
SearchZone = table.clone(initialSearchZone)
end
if #SearchClass == 0 then
SearchClass = table.clone(initialSearchClass)
end
if not searching then
GINVITER_RestartSearch()
end
end
end
end
function GINVITER_OnEvent(args)
if (searching == false) then return end
GINVITER_InviteWhoResults()
GINVITER_CheckGuildMemberCount()
end
function GINVITER_OnLoad()
local initialSearchZone = table.clone(SearchZone)
local initialSearchClass = table.clone(SearchClass)
end
function GINVITER_InviteWhoResults()
local numWhos = GetNumWhoResults()
for index = 1, numWhos, 1 do
local charname, guildname, level, race, class, zone, classFileName = GetWhoInfo(index)
if (guildname == "" and not GINVITER_IsExcluded(charname) and not IsZoneExcluded(zone)) then
GINVITER_AddToExcludeList(charname)
GuildInvite(charname)
end
end
end
function IsZoneExcluded(zone)
for _, excludedZone in ipairs(excludedZones) do
if zone == excludedZone then
return true
end
end
return false
end
frame:SetScript("OnUpdate", GINVITER_OnUpdate)
frame:SetScript("OnEvent", GINVITER_OnEvent)
frame:SetScript("OnLoad", GINVITER_OnLoad)
frame:RegisterEvent("WHO_LIST_UPDATE")
frame:SetFrameStrata("LOW")
frame:SetClampedToScreen(true)
SLASH_GINVITER1 = "/GINVITER"
SlashCmdList["GINVITER"] = GINVITER_Command
print("|cffffff00GInviter:|r Use /GINVITER. Modify file ginviter.lua inside addon folder. Check |cffffff00github.com/nelbin4/ginviter|r for updates.")