-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathSystemEventHandler.lua
176 lines (130 loc) · 6.08 KB
/
SystemEventHandler.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
171
172
173
174
175
176
--[[-----------------------------------------------------------------------
The MIT License (MIT)
Copyright (c) 2010-2020 Mark Rogaski
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]]-----------------------------------------------------------------------
local pat_online = ERR_FRIEND_ONLINE_SS:format('(.+)', '(.+)'):gsub('([%[%]])', '%%%1')
local pat_online_raw = "(.+) has come online."
local pat_offline = ERR_FRIEND_OFFLINE_S:format('(.+)')
local pat_join = ERR_GUILD_JOIN_S:format('(.+)')
local pat_leave = ERR_GUILD_LEAVE_S:format('(.+)')
local pat_quit = ERR_GUILD_QUIT_S:format('(.+)')
local pat_removed = ERR_GUILD_REMOVE_SS:format('(.+)', '(.+)')
local pat_kick = ERR_GUILD_REMOVE_SELF
GwSystemEventHandler = { config = nil, player = nil }
function GwSystemEventHandler:new(obj)
obj = obj or {}
setmetatable(obj, self)
self.__index = self
return obj
end
function GwSystemEventHandler:run()
end
GwOnlineSystemEventHandler = GwSystemEventHandler:new()
function GwOnlineSystemEventHandler:run()
self.config.comember_cache:hold(self.player)
gw.Debug(GW_LOG_DEBUG, 'comember_cache: updated %s', self.player)
end
GwOfflineSystemEventHandler = GwSystemEventHandler:new()
function GwOfflineSystemEventHandler:run()
self.config.comember_cache:hold(self.player)
gw.Debug(GW_LOG_DEBUG, 'comember_cache: updated %s', self.player)
end
GwJoinSystemEventHandler = GwSystemEventHandler:new()
function GwJoinSystemEventHandler:run()
if self.player == gw.player then
gw.Debug(GW_LOG_NOTICE, 'guild join detected.')
self.config.channel.guild:send(GW_MTYPE_BROADCAST, 'join')
end
end
GwLeaveSystemEventHandler = GwSystemEventHandler:new()
function GwLeaveSystemEventHandler:run()
if self.player == gw.player then
gw.Debug(GW_LOG_NOTICE, 'guild quit detected.')
self.config.channel.guild:send(GW_MTYPE_BROADCAST, 'leave')
self.config:reset()
end
end
GwQuitSystemEventHandler = GwSystemEventHandler:new()
function GwQuitSystemEventHandler:run()
gw.Debug(GW_LOG_NOTICE, 'guild quit detected.')
self.config.channel.guild:send(GW_MTYPE_BROADCAST, 'leave')
self.config:reset()
end
GwRemoveSystemEventHandler = GwSystemEventHandler:new()
function GwRemoveSystemEventHandler:run()
if self.player == gw.player then
gw.Debug(GW_LOG_NOTICE, 'guild kick detected.')
self.config.channel.guild:send(GW_MTYPE_BROADCAST, 'remove')
self.config:reset()
end
end
GwKickSystemEventHandler = GwSystemEventHandler:new()
function GwKickSystemEventHandler:run()
gw.Debug(GW_LOG_NOTICE, 'guild kick detected.')
self.config.channel.guild:send(GW_MTYPE_BROADCAST, 'leave')
self.config:reset()
end
GwPromoteSystemEventHandler = GwSystemEventHandler:new()
function GwSystemEventHandler:factory(config, message)
-- Remove coloring
message = string.gsub(message, "|c%w%w%w%w%w%w%w%w([^|]*)|r", "%1")
if message:match(pat_online) then
local _, player = message:match(pat_online)
player = gw.GlobalName(player)
gw.Debug(GW_LOG_NOTICE, 'player online: %s', player)
return GwOnlineSystemEventHandler:new({ config = config, player = player })
elseif message:match(pat_online_raw) then
local player = message:match(pat_online_raw)
player = gw.GlobalName(player)
gw.Debug(GW_LOG_NOTICE, 'player online: %s', player)
return GwOnlineSystemEventHandler:new({ config = config, player = player })
elseif message:match(pat_offline) then
local player = message:match(pat_offline)
player = gw.GlobalName(player)
gw.Debug(GW_LOG_NOTICE, 'player offline: %s', player)
return GwOfflineSystemEventHandler:new({ config = config, player = player })
elseif message:match(pat_join) then
local player = message:match(pat_join)
player = gw.GlobalName(player)
gw.Debug(GW_LOG_NOTICE, 'player join: %s', player)
return GwJoinSystemEventHandler:new({ config = config, player = player })
elseif message:match(pat_leave) then
local player = message:match(pat_leave)
player = gw.GlobalName(player)
gw.Debug(GW_LOG_NOTICE, 'player leave: %s', player)
return GwLeaveSystemEventHandler:new({ config = config, player = player })
elseif message:match(pat_quit) then
local player = UnitName('player')
player = gw.GlobalName(player)
gw.Debug(GW_LOG_NOTICE, 'player leave: %s', player)
return GwQuitSystemEventHandler:new({ config = config, player = player })
elseif message:match(pat_removed) then
local player = message:match(pat_removed)
player = gw.GlobalName(player)
gw.Debug(GW_LOG_NOTICE, 'player removed: %s', player)
return GwRemoveSystemEventHandler:new({ config = config, player = player })
elseif message:match(pat_kick) then
local player = UnitName('player')
player = gw.GlobalName(player)
gw.Debug(GW_LOG_NOTICE, 'player removed: %s', player)
return GwKickSystemEventHandler:new({ config = config, player = player })
else
-- Unhandled system message
return GwSystemEventHandler:new({ config = config })
end
end