-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAutoInvite.lua
356 lines (311 loc) · 10.3 KB
/
AutoInvite.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
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
local _, FS = ...
-- XXX KILL MODULE
do return end
local AutoInvite = FS:RegisterModule("AutoInvite")
local Console
local callTimer=0
local playerName,homeRealm,playerFullName
local raidSizeMax=40
local loopTok --timer token for invite loop
local maxlevel=100
local LEGION = select(4, GetBuildInfo()) >= 70000
if LEGION then
maxlevel=110
end
local connectedMates={}
local invited={}
------------------------------------------------------------------------------------------------------------------------
-- Config Auto Invite
------------------------------------------------------------------------------------------------------------------------
local autoinvite_default = {
profile = {
freq=5
}
}
local autoinvite_config = {
title = {
type = "description",
name = "|cff64b4ffAuto Invitation",
fontSize = "large",
order = 0
},
desc = {
type = "description",
name = "Group your guildmates as soon as they connect.\n",
fontSize = "medium",
order = 1
},
freq ={
type = "input",
name = "Invitation frequency",
get = function() return AutoInvite.settings.freq end,
set = function(_,val) if loopTok then AutoInvite:Stop() end AutoInvite.settings.freq=val end,
desc= "Time to wait in seconds before resending invitations to not invited players. Default 5 sec",
order = 5
},
ref = {
type = "header",
name = "Module reference",
order = 1000
},
cmds = FS.Config:MakeDoc("Available chat commands", 2000, {
{"inv", "Enable auto invite for all guild members"},
{"inv stop", "Disable auto invite"},
{"inv rank <rank>", "Enable auto invite for only guild members of rank <rank>"},
{"inv rank <x> <y>", "Enable auto invite for guild members of rank beween x and y (included)"},
{"inv level <x>", "Enable auto invite for guild members with level x"},
{"inv level <x> <y>", "Enable auto invite for guild members beween level x and y"},
}, "/fs "),
api = FS.Config:MakeDoc("Public API", 3000, {
{":InviteAll ( )", "Looping invitations of all connected guild members"},
{":InviteRank( guildRank )", "Looping invitations of all connected guild members having the specified rank. This rank can be the rankIndex or the rank name.\nBeware with ranks having spaces in it. The parameter is therefore \"The guild rank name\" "},
{":InviteRangeRank( guildRank1 , guildRank2 )", "Looping invitations of all connected guild members having a rank within the ranks provided. Ranks can also be the rankIndex or the rank name."},
{":InviteLevel( level )", "Looping invitations of all connected guild members having the specified level. Max level if no level provided."},
{":InviteRangeLevel( levelStart , levelStop )", "Looping invitations of all connected guild members having a level between the specified levels."},
{":Stop ( )", "Stops invitation looping."}
}, "FS.Invite"),
}
------------------------------------------------------------------------------------------------------------------------
-- Module initialization
function AutoInvite:OnInitialize()
Console = FS:GetModule("Console")
Console:RegisterCommand("inv", self)
self.db = FS.db:RegisterNamespace("AutoInvite", autoinvite_default)
self.settings = self.db.profile
FS.Config:Register("AutoInvite", autoinvite_config)
end
function AutoInvite:OnEnable()
homeRealm = GetRealmName()
homeRealm = homeRealm:gsub("%s+", "")
playerName = UnitName("player")
playerFullName = playerName.."-"..homeRealm
end
-----------------------------------------------------------------------------------------------------------------------------
-- Private
local function GetGuildRanks()
GuildRoster()
local numTotalMembers,_,_ = GetNumGuildMembers();
local ranks={}
for member=1,numTotalMembers,1 do
_, rk, rankIndex, _, _, _, _, _, _, _, _,_, _, _=GetGuildRosterInfo(member);
if not ranks[rankIndex+1] then
ranks[rankIndex+1]=rk
end
end
return ranks
end
local function GetConnected()
GuildRoster()
local _,_,numOnlineMembers = GetNumGuildMembers();
local connectedMates={}
for connected=1,numOnlineMembers,1 do
local name, rank, rankIndex, level, _, _, _, _, _, _, _,_, _, isMobile=GetGuildRosterInfo(connected);
connectedMates[#connectedMates+1]={["name"]=name,["rank"]=rank,["rankIndex"]=rankIndex,["level"]=level,["isMobile"]=isMobile }
end
return connectedMates
end
local function GetPplGroup()
local grouped={}
for i=1,GetNumGroupMembers(),1 do
local name=select(1,GetRaidRosterInfo(i))
if not name:find('%u%U*-%u%U') then
name=name.."-"..homeRealm
end
grouped[#grouped+1]=name
end
return grouped
end
local function update(typeCriteria,arg1,arg2)
if callTimer < 60 then
callTimer=callTimer+AutoInvite.settings.freq
else
callTimer=0
invited={}
end
local connectedMates=GetConnected() -- Get all ppl connected in guild
local grouped=GetPplGroup()
if connectedMates then
local connectedSelected={} --Select ppl filling the criteria
for i=1,#connectedMates,1 do
if typeCriteria == "rangeLevel" then
if connectedMates[i].level >= tonumber(arg1) and connectedMates[i].level <= tonumber(arg2) and not connectedMates[i].isMobile then
connectedSelected[#connectedSelected+1]=connectedMates[i]
end
elseif typeCriteria == "level" then
if connectedMates[i].level==tonumber(arg1) and not connectedMates[i].isMobile then
connectedSelected[#connectedSelected+1]=connectedMates[i]
end
elseif typeCriteria == "rangeRank" then
if connectedMates[i].rankIndex>=tonumber(arg1)and connectedMates[i].rankIndex<=tonumber(arg2) and not connectedMates[i].isMobile then
connectedSelected[#connectedSelected+1]=connectedMates[i]
end
elseif typeCriteria == "rank" then
if connectedMates[i].rankIndex == arg1 and not connectedMates[i].isMobile then
connectedSelected[#connectedSelected+1]=connectedMates[i]
end
else
if not connectedMates[i].isMobile then
connectedSelected[#connectedSelected+1]=connectedMates[i]
end
end
end
if #grouped < raidSizeMax then
for i=1,#connectedSelected,1 do
local invitation=true
for j=1,#grouped,1 do
if connectedSelected[i].name == grouped[j] then
invitation=false
break
end
end
if invitation then
for j=1,#invited,1 do
if connectedSelected[i].name == invited[j] then
invitation=false
break
end
end
end
--Convert to raid if party full and invites pending
if not IsInRaid() and #grouped==5 and invitation then
ConvertToRaid()
end
if invitation and connectedSelected[i].name~=playerFullName then
AutoInvite:Printf("Inviting "..connectedSelected[i].name) -- Might be unnecessary
InviteUnit(connectedSelected[i].name)
invited[#invited+1]=connectedSelected[i].name
end
end
end
end
end
-----------------------------------------------------------------------------------------------------------------------
-- Public API
function AutoInvite:InviteAll()
if loopTok then
self:Printf("Invitations already in progress, please stop them before to inviting again")
else
self:Printf("Inviting all connected members")
update()
loopTok=C_Timer.NewTicker(self.settings.freq, function() update() end)
end
end
function AutoInvite:InviteRank(guildRank)
if loopTok then
self:Printf("Invitations already in progress, please stop them before to inviting again")
else
local rank=tonumber(guildRank)
if not rank then
for k,v in pairs(GetGuildRanks()) do
if v==guildRank then
rank=k-1
end
end
end
if not rank or rank >= GuildControlGetNumRanks()then
self:Printf("Rank %s does not exists. Not inviting.",guildRank)
return
end
self:Printf("Inviting members with rank %s",guildRank)
update("rank",rank)
loopTok=C_Timer.NewTicker(self.settings.freq, function() update("rank",rank) end)
end
end
function AutoInvite:InviteRangeRank(guildRank1,guildRank2)
if loopTok then
self:Printf("Invitations already in progress, please stop them before to inviting again")
else
local rk1=tonumber(guildRank1)
local rk2=tonumber(guildRank2)
--Parameters are not numbers
if not rk1 or not rk2 then
for k,v in pairs(GetGuildRanks()) do
if v==guildRank1 then
rk1=k-1
end
if v==guildRank2 then
rk2=k-1
end
end
end
if rk1 and rk2 and rk1>rk2 then
local tmp=rk1
rk1=rk2
rk2=tmp
end
if not rk1 or not rk2 or rk2 >= GuildControlGetNumRanks()then
self:Printf("One of the ranks does not exists. Not inviting.")
return
end
self:Printf("Inviting members between rank %s and %s",guildRank1,guildRank2)
update("rangeRank",rk1,rk2)
loopTok=C_Timer.NewTicker(self.settings.freq, function() update("rangeRank",rk1,rk2) end)
end
end
function AutoInvite:InviteLevel(level)
if loopTok then
self:Printf("Invitations already in progress, please stop them before to inviting again")
else
if not tonumber(level) then
level=maxlevel
else
level=tonumber(level)
end
self:Printf("Inviting members at level %d",level)
update("level",level)
loopTok=C_Timer.NewTicker(self.settings.freq, function() update("level",level) end)
end
end
function AutoInvite:InviteRangeLevel(levelStart,levelStop)
if loopTok then
self:Printf("Invitations already in progress, please stop them before to inviting again")
else
if tonumber(levelStart) > tonumber(levelStop)then
local tmp=tonumber(levelStart)
levelStart=levelStop
levelStop=tmp
end
if levelStop > maxlevel then
levelStop=maxlevel
self:Printf("Limiting invites to max level")
end
self:Printf("Inviting members beteween level %d and %d",levelStart,levelStop)
update("rangeLevel",levelStart,levelStop)
loopTok=C_Timer.NewTicker(self.settings.freq, function() update("rangeLevel",levelStart,levelStop) end)
end
end
function AutoInvite:Stop()
if loopTok then
loopTok:Cancel()
loopTok=nil --to be sure
callTimer=0
invited={}
self:Printf("Invitations stopped")
end
end
--------------------------------------------------------------------------------
-- Slash command handler
function AutoInvite:OnSlash(arg1,arg2,arg3)
if arg1 then
if arg1 == "stop" then
self:Stop()
elseif arg1 == "rank" then
if arg2 and not arg3 then
self:InviteRank(arg2)
end
if arg2 and arg3 then
self:InviteRangeRank(arg2,arg3)
end
elseif arg1 == "level" then
if arg2 and not arg3 then
self:InviteLevel(tonumber(arg2))
elseif arg2 and arg3 then
self:InviteRangeLevel(tonumber(arg2),tonumber(arg3))
else
self:InviteLevel()
end
end
else
self:InviteAll()
end
end