-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCore.lua
148 lines (127 loc) · 3.32 KB
/
Core.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
PortalWhere = CreateFrame("Frame")
PortalWhere.matchWords = {
["Undercity"] = {
"Undercity",
"UC",
"Undershitty",
},
["Orgrimmar"] = {
"Orgrimmar",
"Orgrimar",
"Org",
"Orgri",
"Ogri",
"Ogr",
"Og",
},
["Thunderbluff"] = {
"Thunderbluff",
"TB",
}
}
function PortalWhere:Print(...)
print("[PortalWh*re]", ...)
end
function PortalWhere:Boot()
self:SetScript("OnEvent", function(self, event, ...)
self[event](self, ...)
end)
self:RegisterEvent("ADDON_LOADED")
end
function PortalWhere:ADDON_LOADED(name)
if name == "PortalWhere" then
self:OnBoot()
end
end
function PortalWhere:RegisterSlashCommand()
SLASH_PORTALWHERE1 = "/pw"
SLASH_PORTALWHERE2 = "/portalwhere"
SlashCmdList["PORTALWHERE"] = function(msg)
local _, _, command, args = string.find(msg, "%s?(%w+)%s?(.*)")
if command then
self:OnSlashCommand(command, args)
end
end
end
function PortalWhere:MakeLowercaseMatchWords()
for destination, wordList in pairs(self.matchWords) do
for index, word in ipairs(wordList) do
self.matchWords[destination][index] = string.lower(word)
end
end
end
function PortalWhere:OnBoot()
self:MakeLowercaseMatchWords()
self:RegisterSlashCommand()
self:Print("Loaded.")
end
function PortalWhere:OnSlashCommand(command, args)
command = string.lower(command)
if command == "on" then
self:On()
elseif command == "off" then
self:Off()
else
self:Print("Unknown command.")
end
end
function PortalWhere:On()
self:RegisterEvent("CHAT_MSG_SAY")
self:RegisterEvent("CHAT_MSG_YELL")
self:RegisterEvent("CHAT_MSG_WHISPER")
self:Print("Looking for punters...")
end
function PortalWhere:Off()
self:UnregisterEvent("CHAT_MSG_SAY")
self:UnregisterEvent("CHAT_MSG_YELL")
self:UnregisterEvent("CHAT_MSG_WHISPER")
self:Print("All done. Time for breakfast.")
end
function PortalWhere:CHAT_MSG_SAY(...)
self:OnChat(...)
end
function PortalWhere:CHAT_MSG_YELL(...)
self:OnChat(...)
end
function PortalWhere:CHAT_MSG_WHISPER(...)
self:OnChat(...)
end
function PortalWhere:MatchWordToDestination(word)
word = string.lower(word)
for destination, wordList in pairs(self.matchWords) do
if self:ArrayHas(word, wordList) then
return true, destination
end
end
return false
end
function PortalWhere:ArrayHas(item, array)
for index, value in pairs(array) do
if value == item then
return true
end
end
return false
end
function PortalWhere:WantsPortal(playerName, guid, message)
if playerName == UnitName("player") then
return false
end
local _, playerClass = GetPlayerInfoByGUID(guid)
if playerClass == "MAGE" then
return false
end
for word in string.gmatch(message, "%a+") do
local match, destination = self:MatchWordToDestination(word)
if match then
return match, destination
end
end
return false
end
function PortalWhere:OnChat(text, playerName, _, _, shortPlayerName, _, _, _, _, _, _, guid)
if self:WantsPortal(playerName, guid, text) then
InviteUnit(playerName)
end
end
PortalWhere:Boot()