/Tukui/modules/misc/invite.lua

http://github.com/Asphyxia/Tukui · Lua · 108 lines · 76 code · 18 blank · 14 comment · 43 complexity · 8d1a2bba2c1d13d9c71fe56eeb2db201 MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. ------------------------------------------------------------------------
  3. -- Auto accept invite
  4. ------------------------------------------------------------------------
  5. if C["invite"].autoaccept then
  6. local holder = CreateFrame("Frame")
  7. holder:RegisterEvent("PARTY_INVITE_REQUEST")
  8. holder:RegisterEvent("PARTY_MEMBERS_CHANGED")
  9. local hidestatic -- used to hide static popup when auto-accepting
  10. holder:SetScript("OnEvent", function(self, event, leader)
  11. local ingroup = false
  12. if event == "PARTY_INVITE_REQUEST" then
  13. if MiniMapLFGFrame:IsShown() then return end -- Prevent losing que inside LFD if someone invites you to group
  14. if GetNumPartyMembers() > 0 or GetNumRaidMembers() > 0 then return end
  15. hidestatic = true
  16. -- Update Guild and Friendlist
  17. if GetNumFriends() > 0 then ShowFriends() end
  18. if IsInGuild() then GuildRoster() end
  19. for friendindex = 1, GetNumFriends() do
  20. local friendname = GetFriendInfo(friendindex)
  21. if friendname == leader then
  22. AcceptGroup()
  23. ingroup = true
  24. break
  25. end
  26. end
  27. -------------------------------------------------------------------
  28. -- friend not found in friend index, so we look now into battle.net
  29. -------------------------------------------------------------------
  30. local playerFaction
  31. -- find which faction we play
  32. if select(1, UnitFactionGroup("player")) == "Horde" then playerFaction = 0 else playerFaction = 1 end
  33. if not ingroup then
  34. for i = 1, select(2, BNGetNumFriends()) do
  35. local presenceID, givenName, surname, toonName, toonID, client, isOnline = BNGetFriendInfo(i)
  36. local _, _, _, realmName, faction, race, class, _, zoneName, level = BNGetToonInfo(presenceID)
  37. if client == "WoW" and realmName == T.myrealm and faction == playerFaction then
  38. if toonName == leader then
  39. AcceptGroup()
  40. ingroup = true
  41. break
  42. end
  43. end
  44. end
  45. end
  46. -----------------------------------------------------------------------------
  47. -- friend not found in battle.net friend index, so we look now into our guild
  48. -----------------------------------------------------------------------------
  49. if not ingroup then
  50. for guildindex = 1, GetNumGuildMembers(true) do
  51. local guildmembername = GetGuildRosterInfo(guildindex)
  52. if guildmembername == leader then
  53. AcceptGroup()
  54. break
  55. end
  56. end
  57. end
  58. elseif event == "PARTY_MEMBERS_CHANGED" and hidestatic == true then
  59. StaticPopup_Hide("PARTY_INVITE")
  60. hidestatic = false
  61. end
  62. end)
  63. end
  64. ------------------------------------------------------------------------
  65. -- Auto invite by whisper
  66. ------------------------------------------------------------------------
  67. local ainvenabled = false
  68. local ainvkeyword = "invite"
  69. local autoinvite = CreateFrame("frame")
  70. autoinvite:RegisterEvent("CHAT_MSG_WHISPER")
  71. autoinvite:SetScript("OnEvent", function(self,event,arg1,arg2)
  72. if ((not UnitExists("party1") or IsPartyLeader("player") or IsRaidOfficer("player") or IsRaidLeader("player")) and arg1:lower():match(ainvkeyword)) and ainvenabled == true then
  73. InviteUnit(arg2)
  74. end
  75. end)
  76. function SlashCmdList.AUTOINVITE(msg, editbox)
  77. if msg == "off" then
  78. ainvenabled = false
  79. print(L.core_autoinv_disable)
  80. elseif msg == "" then
  81. ainvenabled = true
  82. print(L.core_autoinv_enable)
  83. ainvkeyword = "invite"
  84. else
  85. ainvenabled = true
  86. print(L.core_autoinv_enable_c .. msg)
  87. ainvkeyword = msg
  88. end
  89. end
  90. SLASH_AUTOINVITE1 = "/ainv"