-
Notifications
You must be signed in to change notification settings - Fork 2
/
AutoResponse.lua
147 lines (129 loc) · 5.31 KB
/
AutoResponse.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
local addonName, addon = ...
local GroupieAutoResponse = addon:NewModule("GroupieAutoResponse", "AceEvent-3.0")
local locale = GetLocale()
if not addon.tableContains(addon.validLocales, locale) then
return
end
local L = LibStub('AceLocale-3.0'):GetLocale('Groupie')
local time = time
addon.recentPlayers = {}
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()
local timediff = 60
local now = GetServerTime()
for player, timestamp in pairs(addon.recentPlayers) do
if now - timestamp > timediff then
addon.recentPlayers[player] = nil
end
end
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 == true 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 listedLFG then
local msg = askForInstance
if addon.db.char.autoRejectInvites == true then
msg = msg .. " " .. addon.autoRejectInviteString
end
SendChatMessage(msg, "WHISPER", "COMMON", author)
addon.recentPlayers[author] = GetServerTime()
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 listedLFG then
local msg = askForPlayerInfo
if addon.db.char.autoRejectRequests == true then
msg = msg .. " " .. addon.autoRejectRequestString
end
SendChatMessage(msg, "WHISPER", "COMMON", author)
addon.recentPlayers[author] = GetServerTime()
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] = GetServerTime()
--end
end
end
local function OnWhisper(isReceiver, _, msg, longAuthor, ...)
expireRecentPlayers()
local author = gsub(longAuthor, "%-.+", "")
--Store the player as recently spoken to with a timestamp
addon.recentPlayers[author] = GetServerTime()
if msg == askForPlayerInfo and isReceiver then
addon.SendPlayerInfo(author)
end
end
local function RejectInviteRequest()
expireRecentPlayers()
local listedLFG = C_LFGList.HasActiveEntryInfo()
--automatically reject party invite requests
if addon.db.char.autoRejectRequests == true 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)
--self:RegisterEvent("CHAT_MSG_WHISPER_INFORM", function(...)
-- OnWhisper(false, ...)
--end)
end