vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- *:***************************************************************
2 -- AutoDecline
3 -- Automatically decline guild/party/duel invites
4  
5 versionInfo = "1.3.1600"
6  
7 -- ------------------------------------------------
8 -- Revisions
9  
10 -- v1.3.1600 ** start 08-14-05
11 -- -Added functionality to always allow invites from your guild
12 -- -Moved text from configuration screen into the localization.lua file
13 -- -Made a change to the options screen to better indicate that checking party/guild/duel/charter meant that those types of requests would be declined
14 -- -Added new option to use the same settings for all characters
15 -- -Fixed a bug where not including on or off for an option was supposed to toggle that option, but it was not.
16 -- -Added functionality to perform a list of command line actions when doing a decline
17 -- -Lenghened last whisper history to include the last 5 names
18 -- -Changed party list commands
19 -- -Added new command to add the last player to send a party invite to the allowed list
20  
21 -- v1.2.1600 ** 07/14/05
22 -- -Updated interface number to 1600 in .toc file.
23 -- -Added functionality to always allow invites from names in the friends list
24 -- -Added new checkbox to settings window to turn allowing invites from friends on and off
25 -- -Added new toggle command line option partyfriends {on|off}
26 -- -Added functionality to always allow invites from last player to send a whisper
27 -- -Added new checkbox to settings window to turn allowing invites from last whisper on and off
28 -- -Added new toggle command line option partywhisper {on|off}
29 -- -Removed DEFAULTS button from settings screen
30  
31 -- v1.1.1300 ** 03/30/05 (not released)
32 -- -Added functionality to always allow invites from a specified list of names
33 -- -Added command line commands partyadd, partyremove, and partylist.
34  
35 -- v1.0.1300 ** 03/23/05
36 -- -Updated interface number to 1300 in .toc file.
37 -- -Changed version numbering to include interface number
38  
39 -- v1.0 ** 03/17/2005
40 -- -Initial Release
41  
42 -- ------------------------------------------------
43 -- Commands
44 -- party/guild/duel/charter/partyfriends/partywhisper on/off - turn on or off
45 -- status - show status
46 -- /ad, /autod, or /autodecline to bring up options window
47  
48 -- partyplayer add - add a name to always allow party invites list
49 -- partyplayer remove - remove a name from always allow party invites list
50 -- partyplayer list - list names to always allow party invites from
51 -- partyguild add - add a guild name to always allow party invites list
52 -- partyguild remove - remove a guild name from always allow party invites list
53 -- partyguild list - list guild names to always allow party invites from
54  
55 -- ------------------------------------------------
56 -- Features in Beta
57 -- new party list command - clear
58 -- changed partyadd, partyremove, partylist to partyplayer {add|remove|list|clear}
59 -- new command partyguild {add|remove|list|clear}
60 -- new functionality - allow party invites from a specified list of guilds
61 --
62 -- ------------------------------------------------
63 -- Features to add at a future date:
64 -- New command /ad addlastinvite to add the last player who sent an invite to the allowed list.
65 -- GUI list of names to always allow invites from (way low on list of things to do)
66  
67 -- *:***************************************************************
68  
69 -- Initialize local variables
70 playerName = nil
71 playerID = nil
72 localPlayerID = nil
73 realmID = nil
74 showAlert = true
75 AutoDeclineFriends = {}
76 whisperNames = {}
77 whisperLimit = 5
78 debugMode = nil
79 optionsFrame = nil
80 lastInvite = nil
81 cancelFriendList = nil
82 variablesLoaded = nil
83 dataLoaded = nil
84 adCheckingGuild = nil
85 adLoopStop = nil
86  
87 -- *:***************************************************************
88 -- *: AutoDecline_OnLoad
89 -- *: Executes when the OnLoad event occurs
90 -- *:***************************************************************
91 function AutoDecline_OnLoad()
92 -- *: Moved these to the AutoDecline.toc file
93 -- RegisterForSave("AutoDeclineConfig")
94 -- RegisterForSave("AutoDeclinePartyAllow")
95 -- RegisterForSave("AutoDeclinePartyGuildAllow")
96 -- RegisterForSave("AutoDeclineActions")
97 -- RegisterForSave("persistentDebug")
98  
99 this:RegisterEvent("VARIABLES_LOADED")
100 this:RegisterEvent("GUILD_INVITE_REQUEST")
101 this:RegisterEvent("PARTY_INVITE_REQUEST")
102 this:RegisterEvent("DUEL_REQUESTED")
103 this:RegisterEvent("PETITION_SHOW")
104 this:RegisterEvent("PLAYER_ENTERING_WORLD")
105 this:RegisterEvent("UNIT_NAME_UPDATE")
106 this:RegisterEvent("FRIENDLIST_UPDATE")
107 this:RegisterEvent("CHAT_MSG_WHISPER")
108 this:RegisterEvent("FRIENDLIST_SHOW")
109 this:RegisterEvent("WHO_LIST_UPDATE")
110 end
111  
112 -- *:***************************************************************
113 function AutoDecline_LoadPlayerInfo()
114 if not playerID then
115 local tempName = UnitName("player")
116 AutoDecline_Debug("Initializing playerID to " .. FormatOutput(tempName) )
117 if tempName and (tempName ~= "Unknown Entity") then
118 playerName = tempName
119 end
120 end
121 if (variablesLoaded) and (not dataLoaded) and playerName then
122 AutoDecline_LoadData();
123 end
124 end
125  
126 -- *:***************************************************************
127 function AutoDecline_OnEvent(event)
128 -- AutoDecline_Debug(format("%s firing", event) )
129 if (event == "VARIABLES_LOADED") then
130 AutoDecline_Debug(format("%s firing", event) )
131 variablesLoaded = true
132 AutoDecline_Init()
133 end
134  
135 if (event == "PLAYER_ENTERING_WORLD") or (event == "VARIABLES_LOADED") or (event == "UNIT_NAME_UPDATE") then
136 AutoDecline_Debug(format("%s firing", event) )
137 AutoDecline_LoadPlayerInfo()
138 end
139  
140 if dataLoaded then
141  
142 if (event == "GUILD_INVITE_REQUEST") then
143 AutoDecline_Debug(format("%s firing", event) )
144 AutoDecline_Guild(arg1, arg2)
145 end
146  
147 if (event == "PARTY_INVITE_REQUEST") then
148 AutoDecline_Debug(format("%s firing", event) )
149 AutoDecline_Party(arg1)
150 end
151  
152 if (event == "PETITION_SHOW") then
153 AutoDecline_Debug(format("%s firing", event) )
154 AutoDecline_Charter()
155 end
156  
157 if (event == "DUEL_REQUESTED") then
158 AutoDecline_Debug(format("%s firing", event) )
159 AutoDecline_Duel(arg1)
160 end
161  
162 if (event == "FRIENDLIST_UPDATE" ) then
163 -- AutoDecline_Debug(format("%s firing", event) )
164 AutoDecline_LoadFriendsList()
165 end
166  
167 if (event == "CHAT_MSG_WHISPER" ) then
168 -- AutoDecline_Debug(format("%s firing", event) )
169 AutoDecline_SetLastWhisper(arg2)
170 end
171  
172 if (event == "FRIENDLIST_SHOW") then
173 AutoDecline_Debug(format("%s firing", event) )
174 AutoDecline_Debug("cancelFriendList = " .. FormatOutput(cancelFriendList))
175 if cancelFriendList then
176 AutoDecline_HideWindow("FriendsFrame")
177 cancelFriendList = nil
178 end
179 end
180  
181 if (event == "WHO_LIST_UPDATE") then
182 -- adCheckingGuild
183 -- AutoDecline_Debug(format("%s firing", event) )
184 AutoDecline_Debug("WHO_LIST_UPDATE fired")
185 end
186  
187 end
188 end
189  
190 -- *:***************************************************************
191 function AutoDecline_Init()
192 AutoDecline_Debug("AutoDecline_Init() firing")
193  
194 SlashCmdList["AUTOD"] = AutoDecline_Commands
195 SLASH_AUTOD1 = "/autodecline"
196 SLASH_AUTOD2 = "/autod"
197 SLASH_AUTOD3 = "/ad"
198 end
199  
200 -- *:***************************************************************
201 function AutoDecline_LoadData()
202 AutoDecline_Debug("AutoDecline_LoadData() firing")
203 AutoDecline_Debug("variablesLoaded = " .. FormatOutput(variablesLoaded) )
204  
205 -- if (playerName ~= nil and playerName ~= "Unknown Entity") and variablesLoaded then
206 if (type(playerName) == "string" and playerName ~= "Unknown Entity") and variablesLoaded then
207 dataLoaded = true
208 realmID = GetCVar("realmName")
209 playerID = playerName .. "@" .. realmID
210 localPlayerID = playerID
211  
212 AutoDecline_Debug("Setting playerID to " .. playerID )
213 AutoDecline_LoadFriendsList()
214  
215 debugMode = AUTODECLINE_DEBUG
216 optionsFrame = getglobal("ADOptionsFrame")
217  
218 -- Initialize configuration
219 -- If this has been populated before, then it was loaded in the OnEvent
220 -- subroutine. Otherwise, we need to initialize it.
221  
222 if (not AutoDeclineConfig) then
223 AutoDecline_Debug("Initializing AutoDeclineConfig")
224 AutoDeclineConfig = {}
225 end
226  
227 if AutoDeclineConfig["allChars"] then
228 playerID = "allChars"
229 -- playerID = AutoDeclineConfig["allChars"]
230 -- AutoDecline_Debug( "AutoDeclineConfig['allChars'] = " .. FormatOutput(AutoDeclineConfig["allChars"]) )
231 -- AutoDecline_Debug( "playerID = " .. FormatOutput(playerID) )
232 end
233  
234 if (not AutoDeclineConfig[playerID]) then
235 AutoDecline_Debug(format("Initializing AutoDeclineConfig[%s]",playerID))
236 AutoDeclineConfig[playerID] = {}
237 end
238  
239 if AutoDeclineConfig["allChars"] then
240 AutoDeclineConfig[localPlayerID] = AutoDeclineConfig[playerID]
241 end
242  
243 if (not AutoDeclinePartyAllow) then
244 AutoDecline_Debug("Initializing AutoDeclinePartyAllow")
245 AutoDeclinePartyAllow = {}
246 end
247 if (not AutoDeclinePartyAllow[realmID]) then
248 AutoDecline_Debug(format("Initializing AutoDeclinePartyAllow[%s]",realmID))
249 AutoDeclinePartyAllow[realmID] = {}
250 end
251  
252 if (not AutoDeclinePartyGuildAllow) then
253 AutoDecline_Debug("Initializing AutoDeclinePartyGuildAllow")
254 AutoDeclinePartyGuildAllow = {}
255 end
256 if (not AutoDeclinePartyGuildAllow[realmID]) then
257 AutoDecline_Debug(format("Initializing AutoDeclinePartyGuildAllow[%s]",realmID))
258 AutoDeclinePartyGuildAllow[realmID] = {}
259 end
260  
261 if (not AutoDeclineActions) then
262 AutoDecline_Debug("Initializing AutoDeclineActions")
263 AutoDeclineActions = {}
264 end
265  
266 -- set the defaults
267 -- default all to be on (decline)
268 if (AutoDeclineConfig[playerID].guildToggle == nil) then
269 AutoDeclineConfig[playerID].guildToggle = true
270 end
271 if (AutoDeclineConfig[playerID].partyToggle == nil) then
272 AutoDeclineConfig[playerID].partyToggle = true
273 end
274 if (AutoDeclineConfig[playerID].duelToggle == nil) then
275 AutoDeclineConfig[playerID].duelToggle = true
276 end
277 if (AutoDeclineConfig[playerID].charterToggle == nil) then
278 AutoDeclineConfig[playerID].charterToggle = true
279 end
280  
281 -- default showAlert to be on (display message when an auto decline occurs)
282 if (AutoDeclineConfig[playerID].showAlert == nil) then
283 AutoDeclineConfig[playerID].showAlert = true
284 end
285  
286 -- default partyFriends to true (allow from friends)
287 if (AutoDeclineConfig[playerID].partyFriends == nil) then
288 AutoDeclineConfig[playerID].partyFriends = true
289 end
290  
291 -- default partyFriends to true (allow from friends)
292 if (AutoDeclineConfig[playerID].partyGuild == nil) then
293 AutoDeclineConfig[playerID].partyGuild = true
294 end
295  
296 -- default partyWhisper to false (don't allow from last whisper)
297 if (AutoDeclineConfig[playerID].partyWhisper == nil) then
298 AutoDeclineConfig[playerID].partyWhisper = false
299 end
300  
301 --display AddOn loaded message at startup
302 AutoDecline_Display(format(AD_LOAD_MSG, versionInfo))
303 AutoDecline_Display(AD_HELP)
304 AutoDecline_Display(AD_SYNTAX)
305 -- AutoDecline_Commands("status")
306  
307 end
308 end
309  
310 -- *:***************************************************************
311 function AutoDecline_Unload()
312 this:UnregisterEvent("VARIABLES_LOADED")
313 this:UnregisterEvent("GUILD_INVITE_REQUEST")
314 this:UnregisterEvent("PARTY_INVITE_REQUEST")
315 this:UnregisterEvent("DUEL_REQUESTED")
316 this:UnregisterEvent("PETITION_SHOW")
317 this:UnregisterEvent("PLAYER_ENTERING_WORLD")
318 this:UnregisterEvent("UNIT_NAME_UPDATE")
319 this:UnregisterEvent("FRIENDLIST_UPDATE")
320 this:UnregisterEvent("CHAT_MSG_WHISPER")
321 this:UnregisterEvent("FRIENDLIST_SHOW")
322 this:UnregisterEvent("WHO_LIST_UPDATE")
323  
324 SlashCmdList["AUTOD"] = nil
325 end
326  
327 -- *:***************************************************************
328 function AutoDecline_Commands(commandLine)
329  
330 local commandLineProcessed = false
331 commandLine = TrimSpace(commandLine)
332  
333 actionVerb, argArray, argString = GetCommand(commandLine, ",")
334  
335 if (actionVerb == "debug") then
336 if string.lower(argArray[1]) == "on" then
337 AutoDecline_Display( "Debug mode ON" )
338 debugMode = true
339 elseif (string.lower(argArray[1]) == "persistent") then
340 AUTODECLINE_DEBUG = (not AUTODECLINE_DEBUG)
341 if AUTODECLINE_DEBUG then
342 AutoDecline_Display( "Persistent debug mode ON" )
343 else
344 AutoDecline_Display( "Persistent debug mode OFF" )
345 end
346 debugMode = AUTODECLINE_DEBUG
347 else
348 AutoDecline_Display( "Debug mode OFF" )
349 debugMode = false
350 end
351 else
352  
353 if not playerID then
354 AutoDecline_LoadPlayerInfo()
355 end
356  
357 if playerID then
358 -- *: I can't think of any reason where this would be useful as a command line option,
359 -- *: so I'm going to leave it as a GUI check box only.
360 -- elseif actionVerb == "allchars" then
361  
362 if (actionVerb == "about") then
363 AutoDecline_Display(format(AD_VERSION_INFO, versionInfo))
364 AutoDecline_Display(AD_BYLINE)
365  
366 elseif (commandLine == "") or (actionVerb == "options") then
367 if not optionsFrame:IsVisible() then
368 optionsFrame:Show();
369 else
370 optionsFrame:Hide();
371 end
372  
373 elseif (actionVerb == "status") or (actionVerb == "s") then
374 AutoDecline_ShowStatus()
375  
376 elseif (actionVerb == "alert") or (actionVerb == "a") then
377 AutoDeclineConfig[playerID].showAlert = AutoDecline_SetStatus(argArray[1], AutoDeclineConfig[playerID].showAlert)
378 AutoDecline_Display(iif(AutoDeclineConfig[playerID].showAlert, AD_ALERT_ON, AD_ALERT_OFF))
379  
380 elseif (actionVerb == "guild") or (actionVerb == "g") then
381 AutoDeclineConfig[playerID].guildToggle = AutoDecline_SetStatus(argArray[1], AutoDeclineConfig[playerID].guildToggle)
382 AutoDecline_Display(iif(AutoDeclineConfig[playerID].guildToggle, AD_GUILD_ON, AD_GUILD_OFF))
383  
384 elseif (actionVerb == "party") or (actionVerb == "p") then
385 AutoDeclineConfig[playerID].partyToggle = AutoDecline_SetStatus(argArray[1], AutoDeclineConfig[playerID].partyToggle)
386 AutoDecline_Display(iif(AutoDeclineConfig[playerID].partyToggle, AD_PARTY_ON, AD_PARTY_OFF))
387  
388 elseif (actionVerb == "duel") or (actionVerb == "d") then
389 AutoDeclineConfig[playerID].duelToggle = AutoDecline_SetStatus(argArray[1], AutoDeclineConfig[playerID].duelToggle)
390 AutoDecline_Display(iif(AutoDeclineConfig[playerID].duelToggle, AD_DUEL_ON, AD_DUEL_OFF))
391  
392 elseif (actionVerb == "charter") or (actionVerb == "c") then
393 AutoDeclineConfig[playerID].charterToggle = AutoDecline_SetStatus(argArray[1], AutoDeclineConfig[playerID].charterToggle)
394 AutoDecline_Display(iif(AutoDeclineConfig[playerID].charterToggle, AD_CHARTER_ON, AD_CHARTER_OFF))
395  
396 elseif (actionVerb == "partyfriends") or (actionVerb == "pf") then
397 AutoDeclineConfig[playerID].partyFriends = AutoDecline_SetStatus(argArray[1], AutoDeclineConfig[playerID].partyFriends)
398 AutoDecline_Display(iif(AutoDeclineConfig[playerID].partyFriends, AD_PARTYFRIENDS_ON, AD_PARTYFRIENDS_OFF))
399  
400 elseif (actionVerb == "partywhisper") or (actionVerb == "pw") then
401 AutoDeclineConfig[playerID].partyWhisper = AutoDecline_SetStatus(argArray[1], AutoDeclineConfig[playerID].partyWhisper)
402 AutoDecline_Display(iif(AutoDeclineConfig[playerID].partyWhisper, AD_PARTYWHISPER_ON, AD_PARTYWHISPER_OFF))
403  
404 elseif (actionVerb == "addlastinvite") or (actionVerb == "ali") then
405 if lastInvite then
406 AutoDecline_AddList(AutoDeclinePartyAllow, { lastInvite }, AD_LASTINVITE_ADD)
407 else
408 AutoDecline_Display( AD_LASTINVITE_NONE )
409 end
410  
411 elseif (actionVerb == "partyplayer") or (actionVerb == "pp") then
412 subVerb, argArray, argString = GetCommand(argString, ",")
413 if (subVerb == "add") or (subVerb == "a")then
414 AutoDecline_AddList(AutoDeclinePartyAllow, argArray, AD_PARTYPLAYER_ADD)
415 elseif (subVerb == "remove") or (subVerb == "r") then
416 for argIndex,argValue in argArray do
417 if (type(argValue) == "string") and (string.len(argValue) > 0) then
418 AutoDeclinePartyAllow[realmID][string.lower(argValue)] = false
419 AutoDecline_Display(format(AD_PARTYPLAYER_REMOVE, argValue))
420 end
421 end
422 elseif (subVerb == "list") or (subVerb == "l") then
423 AutoDecline_Display(AD_PARTYPLAYER_LIST)
424 for personName in AutoDeclinePartyAllow[realmID] do
425 if AutoDeclinePartyAllow[realmID][personName] then
426 AutoDecline_Display(" " .. personName)
427 end
428 end
429 elseif (subVerb == "clear") or (subVerb == "c") then
430 AutoDeclinePartyAllow[realmID] = {}
431 AutoDecline_Display(AD_PARTYPLAYER_CLEAR)
432 end
433  
434 elseif (actionVerb == "partyguild") then
435 AutoDeclineConfig[playerID].partyGuild = AutoDecline_SetStatus(argArray[1], AutoDeclineConfig[playerID].partyGuild)
436 AutoDecline_Display(iif(AutoDeclineConfig[playerID].partyGuild, AD_PARTYGUILD_ON, AD_PARTYGUILD_OFF))
437  
438 --[[
439 -- This doesn't work, the WoW AI currently does not support a good way of
440 -- getting the guild name of a player given the players name. This will have
441 -- to wait until some future time when and if they do support that.
442 subVerb, argArray, argString = GetCommand(argString, ",")
443 if (subVerb == "add") or (subVerb == "a") then
444 AutoDecline_AddList(AutoDeclinePartyGuildAllow, argArray, AD_PARTYGUILD_ADD )
445 elseif (subVerb == "remove") or (subVerb == "r") then
446 for argIndex,argValue in argArray do
447 if (type(argValue) == "string") and (string.len(argValue) > 0) then
448 AutoDecline_Debug("argValue = >" .. argValue .. "<")
449 AutoDecline_Debug("string.len(argValue) = " .. string.len(argValue))
450 AutoDeclinePartyGuildAllow[realmID][string.lower(argValue)] = false
451 AutoDecline_Display(format(AD_PARTYGUILD_REMOVE, argValue))
452 end
453 end
454 elseif (subVerb == "list") or (subVerb == "l") then
455 AutoDecline_Display(AD_PARTYGUILD_LIST)
456 for guildName in AutoDeclinePartyGuildAllow[realmID] do
457 if AutoDeclinePartyGuildAllow[realmID][guildName] then
458 AutoDecline_Display(" " .. guildName)
459 end
460 end
461 elseif (subVerb == "clear") or (subVerb == "c") then
462 AutoDeclinePartyAllow[realmID] = {}
463 AutoDecline_Display(AD_PARTYGUILD_CLEAR)
464 end
465 ]]--
466  
467 elseif (actionVerb == "partyaction") or (actionVerb == "pa") then
468 AutoDecline_AddAction("PARTY", argString)
469 elseif (actionVerb == "duelaction") or (actionVerb == "da") then
470 AutoDecline_AddAction("DUEL", argString)
471 elseif (actionVerb == "guildaction") or (actionVerb == "ga") then
472 AutoDecline_AddAction("GUILD", argString)
473 elseif (actionVerb == "charteraction") or (actionVerb == "ca") then
474 AutoDecline_AddAction("CHARTER", argString)
475  
476 elseif (actionVerb == "listfriends") and debugMode then
477 AutoDecline_Debug("List of friends")
478 for personName in AutoDeclineFriends[realmID] do
479 AutoDecline_Debug(" " .. personName)
480 end
481  
482 -- *: Manually perform actions for testing
483 elseif (actionVerb == "doaction") and debugMode then
484 if (argArray[1] == "charter") then
485 AutoDecline_DoAction( AutoDeclineActions["CHARTER"], {player=argArray[2],guild=argArray[3]} )
486 elseif (argArray[1] == "party") then
487 AutoDecline_DoAction( AutoDeclineActions["PARTY"], {player=argArray[2],guild=""} )
488 elseif (argArray[1] == "guild") then
489 AutoDecline_DoAction( AutoDeclineActions["GUILD"], {player=argArray[2],guild=argArray[3]} )
490 elseif (argArray[1] == "duel") then
491 AutoDecline_DoAction( AutoDeclineActions["DUEL"], {player=argArray[2],guild=""} )
492 else
493 AutoDecline_Debug( "Unknown action: " .. FormatOutput(argArray[1]) )
494 end
495  
496 elseif (actionVerb == "listwindows") and debugMode then
497 AutoDecline_ListWindows()
498  
499 elseif (actionVerb == "hidewin") and debugMode then
500 AutoDecline_Debug(format("Hiding window %s", argString))
501 AutoDecline_HideWindow(argString)
502  
503 elseif (actionVerb == "charinfo") and debugMode then
504 SetWhoToUI(1)
505 SendWho( argArray[1] )
506 AutoDecline_Debug("AutoDecline_CheckGuild(" .. argArray[1] .. ") = " .. FormatOutput(AutoDecline_CheckGuild(argArray[1])))
507  
508 elseif (actionVerb == "showvars") and debugMode then
509 AutoDecline_ShowVars()
510  
511 else
512 AutoDecline_Display(AD_SYNTAX)
513 end
514 else
515 AutoDecline_Display(AD_NAME_NOT_FOUND)
516 AutoDecline_Unload()
517 end
518  
519 end
520  
521 end
522  
523 -- *:***************************************************************
524 function AutoDecline_Charter()
525 if AutoDeclineConfig[playerID].charterToggle then
526 local petitionType, title, bodyText, maxSignatures, originatorName, isOriginator = GetPetitionInfo();
527 if (petitionType == "charter") then
528 ClosePetition()
529 AutoDecline_Display(format(AD_PETITION_REQUEST, originatorName, title))
530 end
531 if AutoDeclineActions["CHARTER"] then
532 AutoDecline_DoAction( AutoDeclineActions["CHARTER"], {player=originatorName, guild=title} )
533 end
534 end
535 end
536  
537 -- *:***************************************************************
538 function AutoDecline_Duel(player)
539 if AutoDeclineConfig[playerID].duelToggle then
540 CancelDuel()
541 AutoDecline_Display(format(AD_DUEL_REQUEST, player))
542 AutoDecline_HideWindow("DUEL_REQUESTED")
543 if AutoDeclineActions["DUEL"] then
544 AutoDecline_DoAction( AutoDeclineActions["DUEL"], {player=player, guild=""} )
545 end
546 end
547 end
548  
549 -- *:***************************************************************
550 function AutoDecline_Guild(player,guild)
551 if AutoDeclineConfig[playerID].guildToggle then
552 DeclineGuild()
553 AutoDecline_Display(format(AD_GUILD_INVITE, player, guild))
554 AutoDecline_HideWindow("GUILD_INVITE")
555 if AutoDeclineActions["GUILD"] then
556 AutoDecline_DoAction( AutoDeclineActions["GUILD"], {player=player, guild=guild} )
557 end
558 end
559 end
560  
561 -- *:***************************************************************
562 function AutoDecline_Party(player)
563 playerCheck = string.lower(player)
564 lastInvite = playerCheck
565  
566 -- *: This doesn't work, GetGuildInfo doesn't take a player name, it takes a key value.
567 -- guildName, guildRankName, guildRankIndex = GetGuildInfo(player);
568  
569 AutoDecline_Debug( "AutoDeclinePartyAllow[realmID][playerCheck] = " .. FormatOutput(AutoDeclinePartyAllow[realmID][playerCheck]) )
570 AutoDecline_Debug( "AutoDeclineConfig[playerID].partyFriends = " .. FormatOutput(AutoDeclineConfig[playerID].partyFriends) )
571 AutoDecline_Debug( "AutoDeclineConfig[playerID].partyGuild = " .. FormatOutput(AutoDeclineConfig[playerID].partyGuild) )
572 AutoDecline_Debug( "AutoDeclineConfig[playerID].partyWhisper = " .. FormatOutput(AutoDeclineConfig[playerID].partyWhisper) )
573 AutoDecline_Debug( "AutoDeclineFriends[realmID][playerCheck] = " .. FormatOutput(AutoDeclineFriends[realmID][playerCheck]) )
574 AutoDecline_Debug( "playerCheck = " .. FormatOutput(playerCheck) )
575 AutoDecline_Debug( "whisperNames = " .. FormatOutput(whisperNames) )
576 AutoDecline_Debug( "AutoDeclineConfig[playerID].partyToggle = " .. FormatOutput(AutoDeclineConfig[playerID].partyToggle) )
577  
578 bypassCheck = AutoDeclinePartyAllow[realmID][playerCheck]
579  
580 if AutoDeclineConfig[playerID].partyFriends and (not bypassCheck) then
581 bypassCheck = bypassCheck or AutoDeclineFriends[realmID][playerCheck]
582 end
583  
584 if AutoDeclineConfig[playerID].partyWhisper and whisperNames[playerCheck] and (not bypassCheck) then
585 bypassCheck = true
586 end
587  
588 if AutoDeclineConfig[playerID].partyGuild and (not bypassCheck) then
589 bypassCheck = bypassCheck or AutoDecline_CheckGuild(playerCheck)
590 end
591 -- bypassCheck or AutoDeclinePartyGuildAllow[realmID][guildName]
592  
593 AutoDecline_Debug( "bypassCheck = " .. FormatOutput(bypassCheck) )
594  
595 if AutoDeclineConfig[playerID].partyToggle and (not bypassCheck) then
596 DeclineGroup();
597 AutoDecline_Display(format(AD_PARTY_INVITE, player))
598 AutoDecline_HideWindow("PARTY_INVITE")
599 if AutoDeclineActions["PARTY"] then
600 AutoDecline_DoAction( AutoDeclineActions["PARTY"], {player=player, guild=""} )
601 end
602 end
603 end
604  
605 -- *:***************************************************************
606 function AutoDecline_Display(displayText)
607 if DEFAULT_CHAT_FRAME and displayText then
608 DEFAULT_CHAT_FRAME:AddMessage(AD_TAG .. " " .. displayText)
609 end
610 end
611  
612 -- *:***************************************************************
613 function AutoDecline_ShowAlert(alertMessage)
614 if AutoDeclineConfig[playerID].showAlert then
615 AutoDecline_Display(alertMessage)
616 end
617 end
618  
619 -- *:***************************************************************
620 function AutoDecline_ListWindows()
621 AutoDecline_Display("Listing open windows:")
622 for windowIndex = 1,STATICPOPUP_NUMDIALOGS do
623 local currentFrame = getglobal("StaticPopup" .. windowIndex)
624 if currentFrame:IsVisible() then
625 isVisible = ""
626 else
627 isVisible = " (invisible)"
628 end
629 AutoDecline_Display(" " .. FormatOutput(currentFrame.which) .. isVisible )
630 end
631 end
632  
633 function test()
634 -- currentFrame = getglobal("FriendsFrame")
635 -- if currentFrame and currentFrame:IsVisible() then
636 -- currentFrame:Hide()
637 -- end
638 end
639  
640 -- *:***************************************************************
641 function AutoDecline_HideWindow(windowToHide)
642 local windowIndex, hidWindow
643 hidWindow = nil
644 for windowIndex = 1, STATICPOPUP_NUMDIALOGS do
645 local currentFrame = getglobal("StaticPopup" .. windowIndex)
646 if currentFrame:IsVisible() and (currentFrame.which == windowToHide) then
647 currentFrame:Hide()
648 hidWindow = true
649 end
650 end
651  
652 if (not hidWindow) then
653 local currentFrame = getglobal(windowToHide)
654 if currentFrame and currentFrame:IsVisible() then
655 currentFrame:Hide()
656 hidWindow = true
657 else
658 if (not currentFrame) then
659 AutoDecline_Debug(format("Frame %s not found.", windowToHide))
660 else
661 AutoDecline_Debug(format("Frame %s found, but it is hidden already.", windowToHide))
662 end
663 end
664 end
665  
666 if not hidWindow then
667 AutoDecline_Debug(format("Window %s not found.", windowToHide))
668 end
669 end
670  
671 -- *:***************************************************************
672 function AutoDecline_ShowToggle(toggleValue)
673 local toggleResult
674 if toggleValue then
675 toggleResult = AD_ON
676 else
677 toggleResult = AD_OFF
678 end
679 return toggleResult
680 end
681  
682 -- *:***************************************************************
683 function AutoDecline_SetStatus(statusString, origValue)
684 returnResult = origValue
685 statusString = string.lower(statusString)
686  
687 if statusString == "on" then
688 returnResult = true
689 elseif statusString == "off" then
690 returnResult = false
691 elseif statusString == "" then
692 returnResult = not returnResult
693 end
694 return returnResult
695 end
696  
697 -- *:***************************************************************
698 function AutoDecline_GetValue(valueKey)
699 returnValue = ""
700 if not playerID then
701 AutoDecline_Display("GetValue ERROR: Invalid playerID = " .. FormatOutput(playerID))
702 elseif not valueKey then
703 AutoDecline_Display("GetValue ERROR: Invalid valueKey = " .. FormatOutput(valueKey))
704 else
705 if valueKey == "allChars" then
706 returnValue = AutoDeclineConfig[valueKey]
707 else
708 returnValue = AutoDeclineConfig[playerID][valueKey]
709 end
710 end
711 -- end
712 return returnValue
713 end
714  
715 -- *:***************************************************************
716 function AutoDecline_SetValue(valueKey, newValue)
717 if valueKey == "allChars" then
718 if playerID ~= "allChars" then
719 AutoDeclineConfig["allChars"] = AutoDeclineConfig[playerID]
720 end
721 else
722 if not playerID then
723 AutoDecline_Display("SetValue ERROR: Invalid playerID = " .. FormatOutput(playerID))
724 elseif not valueKey then
725 AutoDecline_Display("SetValue ERROR: Invalid valueKey = " .. FormatOutput(valueKey))
726 else
727 AutoDeclineConfig[playerID][valueKey] = newValue
728 end
729 end
730 end
731  
732 -- *:***************************************************************
733 function AutoDecline_SetAllChars()
734 if playerID ~= "allChars" then
735 AutoDecline_Debug( "Setting AllChars")
736 AutoDeclineConfig["allChars"] = AutoDeclineConfig[playerID]
737 playerID = "allChars"
738 end
739 end
740  
741 -- *:***************************************************************
742 function AutoDecline_SetLocalChars()
743 if playerID ~= localPlayerID then
744 AutoDecline_Debug( "Restoring local character settings")
745 playerID = localPlayerID
746 AutoDeclineConfig[playerID] = AutoDeclineConfig["allChars"]
747 AutoDeclineConfig["allChars"] = nil
748 end
749 end
750  
751 -- *:***************************************************************
752 function AutoDecline_LoadFriendsList()
753 if realmID then
754 AutoDeclineFriends[realmID] = {}
755 numberOfFriends = GetNumFriends()
756 for friendIndex = 1, numberOfFriends do
757 friendName, friendLevel, friendClass, friendArea, friendConnected = GetFriendInfo(friendIndex)
758 if friendName then
759 friendName = string.lower(friendName)
760 AutoDeclineFriends[realmID][friendName] = true
761 end
762 end
763 end
764 end
765  
766 -- *:***************************************************************
767 function AutoDecline_SetLastWhisper(playerName)
768 local newName = string.lower(playerName)
769 if not whisperNames then
770 whisperNames = {}
771 end
772 inList = table.foreach(whisperNames, function (index,value)
773 if (newName == value) then
774 return 1
775 end
776 end)
777  
778 if (not inList) then
779 table.insert(whisperNames, newName)
780 AutoDecline_Debug(format("Adding %s to whisperNames.", newName))
781 if table.getn(whisperNames) > whisperLimit then
782 AutoDecline_Debug(format("Removing %s to whisperNames.", whisperNames[1]))
783 table.remove(whisperNames, 1)
784 end
785 end
786 end
787  
788 -- *:***************************************************************
789 function AutoDecline_CheckGuild(playerName)
790 returnValue = nil
791  
792 for guildIndex = 1,GetNumGuildMembers() do
793 memberName, _, _, _, _, _, _, _, _, _ = GetGuildRosterInfo(guildIndex);
794 if playerName == string.lower(memberName) then
795 returnValue = true
796 break
797 end
798 end
799  
800  
801 --[[
802  
803 -- This doesn't work, to be implemented in the future when WoW supports a good way
804 -- to get the guild name given a players name.
805 adCheckingGuild = true
806  
807 -- SetWhoToUI(1)
808 -- SendWho( playerName )
809  
810 AutoDecline_Debug( "Waiting for FriendsFrame to be visible." )
811 friendsFrame = getglobal( "FriendsFrame" )
812  
813 -- while friendsFrame and (not friendsFrame:IsVisible()) and (not adLoopStop) do
814 -- end
815  
816 if adLoopStop then
817 AutoDecline_Debug( "Waiting for FriendsFrame to be visible." )
818 else
819 if friendsFrame then
820 AutoDecline_Debug( "FriendsFrame is visible!" )
821 AutoDecline_HideWindow( "FriendsFrame" )
822 else
823 AutoDecline_Debug( "FriendsFrame not found." )
824 end
825 end
826  
827 whoCount = GetNumWhoResults()
828 AutoDecline_Debug( "Got " .. whoCount .. " who results back." )
829 for whoIndex = 1,whoCount do
830 whoName, guildName, playerLevel, playerRace, playerClass, playerZone, unknown = GetWhoInfo( whoIndex );
831  
832 AutoDecline_Debug( "whoName = " .. FormatOutput(whoName) )
833 AutoDecline_Debug( "guildName = " .. FormatOutput(guildName) )
834 AutoDecline_Debug( "playerLevel = " .. FormatOutput(playerLevel) )
835 AutoDecline_Debug( "playerRace = " .. FormatOutput(playerRace) )
836 AutoDecline_Debug( "playerClass = " .. FormatOutput(playerClass) )
837 AutoDecline_Debug( "playerZone = " .. FormatOutput(playerZone) )
838 AutoDecline_Debug( "unknown = " .. FormatOutput(unknown) )
839  
840 if string.lower( whoName ) == playerName then
841 whoIndex = whoCount
842 else
843 guildName = nil
844 end
845 end
846  
847 if guildName then
848 returnValue = AutoDeclinePartyGuildAllow[realmID][string.lower(guildName)]
849 else
850 returnValue = ""
851 end
852  
853 AutoDecline_HideWindow( "FriendsFrame" )
854 cancelFriendList = true
855 ]]--
856  
857 return returnValue
858 end
859  
860 -- *:***************************************************************
861 function AutoDecline_ShowStatus()
862 AutoDecline_Display("Status")
863 AutoDecline_Display(" " .. iif(AutoDeclineConfig[playerID].guildToggle, AD_GUILD_ON, AD_GUILD_OFF))
864 AutoDecline_Display(" " .. iif(AutoDeclineConfig[playerID].partyToggle, AD_PARTY_ON, AD_PARTY_OFF))
865 AutoDecline_Display(" " .. iif(AutoDeclineConfig[playerID].duelToggle, AD_DUEL_ON, AD_DUEL_OFF))
866 AutoDecline_Display(" " .. iif(AutoDeclineConfig[playerID].charterToggle, AD_CHARTER_ON, AD_CHARTER_OFF))
867 AutoDecline_Display(" " .. iif(AutoDeclineConfig[playerID].partyFriends, AD_PARTYFRIENDS_ON, AD_PARTYFRIENDS_OFF))
868 AutoDecline_Display(" " .. iif(AutoDeclineConfig[playerID].partyGuild, AD_PARTYGUILD_ON, AD_PARTYGUILD_OFF))
869 AutoDecline_Display(" " .. iif(AutoDeclineConfig[playerID].partyWhisper, AD_PARTYWHISPER_ON, AD_PARTYWHISPER_OFF))
870 AutoDecline_Display(" " .. iif(AutoDeclineConfig[playerID].showAlert, AD_ALERT_ON, AD_ALERT_OFF))
871  
872 if AUTODECLINE_DEBUG then
873 AutoDecline_Display(" ** Persistant debug mode is ON")
874 end
875 if debugMode then
876 AutoDecline_Display(" ** Debug mode is ON")
877 end
878  
879 AutoDecline_Display("")
880 AutoDecline_DisplayActions("PARTY")
881 AutoDecline_DisplayActions("DUEL")
882 AutoDecline_DisplayActions("CHARTER")
883 AutoDecline_DisplayActions("GUILD")
884 end
885  
886 -- *:***************************************************************
887 function AutoDecline_DisplayActions(declineType)
888 if AutoDeclineActions[declineType] then
889 AutoDecline_Display(format(AD_DISPLAYACTION_HEADER, declineType))
890 for actionIndex,eachAction in AutoDeclineActions[declineType] do
891 AutoDecline_Display(format("%4s",actionIndex) .. ": " .. eachAction)
892 end
893 else
894 AutoDecline_Display(format(AD_DISPLAYACTION_NONE, declineType))
895 end
896 end
897  
898 -- *:***************************************************************
899 function AutoDecline_DoAction( actionList, argList )
900 if debugMode then
901 if actionList then
902 AutoDecline_Debug("actionList: " .. table.concat(actionList,"::"))
903 else
904 AutoDecline_Debug("actionList: (nil)")
905 end
906 end
907  
908 if actionList then
909 for actionIndex,eachAction in actionList do
910 eachAction = string.gsub(eachAction, "%$(%w+)", function (actionType)
911 return argList[actionType]
912 end)
913 AutoDecline_Debug( "Performing action " .. eachAction )
914 chatFrame = DEFAULT_CHAT_FRAME
915 chatFrame.editBox:SetText( eachAction )
916 ChatEdit_SendText(chatFrame.editBox)
917 ChatEdit_OnEscapePressed(chatFrame.editBox)
918 end
919 end
920 end
921  
922 -- *:***************************************************************
923 function AutoDecline_AddAction(declineType, actionText)
924 local removedAction = nil
925  
926 if actionText then
927 actionText = TrimSpace(actionText)
928 subAction, actionValue = GetCommand(string.lower(actionText))
929  
930 if string.sub(actionText,1,1) == "/" then
931 if type(AutoDeclineActions[declineType]) == "table" then
932 table.insert( AutoDeclineActions[declineType], actionText )
933 else
934 AutoDeclineActions[declineType] = { actionText }
935 end
936 AutoDecline_Display(format(AD_ADDACTION_ADD, declineType))
937 AutoDecline_Display(" " .. actionText)
938  
939 elseif subAction == "clear" then
940 AutoDecline_Display(format(AD_ADDACTION_CLEAR, declineType))
941 AutoDeclineActions[declineType] = nil
942  
943 elseif subAction == "list" then
944 AutoDecline_DisplayActions(declineType)
945  
946 elseif subAction == "remove" then
947 if AutoDeclineActions[declineType] then
948 actionValue = tonumber(actionValue)
949 if actionValue and actionValue <= table.getn(AutoDeclineActions[declineType]) then
950 AutoDecline_Display(format(AD_ADDACTION_REMOVE, declineType))
951 AutoDecline_Display(" " .. AutoDeclineActions[declineType][actionValue])
952 table.remove(AutoDeclineActions[declineType], actionValue)
953 end
954 end
955  
956 else
957 -- if actionText == "" then
958 -- actionText = AD_NONE_SPECIFIED
959 -- end
960 AutoDecline_Display(format(AD_ADDACTION_ERROR, actionText))
961  
962 end
963 end
964 end
965  
966 -- *:***************************************************************
967 function AutoDecline_Debug(displayText)
968 if debugMode then
969 if DEFAULT_CHAT_FRAME and displayText then
970 DEFAULT_CHAT_FRAME:AddMessage(AD_DEBUG_TAG .. " " .. displayText)
971 end
972 end
973 end
974  
975  
976 -- *:***************************************************************
977 function AutoDecline_AddList( listArray, argArray, messageText )
978 for argIndex,argValue in argArray do
979 if (type(argValue) == "string") and (string.len(argValue) > 0) then
980 listArray[realmID][string.lower(argValue)] = true
981 AutoDecline_Display(format(messageText, argValue))
982 end
983 end
984 end
985  
986  
987 -- *:***************************************************************
988 -- *:***************************************************************
989 -- *:***************************************************************
990 -- *: Generic functions
991 -- *:***************************************************************
992 -- *:***************************************************************
993 -- *:***************************************************************
994  
995 -- *:***************************************************************
996 -- *: Trims leading and trailing spaces from a string, and collapses
997 -- *: groups of spaces into a single space.
998 function TrimSpace(paramString)
999 return string.gsub(string.gsub(paramString, "^%s*(.-)%s*$", "%1"), "%s+"," ")
1000 end
1001  
1002 -- *:***************************************************************
1003 -- *: Returns the action verb and arguments from a command line
1004 -- *:
1005 -- *: Parameters:
1006 -- *: commandLine - the command line
1007 -- *: argSeperator - seperator for each argument. if nil, all arguments
1008 -- *: are passed back as a single string. Also, if a seperator
1009 -- *: is declared, all arguments are lower cased.
1010 -- *:
1011 -- *: Returns:
1012 -- *: actionVerb - The action verb
1013 -- *: parmsResult - The parameters, as a string or array depending
1014 -- *: if sep was declared.
1015 function GetCommand(commandLine, argSeperator)
1016 actionVerb = nil
1017 parmsResult = nil
1018 argString = nil
1019  
1020 commandLine = TrimSpace(commandLine)
1021 regexString = "^%s*(%w+)%s*(.-)$"
1022 _, _, actionVerb, argString = string.find(commandLine, regexString)
1023  
1024 if argString and argSeperator then
1025 parmsResult = {}
1026 for eachArgument in string.gfind(argString .. argSeperator,"(.-)" .. argSeperator) do
1027 -- table.insert( parmsResult, TrimSpace(string.lower(eachArgument)) )
1028 eachArgument = TrimSpace(string.lower(eachArgument))
1029 table.insert(parmsResult, eachArgument)
1030 end
1031 else
1032 parmsResult = argString
1033 end
1034  
1035 if actionVerb then
1036 actionVerb = string.lower(actionVerb)
1037 end
1038 return actionVerb, parmsResult, argString
1039 end
1040  
1041 -- *:***************************************************************
1042 function iif( ifCondition, thenResult, elseResult )
1043 if ifCondition then
1044 return thenResult
1045 else
1046 return elseResult
1047 end
1048 end
1049  
1050 -- *:***************************************************************
1051 function FormatOutput( outputToFormat )
1052 local returnResult = ""
1053  
1054 if type(outputToFormat) == "nil" then
1055 returnResult = "(nil)"
1056 elseif type(outputToFormat) == "table" then
1057 returnResult = table.concat(outputToFormat, "::")
1058 elseif type(outputToFormat) == "boolean" then
1059 if outputToFormat then
1060 returnResult = "Yes"
1061 else
1062 returnResult = "No"
1063 end
1064 elseif (type(outputToFormat) == "number") then
1065 returnResult = string.format( "%s", outputToFormat )
1066 elseif (type(outputToFormat) == "string") then
1067 returnResult = outputToFormat
1068 else
1069 returnResult = outputToFormat
1070 end
1071  
1072 return returnResult
1073 end
1074  
1075