Skip to content

Commit

Permalink
resolve merge
Browse files Browse the repository at this point in the history
  • Loading branch information
TannerShmoog committed Nov 11, 2022
2 parents 566ea1e + e4508e0 commit a3c2bcf
Show file tree
Hide file tree
Showing 31 changed files with 8,711 additions and 401 deletions.
110 changes: 82 additions & 28 deletions AutoResponse.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
local addonName, addon = ...
local GroupieAutoResponse = addon:NewModule("GroupieAutoResponse", "AceEvent-3.0")

local locale = GetLocale()
if not addon.tableContains(addon.validLocales, locale) then
return
Expand All @@ -7,9 +9,10 @@ local L = LibStub('AceLocale-3.0'):GetLocale('Groupie')
local time = time

addon.recentPlayers = {}
local askForPlayerInfo = format("{rt3} %s : What Role are you?", addonName)
local askForInstance = format("{rt3} %s : What are you inviting me to?"
, addonName)
local askForPlayerInfo = addon.askForPlayerInfo
local askForInstance = addon.askForInstance
local autoRejectInviteString = addon.autoRejectInviteString
local autoRejectRequestString = addon.autoRejectRequestString

--Clear table entries more than 1 minute old
local function expireRecentPlayers()
Expand All @@ -25,45 +28,74 @@ end
--Respond to invitations the player recieves to another's group
local function RespondToInvite(_, author)
expireRecentPlayers()
local listedLFG = C_LFGList.HasActiveEntryInfo()

--automatically reject party invites
if addon.db.char.autoRejectInvites and listedLFG then
for i = 1, STATICPOPUP_NUMDIALOGS do
if _G["StaticPopup" .. i].which == "PARTY_INVITE" then
local player = _G["StaticPopup" .. i].text.text_arg1:gsub(" invites you.+", "")
--dont reject recently spoken to players or friends
if addon.recentPlayers[player] == nil and addon.friendList[player] == nil then
_G["StaticPopup" .. i .. "Button2"]:Click()
end
end
end
end

if not addon.db.char.autoRespondInvites then
return
end

--Not someone recently spoken to
if addon.recentPlayers[author] == nil and C_LFGList.HasActiveEntryInfo() then
SendChatMessage(askForInstance, "WHISPER", "COMMON", author)
if addon.recentPlayers[author] == nil and listedLFG then
local msg = askForInstance
if addon.db.char.autoRejectInvites then
msg = msg .. " " .. addon.autoRejectInviteString
end
SendChatMessage(msg, "WHISPER", "COMMON", author)
addon.recentPlayers[author] = time()
end
end

--Respond to requests to join player's group
local function RespondToRequest(_, msg, ...)
expireRecentPlayers()
local listedLFG = C_LFGList.HasActiveEntryInfo()

if strmatch(msg, "has requested to join your group") then
if not addon.db.char.autoRespondRequests then
return
end

local author = msg:gsub("%|Hplayer:", ""):gsub("%|h.+", "")

--Not someone recently spoken to
if addon.recentPlayers[author] == nil and C_LFGList.HasActiveEntryInfo() then
SendChatMessage(askForPlayerInfo, "WHISPER", "COMMON", author)
addon.recentPlayers[author] = time()
end
elseif strmatch(msg, "could not accept because you are already in a group") then
if not addon.db.char.autoRespondInvites then
if not addon.db.char.autoRespondRequests then
return
end

local author = msg:gsub("%|Hplayer:", ""):gsub("%|h.+", "")

--Not someone recently spoken to
if addon.recentPlayers[author] == nil and C_LFGList.HasActiveEntryInfo() then
SendChatMessage(askForInstance, "WHISPER", "COMMON", author)
if addon.recentPlayers[author] == nil and listedLFG then
local msg = askForPlayerInfo
if addon.db.char.autoRejectRequests then
msg = msg .. " " .. addon.autoRejectRequestString
end
SendChatMessage(msg, "WHISPER", "COMMON", author)
addon.recentPlayers[author] = time()
end
elseif strmatch(msg, "could not accept because you are already in a group") then
--Decided not to auto respond in this situation. If you are already
--in a group you likely dont care what they are inviting you to anymore
return
--if not addon.db.char.autoRespondInvites then
-- return
--end
--
--local author = msg:gsub("%|Hplayer:", ""):gsub("%|h.+", "")
--
----Not someone recently spoken to
--if addon.recentPlayers[author] == nil and listedLFG then
-- SendChatMessage(askForInstance, "WHISPER", "COMMON", author)
-- addon.recentPlayers[author] = time()
--end
end
end

Expand All @@ -77,17 +109,39 @@ local function OnWhisper(isReceiver, _, msg, longAuthor, ...)
end
end

local function RejectInviteRequest()
expireRecentPlayers()
local listedLFG = C_LFGList.HasActiveEntryInfo()

--automatically reject party invite requests
if addon.db.char.autoRejectRequests and listedLFG then
for i = 1, STATICPOPUP_NUMDIALOGS do
if _G["StaticPopup" .. i].which == "GROUP_INVITE_CONFIRMATION" then
local player = _G["StaticPopup" .. i].text.text_arg1:gsub(" has requested.+", "")
if addon.recentPlayers[player] == nil and addon.friendList[player] == nil then
_G["StaticPopup" .. i .. "Button2"]:Click()
end
end
end
end
end

-------------------
--EVENT REGISTERS--
-------------------
function GroupieAutoResponse:OnEnable()
self:RegisterEvent("PARTY_INVITE_REQUEST", RespondToInvite)
--GROUP_INVITE_CONFIRMATION is the event fired for invite requests
--but doesnt return any context, so we need to use the system message
self:RegisterEvent("CHAT_MSG_SYSTEM", RespondToRequest)
self:RegisterEvent("CHAT_MSG_WHISPER", function(...)
OnWhisper(true, ...)
end)
--This requires a seperate event register, as we use system message for
--responding to invite requests, but this fires before the popup sometimes
self:RegisterEvent("GROUP_INVITE_CONFIRMATION", RejectInviteRequest)

addon:RegisterEvent("PARTY_INVITE_REQUEST", RespondToInvite)
--GROUP_INVITE_CONFIRMATION is the event fired for invite requests
--but doesnt return any context, so we need to use the system message
addon:RegisterEvent("CHAT_MSG_SYSTEM", RespondToRequest)
addon:RegisterEvent("CHAT_MSG_WHISPER", function(...)
OnWhisper(true, ...)
end)
addon:RegisterEvent("CHAT_MSG_WHISPER_INFORM", function(...)
OnWhisper(false, ...)
end)
--self:RegisterEvent("CHAT_MSG_WHISPER_INFORM", function(...)
-- OnWhisper(false, ...)
--end)
end
Loading

0 comments on commit a3c2bcf

Please sign in to comment.