-
Notifications
You must be signed in to change notification settings - Fork 1
/
AutoInvite.lua
170 lines (139 loc) · 5.02 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
local addonName, addonTable = ...
AutoInvite = addonTable
AutoInvite.autoInviteFrame = CreateFrame("Frame", "AutoInvite", UIParent)
AutoInvite.autoInviteFrame:RegisterEvent("PLAYER_LOGIN")
AutoInvite.autoInviteFrame:RegisterEvent("CHAT_MSG_WHISPER")
AutoInvite.autoInviteFrame:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_LOGIN" then
AutoInvite:Initialize()
end
if event == "CHAT_MSG_WHISPER" then
AutoInvite:ProcessWhisper(...)
end
end)
function AutoInvite:Initialize()
if AutoInviteSettings == nil then
AutoInvite:LoadDefaults()
else
AutoInvite:ApplySavedVariables()
end
end
function AutoInvite:ApplySavedVariables()
AutoInvite:SetEnableDisable(AutoInviteSettings.AutoInviteEnabled)
AutoInvite:SetInviteKeyword(AutoInviteSettings.AutoInviteKeyword, 0)
AutoInvite:SetInviteChannel(AutoInviteSettings.AutoInviteChannel, 0)
end
function AutoInvite:ProcessWhisper(text, playerName)
if not AutoInviteSettings.AutoInviteEnabled then
return
end
if text:gsub("^%s*(.-)%s*$", "%1") == AutoInviteSettings.AutoInviteKeyword then
InviteUnit(playerName)
end
end
SLASH_AUTOINVITE1 = "/autoinvite"
SLASH_AUTOINVITE2 = "/autoinvite help"
SLASH_AUTOINVITE3 = "/autoinvite enable"
SLASH_AUTOINVITE4 = "/autoinvite disable"
SLASH_AUTOINVITE5 = "/autoinvite toggle"
SLASH_AUTOINVITE6 = "/autoinvite b"
SLASH_AUTOINVITE7 = "/autoinvite broadcast"
SLASH_AUTOINVITE8 = "/autoinvite k"
SLASH_AUTOINVITE9 = "/autoinvite keyword"
SLASH_AUTOINVITE10 = "/autoinvite c"
SLASH_AUTOINVITE11 = "/autoinvite channel"
SlashCmdList["AUTOINVITE"] = function(msg)
if AutoInvite:StringIsNullOrEmpty(msg) then
AutoInvite:PrintHelpInformation()
end
local slashCommandMsg = AutoInvite:SplitString(msg, " ")
local subCommand = slashCommandMsg[1]
local subCommandMsg = nil
if table.getn(slashCommandMsg) > 1 then
subCommandMsg = slashCommandMsg[2]
end
if subCommand == "help" then
AutoInvite:PrintHelpInformation()
end
if subCommand == "toggle" then
if AutoInviteSettings.AutoInviteEnabled then
subCommand = "disable"
else
subCommand = "enable"
end
end
if subCommand == "enable" then
AutoInvite:SetEnableDisable(true)
print("AutoInvite enabled.")
end
if subCommand == "disable" then
AutoInvite:SetEnableDisable(false)
print("AutoInvite disabled.")
end
if subCommand == "broadcast" or subCommand == "b" then
AutoInvite:ProcessBroadcast(subCommandMsg, AutoInviteSettings.AutoInviteChannel)
end
if subCommand == "keyword" or subCommand == "k" then
AutoInvite:ProcessKeyword(subCommandMsg)
end
if subCommand == "channel" or subCommand == "c" then
AutoInvite:ProcessChannel(subCommandMsg)
end
end
function AutoInvite:PrintHelpInformation()
print("AutoInvite Help Information")
print("/autoinvite, /autoinvite help -- Displays help information for AutoInvite addon.")
print("/autoinvite enable -- Turns on the AutoInvite functionality.")
print("/autoinvite disable -- Turns off the AutoInvite functionality.")
print("/autoinvite toggle -- Toggles AutoInvite functionality.")
print("/autoinvite broadcast [keyword], /autoinvite b [keyword] -- Broadcasts the invite keyword to the guild channel and enables addon if it is disabled.")
print("/autoinvite keyword [keyword], /autoinvite k [keyword] -- Changes the invite keyword.")
print("/autoinvite channel [channel], /autoinvite c [channel] -- Changes the invite channel. Possible examples: 'SAY', 'YELL', 'PARTY', 'GUILD', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'")
end
function AutoInvite:ProcessBroadcast(subCommandMsg, chatChannel)
AutoInvite:SetEnableDisable(true)
if not AutoInvite:StringIsNullOrEmpty(subCommandMsg) then
AutoInvite:SetInviteKeyword(subCommandMsg, 0)
end
if AutoInvite:StringIsNullOrEmpty(AutoInviteSettings.AutoInviteKeyword) then
print("AutoInvite keyword is not set.")
return
end
if AutoInvite:StringIsNullOrEmpty(AutoInviteSettings.AutoInviteChannel) then
print("AutoInvite channel is not set.")
return
end
SendChatMessage("Whisper me '" .. AutoInviteSettings.AutoInviteKeyword .. "' for invite.", chatChannel)
end
function AutoInvite:ProcessKeyword(keyword)
if not AutoInvite:StringIsNullOrEmpty(keyword) then
AutoInvite:SetInviteKeyword(keyword, 0)
end
if AutoInvite:StringIsNullOrEmpty(AutoInviteSettings.AutoInviteKeyword) then
print("AutoInvite keyword is not set.")
else
print("AutoInvite keyword is set to '" .. AutoInviteSettings.AutoInviteKeyword .. "'.")
end
end
function AutoInvite:ProcessChannel(channel)
if not AutoInvite:StringIsNullOrEmpty(channel) then
AutoInvite:SetInviteChannel(channel, 0)
end
if AutoInvite:StringIsNullOrEmpty(AutoInviteSettings.AutoInviteChannel) then
print("AutoInvite channel is not set.")
else
print("AutoInvite channel is set to '" .. AutoInviteSettings.AutoInviteChannel .. "'.")
end
end
function AutoInvite:StringIsNullOrEmpty(s)
if s == nil or s == '' then
return true
end
end
function AutoInvite:SplitString(slashCommand, delimiter)
result = {}
for match in (slashCommand .. delimiter):gmatch("(.-)" .. delimiter) do
table.insert(result, match)
end
return result
end