vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | ------------------------------ |
2 | -- Are you local? -- |
||
3 | ------------------------------ |
||
4 | local L = AceLibrary("AceLocale-2.2"):new("oRA") |
||
5 | |||
6 | local CTRAversion = "1.541" |
||
7 | |||
8 | |||
9 | ---------------------------- |
||
10 | -- Localization -- |
||
11 | ---------------------------- |
||
12 | |||
13 | L:RegisterTranslations("enUS", function() return { |
||
14 | ["You are now AFK"] = true, |
||
15 | ["You are now DND"] = true, |
||
16 | ["You have to be Raid Leader or Assistant to do that."] = true, |
||
17 | ["Requested a status update."] = true, |
||
18 | ["useshorthands"] = true, |
||
19 | ["Use shorthands"] = true, |
||
20 | ["Toggle using of CTRA shorthands"] = true, |
||
21 | [" ...hic!"] = true, |
||
22 | ["status"] = true, |
||
23 | ["Request status"] = true, |
||
24 | ["Request a status update"] = true, |
||
25 | -- texture handling in the core yeah baby |
||
26 | ["Textures"] = true, |
||
27 | ["default"] = true, |
||
28 | ["otravi"] = true, |
||
29 | ["perl"] = true, |
||
30 | ["smooth"] = true, |
||
31 | ["striped"] = true, |
||
32 | ["bantobar"] = true, |
||
33 | ["smudge"] = true, |
||
34 | ["charcoal"] = true, |
||
35 | ["Set all statusbar textures."] = true, |
||
36 | } end) |
||
37 | |||
38 | L:RegisterTranslations("deDE", function() return { |
||
39 | ["You are now AFK"] = "Ihr seid jetzt AFK", |
||
40 | ["You are now DND"] = "Ihr seid jetzt DND", |
||
41 | ["You have to be Raid Leader or Assistant to do that."] = "Ihr m\195\188sst Raid Leiter oder Assistent sein, um das zu machen.", |
||
42 | ["Requested a status update."] = "Status-Aktualisierung wurde angefordert.", |
||
43 | ["Use shorthands"] = "K\195\188rzel verwenden", |
||
44 | ["Toggle using of CTRA shorthands"] = "Verwendung von CTRA K\195\188rzel umschalten", |
||
45 | [" ...hic!"] = " ...hic!", |
||
46 | ["Request status"] = "Status anfordern", |
||
47 | ["Request a status update"] = "Eine Status-Aktualisierung anfordern", |
||
48 | -- texture handling in the core yeah baby |
||
49 | ["Textures"] = "Texturen", |
||
50 | ["default"] = "default", |
||
51 | ["otravi"] = "otravi", |
||
52 | ["perl"] = "perl", |
||
53 | ["smooth"] = "smooth", |
||
54 | ["striped"] = "striped", |
||
55 | ["bantobar"] = "bantobar", |
||
56 | ["smudge"] = "smudge", |
||
57 | ["charcoal"] = "charcoal", |
||
58 | ["Set all statusbar textures."] = "Texturen der StatusBars festlegen.", |
||
59 | } end) |
||
60 | |||
61 | L:RegisterTranslations("koKR", function() return { |
||
62 | ["You are now AFK"] = "자리 비움으로 설정되었습니다", |
||
63 | ["You are now DND"] = "|1으로;로; 설정되었습니다", |
||
64 | ["You have to be Raid Leader or Assistant to do that."] = "공격대장이거나 승급된 사람만 사용 가능합니다.", |
||
65 | ["Requested a status update."] = "상태 갱신을 요청합니다.", |
||
66 | ["useshorthands"] = "단축명령어사용", |
||
67 | ["Use shorthands"] = "단축 명령어 사용", |
||
68 | ["Toggle using of CTRA shorthands"] = "공격대 도우미 단축 명령어 사용 토글", |
||
69 | [" ...hic!"] = " ...딸꾹!", |
||
70 | ["status"] = "상태", |
||
71 | ["Request status"] = "상태 갱신 요청", |
||
72 | ["Request a status update"] = "상태 갱신을 요청", |
||
73 | -- texture handling in the core yeah baby |
||
74 | ["Textures"] = "텍스쳐", |
||
75 | ["default"] = "기본값", |
||
76 | ["otravi"] = "오트라비", |
||
77 | ["perl"] = "펄", |
||
78 | ["smooth"] = "부드러운바", |
||
79 | ["striped"] = "줄무늬", |
||
80 | ["bantobar"] = "반토바", |
||
81 | ["smudge"] = "얼룩", |
||
82 | ["charcoal"] = "목탄", |
||
83 | ["Set all statusbar textures."] = "모든 바의 텍스쳐로 설정합니다.", |
||
84 | |||
85 | } end) |
||
86 | |||
87 | L:RegisterTranslations("zhCN", function() return { |
||
88 | ["You are now AFK"] = "你正在AFK状态", |
||
89 | ["You are now DND"] = "你正在DND状态", |
||
90 | ["You have to be Raid Leader or Assistant to do that."] = "只有团队领袖/队长才可以", |
||
91 | ["Requested a status update."] = "请求更新状态", |
||
92 | ["useshorthands"] = "使用缩略", |
||
93 | ["Use shorthands"] = "使用缩略", |
||
94 | ["Toggle using of CTRA shorthands"] = "使用CTRA缩略", |
||
95 | ["Toggle using of CTRA shorthands"] = "使用CTRA缩略", |
||
96 | [" ...hic!"] = "...嗝!", |
||
97 | ["status"] = "状态", |
||
98 | ["Request status"] = "获取状态", |
||
99 | ["Request a status update"] = "获取状态更新", |
||
100 | ["Textures"] = "材质", |
||
101 | ["default"] = "default", |
||
102 | ["otravi"] = "otravi", |
||
103 | ["perl"] = "perl", |
||
104 | ["smooth"] = "smooth", |
||
105 | ["striped"] = "striped", |
||
106 | ["bantobar"] = "bantobar", |
||
107 | ["smudge"] = "smudge", |
||
108 | ["charcoal"] = "charcoal", |
||
109 | ["Set all statusbar textures."] = "设置所有状态条的材质" |
||
110 | |||
111 | } end) |
||
112 | |||
113 | L:RegisterTranslations("zhTW", function() return { |
||
114 | ["You are now AFK"] = "你現在處於離開狀態", |
||
115 | ["You are now DND"] = "你現在處於勿打擾狀態", |
||
116 | ["You have to be Raid Leader or Assistant to do that."] = "只有領隊/隊長才可以", |
||
117 | ["Requested a status update."] = "請求更新狀態", |
||
118 | ["useshorthands"] = "使用縮略", |
||
119 | ["Use shorthands"] = "使用縮略", |
||
120 | ["Toggle using of CTRA shorthands"] = "使用CTRA縮略", |
||
121 | ["Toggle using of CTRA shorthands"] = "使用CTRA縮略", |
||
122 | [" ...hic!"] = "...啊!", |
||
123 | ["status"] = "狀態", |
||
124 | ["Request status"] = "請求狀態", |
||
125 | ["Request a status update"] = "請求狀態更新", |
||
126 | ["Textures"] = "材質", |
||
127 | ["default"] = "預設", |
||
128 | ["otravi"] = "otravi", |
||
129 | ["perl"] = "perl", |
||
130 | ["smooth"] = "平滑", |
||
131 | ["striped"] = "條紋", |
||
132 | ["bantobar"] = "bantobar", |
||
133 | ["smudge"] = "斑點", |
||
134 | ["charcoal"] = "炭畫", |
||
135 | ["Set all statusbar textures."] = "設置所有狀態條的材質" |
||
136 | |||
137 | } end) |
||
138 | |||
139 | L:RegisterTranslations("frFR", function() return { |
||
140 | ["You are now AFK"] = "Vous \195\170tes maintenant ABS", |
||
141 | ["You are now DND"] = "Vous \195\170tes maintenant en mode NPD", |
||
142 | ["You have to be Raid Leader or Assistant to do that."] = "Vous devez \195\170tre le chef du raid ou un de ses assistants pour faire cela.", |
||
143 | ["Requested a status update."] = "Mise \195\160 jour du statut demand\195\169.", |
||
144 | ["Use shorthands"] = "Utiliser les commandes courtes", |
||
145 | ["Toggle using of CTRA shorthands"] = "Utilise ou non les commandes courtes de CTRA.", |
||
146 | [" ...hic!"] = " ... hic !", |
||
147 | --["status"] = true, |
||
148 | ["Request status"] = "Demander le statut", |
||
149 | ["Request a status update"] = "Demande une mise \195\160 jour du statut.", |
||
150 | -- texture handling in the core yeah baby |
||
151 | --["Textures"] = true, |
||
152 | ["default"] = "default", |
||
153 | ["otravi"] = "otravi", |
||
154 | ["perl"] = "perl", |
||
155 | ["smooth"] = "smooth", |
||
156 | ["striped"] = "striped", |
||
157 | ["bantobar"] = "bantobar", |
||
158 | ["smudge"] = "smudge", |
||
159 | ["charcoal"] = "charcoal", |
||
160 | ["Set all statusbar textures."] = "D\195\169termine la texture de toutes les barres de statut.", |
||
161 | } end) |
||
162 | |||
163 | --------------------------------- |
||
164 | -- Addon Declaration -- |
||
165 | --------------------------------- |
||
166 | |||
167 | oRA = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceModuleCore-2.0", "AceConsole-2.0", "AceDB-2.0") |
||
168 | oRA:SetModuleMixins("AceEvent-2.0") |
||
169 | oRA.defaults = { |
||
170 | bartexture = L["default"], |
||
171 | useshorthands = true, |
||
172 | } |
||
173 | oRA.version = tonumber(string.sub("$Revision: 17466 $", 12, -3)) |
||
174 | oRA.CTRAversion = CTRAversion |
||
175 | oRA.consoleOptions = { |
||
176 | type = "group", |
||
177 | handler = oRA, |
||
178 | args = { |
||
179 | [L["useshorthands"]] = { |
||
180 | name = L["Use shorthands"], type = "toggle", |
||
181 | desc = L["Toggle using of CTRA shorthands"], |
||
182 | get = function() return oRA.db.profile.useshorthands end, |
||
183 | set = function(v) |
||
184 | oRA.db.profile.useshorthands = v |
||
185 | oRA:UpdateShorthands() |
||
186 | end, |
||
187 | order = 1000, |
||
188 | }, |
||
189 | [L["status"]] = { |
||
190 | name = L["Request status"], type = "execute", |
||
191 | desc = L["Request a status update"], |
||
192 | func = function() |
||
193 | oRA:RequestStatus() |
||
194 | end, |
||
195 | order = 1000, |
||
196 | disabled = function() return not oRA:IsActive() end, |
||
197 | }, |
||
198 | [L["Textures"]] = { |
||
199 | type = "text", |
||
200 | name = L["Textures"], |
||
201 | desc = L["Set all statusbar textures."], |
||
202 | get = function() return oRA.db.profile.bartexture end, |
||
203 | set = function(v) oRA:SetBarTexture(v) end, |
||
204 | validate = { L["smudge"], L["bantobar"], L["charcoal"], L["smooth"], L["otravi"], L["perl"], L["striped"], L["default"] } |
||
205 | } |
||
206 | } |
||
207 | } |
||
208 | |||
209 | oRA:RegisterDB("oRADB", "oRADBPerChar") |
||
210 | oRA:RegisterDefaults("profile", oRA.defaults) |
||
211 | oRA:RegisterChatCommand({"/ora", "/oRA"}, oRA.consoleOptions ) |
||
212 | |||
213 | |||
214 | ------------------------------ |
||
215 | -- Initialization -- |
||
216 | ------------------------------ |
||
217 | |||
218 | function oRA:OnInitialize() |
||
219 | |||
220 | self.checks = {} |
||
221 | self.shorthands = {} |
||
222 | self.moduletooltips = {} |
||
223 | |||
224 | self.roster = AceLibrary("RosterLib-2.0") |
||
225 | |||
226 | setglobal("BINDING_HEADER_oRA2", "oRA2") |
||
227 | |||
228 | self.bartextures = { |
||
229 | ["default"] = "Interface\\TargetingFrame\\UI-StatusBar", |
||
230 | ["otravi"] = "Interface\\AddOns\\oRA2\\Textures\\otravi", |
||
231 | ["perl"] = "Interface\\AddOns\\oRA2\\Textures\\perl", |
||
232 | ["smooth"] = "Interface\\AddOns\\oRA2\\Textures\\smooth", |
||
233 | ["striped"] = "Interface\\AddOns\\oRA2\\Textures\\striped", |
||
234 | ["bantobar"] = "Interface\\AddOns\\oRA2\\Textures\\bantobar", |
||
235 | ["smudge"] = "Interface\\AddOns\\oRA2\\Textures\\smudge", |
||
236 | ["charcoal"] = "Interface\\AddOns\\oRA2\\Textures\\charcoal", |
||
237 | } |
||
238 | |||
239 | self.loading = true |
||
240 | |||
241 | -- try and enable ourselves |
||
242 | self:ToggleActive(true) |
||
243 | end |
||
244 | |||
245 | function oRA:OnEnable() |
||
246 | if AceLibrary("AceEvent-2.0"):IsFullyInitialized() then |
||
247 | self:AceEvent_FullyInitialized() |
||
248 | else |
||
249 | self:RegisterEvent("AceEvent_FullyInitialized") |
||
250 | end |
||
251 | end |
||
252 | |||
253 | function oRA:AceEvent_FullyInitialized() |
||
254 | if GetNumRaidMembers() > 0 or not self.loading then |
||
255 | self:RegisterEvent("CHAT_MSG_ADDON") |
||
256 | self:RegisterEvent("CHAT_MSG_SYSTEM") |
||
257 | |||
258 | self:RegisterEvent("oRA_SendVersion", "DistributeVersion") |
||
259 | self:RegisterEvent("oRA_JoinedRaid") |
||
260 | self:RegisterEvent("oRA_LeftRaid") |
||
261 | self:RegisterEvent("oRA_UpdateVersion") |
||
262 | self:RegisterEvent("oRA_UpdateAfkDnd") |
||
263 | self:RegisterEvent("oRA_UpdateCTRAVersion") |
||
264 | self:RegisterEvent("oRA_UpdateVersion") |
||
265 | |||
266 | self:RegisterCheck("SR", "oRA_SendVersion") |
||
267 | self:RegisterCheck("AFK", "oRA_UpdateAfkDnd") |
||
268 | self:RegisterCheck("DND", "oRA_UpdateAfkDnd") |
||
269 | self:RegisterCheck("UNAFK", "oRA_UpdateAfkDnd") |
||
270 | self:RegisterCheck("UNDND", "oRA_UpdateAfkDnd") |
||
271 | self:RegisterCheck("V", "oRA_UpdateCTRAVersion") |
||
272 | self:RegisterCheck("oRAV", "oRA_UpdateVersion") |
||
273 | |||
274 | self:TriggerEvent("oRA_CoreEnabled") |
||
275 | if GetNumRaidMembers() > 0 then |
||
276 | self:TriggerEvent("oRA_JoinedRaid") |
||
277 | else |
||
278 | self:TriggerEvent("oRA_LeftRaid") |
||
279 | end |
||
280 | else |
||
281 | self:ToggleActive(false) |
||
282 | end |
||
283 | self.loading = nil |
||
284 | end |
||
285 | |||
286 | function oRA:OnDisable() |
||
287 | self:TriggerEvent("oRA_LeftRaid") |
||
288 | |||
289 | -- Unconditionally disable all modules, disregarding module.shouldEnable |
||
290 | local name, module = nil, nil |
||
291 | for name, module in self:IterateModules() do |
||
292 | self:ToggleModuleActive(module, false) |
||
293 | end |
||
294 | |||
295 | self:TriggerEvent("oRA_CoreDisabled") |
||
296 | self:UnregisterAllEvents() |
||
297 | end |
||
298 | |||
299 | -------------------------------- |
||
300 | -- Module Prototype -- |
||
301 | -------------------------------- |
||
302 | |||
303 | oRA.modulePrototype.core = oRA |
||
304 | |||
305 | function oRA.modulePrototype:OnInitialize() |
||
306 | -- Unconditionally register, this shouldn't happen from any other place |
||
307 | -- anyway. |
||
308 | self.core:RegisterModule(self.name, self) |
||
309 | end |
||
310 | |||
311 | function oRA.modulePrototype:RegisterCheck( c, e ) |
||
312 | self.core:RegisterCheck(c, e) |
||
313 | self:RegisterEvent(e) |
||
314 | end |
||
315 | |||
316 | function oRA.modulePrototype:UnregisterCheck( c ) |
||
317 | self.core:UnregisterCheck(c) |
||
318 | end |
||
319 | |||
320 | function oRA.modulePrototype:IsValidRequest( a, i) |
||
321 | return self.core:IsValidRequest(a, i) |
||
322 | end |
||
323 | |||
324 | function oRA.modulePrototype:SendMessage( msg, ora) |
||
325 | self.core:SendMessage(msg, ora) |
||
326 | end |
||
327 | |||
328 | function oRA.modulePrototype:CleanMessage( msg ) |
||
329 | return self.core:CleanMessage( msg ) |
||
330 | end |
||
331 | |||
332 | function oRA.modulePrototype:IsPromoted( a ) |
||
333 | return self.core:IsPromoted( a ) |
||
334 | end |
||
335 | |||
336 | function oRA.modulePrototype:RegisterShorthand( s, f, i) |
||
337 | self.core:RegisterShorthand(s, f, i) |
||
338 | end |
||
339 | |||
340 | function oRA.modulePrototype:UnregisterShorthand( s ) |
||
341 | self.core:UnregisterShorthand(s) |
||
342 | end |
||
343 | |||
344 | function oRA.modulePrototype:Print( msg ) |
||
345 | self.core:Print("(%s) %s", self.name, msg ) |
||
346 | end |
||
347 | |||
348 | function oRA.modulePrototype:IsRegistered() |
||
349 | return self.registered |
||
350 | end |
||
351 | ------------------------------- |
||
352 | -- Module Handling -- |
||
353 | ------------------------------- |
||
354 | |||
355 | function oRA:RegisterModule(name, module) |
||
356 | |||
357 | if module:IsRegistered() then |
||
358 | error(string.format("%q is already registered.", name)) |
||
359 | return |
||
360 | end |
||
361 | |||
362 | if module.db and module.RegisterDefaults and type(module.RegisterDefaults) == "function" then |
||
363 | module:RegisterDefaults("profile", opts or module.defaults or {}) |
||
364 | else |
||
365 | self:RegisterDefaults(name, "profile", opts or module.defaults or {}) |
||
366 | end |
||
367 | |||
368 | if not module.db then module.db = self:AcquireDBNamespace(name) end |
||
369 | |||
370 | if module.consoleOptions then |
||
371 | local m = module.consoleCmd or name |
||
372 | -- if the consoleoption already exists we merge in the data otherwise we create a new option |
||
373 | if self.consoleOptions.args[m] then |
||
374 | for k,v in pairs(module.consoleOptions.args) do self.consoleOptions.args[m].args[k] = v end |
||
375 | else |
||
376 | self.consoleOptions.args[m] = module.consoleOptions |
||
377 | end |
||
378 | end |
||
379 | if module.OnTooltipUpdate then |
||
380 | self.moduletooltips[name] = module |
||
381 | end |
||
382 | module.registered = true |
||
383 | if module.OnRegister and type(module.OnRegister) == "function" then |
||
384 | module:OnRegister() |
||
385 | end |
||
386 | end |
||
387 | |||
388 | ------------------------------- |
||
389 | -- Core -- |
||
390 | ------------------------------- |
||
391 | |||
392 | -- Distrubutes your version to the raid |
||
393 | |||
394 | function oRA:DistributeVersion() |
||
395 | self:SendMessage( "V " .. self.CTRAversion) |
||
396 | self:SendMessage( "oRAV "..self.version, true ) |
||
397 | end |
||
398 | |||
399 | |||
400 | -- Command handler |
||
401 | -- Updates the shorthands for the current setting |
||
402 | |||
403 | function oRA:UpdateShorthands() |
||
404 | if self.db.profile.useshorthands then |
||
405 | local s,f |
||
406 | for s,f in pairs(self.shorthands) do |
||
407 | self:RegisterShorthand(s, f, true) |
||
408 | end |
||
409 | else |
||
410 | local s,f |
||
411 | for s, f in pairs(self.shorthands) do |
||
412 | local type = "ORA_SHORTHAND_"..strupper(s) |
||
413 | SlashCmdList[type] = nil |
||
414 | setglobal("SLASH_"..type.."1", nil) |
||
415 | end |
||
416 | end |
||
417 | end |
||
418 | |||
419 | -- Command handler |
||
420 | -- Sends a status request. |
||
421 | |||
422 | function oRA:RequestStatus() |
||
423 | self:Print(L["Requested a status update."]) |
||
424 | self:SendMessage("SR") |
||
425 | end |
||
426 | |||
427 | function oRA:SetBarTexture( texture ) |
||
428 | if L:HasReverseTranslation(texture) then |
||
429 | texture = L:GetReverseTranslation(texture) |
||
430 | else |
||
431 | texture = "default" |
||
432 | end |
||
433 | self.db.profile.bartexture = texture |
||
434 | |||
435 | self:TriggerEvent("oRA_BarTexture", texture ) |
||
436 | end |
||
437 | |||
438 | ------------------------------- |
||
439 | -- Event Handlers -- |
||
440 | ------------------------------- |
||
441 | |||
442 | function oRA:oRA_JoinedRaid() |
||
443 | local name, module = nil, nil |
||
444 | local enabledModule = nil |
||
445 | for name, module in self:IterateModules() do |
||
446 | if not self:IsModuleActive(module) then enabledModule = true end |
||
447 | self:ToggleModuleActive(module, true) |
||
448 | end |
||
449 | if enabledModule then |
||
450 | self:TriggerEvent("oRA_JoinedRaid") |
||
451 | end |
||
452 | self:DistributeVersion() |
||
453 | end |
||
454 | |||
455 | function oRA:oRA_LeftRaid() |
||
456 | local name, module = nil, nil |
||
457 | for name, module in self:IterateModules() do |
||
458 | if not module.shouldEnable or (module.shouldEnable ~= nil and type(module.shouldEnable) == "function" and not module:shouldEnable()) then |
||
459 | self:ToggleModuleActive(module, false) |
||
460 | end |
||
461 | end |
||
462 | end |
||
463 | |||
464 | -- Event handler for the CHAT_MSG_ADDON event |
||
465 | -- Parses the info sent over the addon channel |
||
466 | -- Checks for the keywrods and triggers the appropriate events |
||
467 | |||
468 | function oRA:CHAT_MSG_ADDON(prefix, msg, type, author) |
||
469 | if prefix ~= "CTRA" and prefix ~= "oRA" then return end |
||
470 | if type ~= "RAID" then return end |
||
471 | local msgArr = self:SplitMessage(msg, "#") |
||
472 | for _, c in pairs(msgArr) do |
||
473 | cmd = self:SplitMessage(c, " ") |
||
474 | if self.checks[cmd[1]] then |
||
475 | self:TriggerEvent(self.checks[cmd[1]],c, author) |
||
476 | end |
||
477 | end |
||
478 | end |
||
479 | |||
480 | |||
481 | -- Event handler for the CHAT_MSG_SYSTEM event |
||
482 | -- Will send your AFK/DND status to the raid |
||
483 | |||
484 | function oRA:CHAT_MSG_SYSTEM(msg) |
||
485 | if string.find(msg, "^"..ERR_RAID_YOU_LEFT) then |
||
486 | self:TriggerEvent("oRA_LeftRaid") |
||
487 | elseif string.find(msg, ERR_RAID_YOU_JOINED) then |
||
488 | self:TriggerEvent("oRA_JoinedRaid") |
||
489 | elseif string.find(msg, L["You are now AFK"]) then |
||
490 | self:SendMessage("AFK") |
||
491 | elseif string.find(msg, L["You are now DND"]) then |
||
492 | self:SendMessage("DND") |
||
493 | elseif string.find(msg, CLEARED_AFK ) then |
||
494 | self:SendMessage("UNAFK") |
||
495 | elseif string.find(msg, CLEARED_DND ) then |
||
496 | self:SendMessage("UNDND") |
||
497 | end |
||
498 | end |
||
499 | |||
500 | ------------------------------- |
||
501 | -- Checks Event Handlers -- |
||
502 | ------------------------------- |
||
503 | |||
504 | -- Event handler for the AFK/DND/UNAFK/UNDND messages |
||
505 | -- Will update the roster for the player who sent the message |
||
506 | |||
507 | function oRA:oRA_UpdateAfkDnd(msg, author) |
||
508 | |||
509 | if not self:IsValidRequest( author, true) then return end |
||
510 | local u = self.roster:GetUnitObjectFromName(author) |
||
511 | if not u then return end |
||
512 | |||
513 | msg = self:CleanMessage(msg) |
||
514 | |||
515 | if string.find( msg, "^AFK(.*)") then u.ora_afk = true |
||
516 | elseif string.find( msg, "^DND(.*)") then u.ora_dnd = true |
||
517 | elseif string.find( msg, "^UNAFK(.*)") then u.ora_afk = nil |
||
518 | elseif string.find( msg, "^UNDND(.*)") then u.ora_dnd = nil |
||
519 | end |
||
520 | self:TriggerEvent("oRA_AfkDndUpdated", author) |
||
521 | end |
||
522 | |||
523 | -- Event handler for the "V " message |
||
524 | -- Will update the roster for the player who sent the V with his version |
||
525 | |||
526 | function oRA:oRA_UpdateCTRAVersion(msg, author) |
||
527 | if not self:IsValidRequest( author, true ) then return end |
||
528 | local u = self.roster:GetUnitObjectFromName(author) |
||
529 | if not u then return end |
||
530 | |||
531 | msg = self:CleanMessage(msg) |
||
532 | |||
533 | local _,_,version = string.find(msg, "V (.+)") |
||
534 | |||
535 | if version then u.ora_ctraversion = version end |
||
536 | end |
||
537 | |||
538 | -- Event handler for the "oRAV " message |
||
539 | -- Will update the roster for the player who sent the oRAV with his version |
||
540 | |||
541 | function oRA:oRA_UpdateVersion(msg, author) |
||
542 | if not self:IsValidRequest( author, true ) then return end |
||
543 | local u = self.roster:GetUnitObjectFromName(author) |
||
544 | if not u then return end |
||
545 | |||
546 | msg = self:CleanMessage(msg) |
||
547 | |||
548 | local _,_,version = string.find(msg, "oRAV (.+)") |
||
549 | |||
550 | if version then u.ora_version = version end |
||
551 | end |
||
552 | |||
553 | ------------------------------- |
||
554 | -- Raid Roster Utils -- |
||
555 | ------------------------------- |
||
556 | |||
557 | -- Checks if the player is raid leader or raid officer |
||
558 | -- Args: showmsg - when set to true will print out an error when the check fails |
||
559 | -- Returns true when the player is raid leader or raid officer |
||
560 | |||
561 | function oRA:IsPromoted( showmsg ) |
||
562 | if IsRaidLeader() or IsRaidOfficer() then return true end |
||
563 | if showmsg then self:Print(L["You have to be Raid Leader or Assistant to do that."]) end |
||
564 | return false |
||
565 | end |
||
566 | |||
567 | -- Checks if a player is in the raid and optionally if he/she has the correct rank |
||
568 | -- Args: name - name of the player |
||
569 | -- ignorerank - flag, when set to true will ignore the rank of the player |
||
570 | -- Returns true when a player is authorized for a request |
||
571 | |||
572 | function oRA:IsValidRequest( name, ignorerank ) |
||
573 | if (not name) then name = UnitName("player") end |
||
574 | local u = self.roster:GetUnitObjectFromName( name ) |
||
575 | if u then |
||
576 | if ignorerank then return true end |
||
577 | if u.rank > 0 then return true end |
||
578 | end |
||
579 | return false |
||
580 | end |
||
581 | |||
582 | --------------------------- |
||
583 | -- Channel checks -- |
||
584 | --------------------------- |
||
585 | |||
586 | -- Registers a keyword check |
||
587 | -- Args: check - keyword to check on |
||
588 | -- event - event to fire when the keyword is received |
||
589 | |||
590 | function oRA:RegisterCheck(check,event) |
||
591 | self.checks[check] = event |
||
592 | end |
||
593 | |||
594 | -- Unregisters a keyword check |
||
595 | -- Args: check - keyword to remove from the checklist |
||
596 | |||
597 | function oRA:UnregisterCheck(check) |
||
598 | if self.checks[check] then self.checks[check] = nil end |
||
599 | end |
||
600 | |||
601 | --------------------------- |
||
602 | -- Messaging -- |
||
603 | --------------------------- |
||
604 | |||
605 | -- Sends a message |
||
606 | -- Args: msg - message to send |
||
607 | -- returns true when succesful |
||
608 | |||
609 | function oRA:SendMessage( msg, ora ) |
||
610 | if ora then |
||
611 | SendAddonMessage("oRA", msg, "RAID") |
||
612 | else |
||
613 | SendAddonMessage("CTRA", msg, "RAID") |
||
614 | end |
||
615 | return true |
||
616 | end |
||
617 | |||
618 | |||
619 | -- Cleans a message replacing escaped characters by their true ones. |
||
620 | -- also removes the drunken ... hic! |
||
621 | -- Args: msg - msg to clean |
||
622 | -- Returns the cleaned up message |
||
623 | |||
624 | function oRA:CleanMessage( msg ) |
||
625 | msg = string.gsub(msg, "%$", "s") |
||
626 | msg = string.gsub(msg, "§", "S") |
||
627 | |||
628 | if strsub(msg, strlen(msg)-strlen(L[" ...hic!"]) ) == L[" ...hic!"] then |
||
629 | msg = strsub(msg, 1, strlen(msg)-strlen(L[" ...hic!"])) |
||
630 | end |
||
631 | return msg |
||
632 | end |
||
633 | |||
634 | -- Splits a string on a given character |
||
635 | -- Args: msg - string to split |
||
636 | -- char - character to split on |
||
637 | -- Returns an array with all the pieces this array will contain the total string if |
||
638 | -- the split character was not found. |
||
639 | |||
640 | function oRA:SplitMessage( msg, char ) |
||
641 | local arr = { } |
||
642 | while (string.find(msg, char) ) do |
||
643 | local iStart, iEnd = string.find(msg, char) |
||
644 | table.insert(arr, strsub(msg, 1, iStart-1)) |
||
645 | msg = strsub(msg, iEnd+1, strlen(msg)) |
||
646 | end |
||
647 | if ( strlen(msg) > 0 ) then |
||
648 | table.insert(arr, msg) |
||
649 | end |
||
650 | return arr |
||
651 | end |
||
652 | |||
653 | --------------------------------- |
||
654 | -- Short Hand System -- |
||
655 | --------------------------------- |
||
656 | |||
657 | -- Registers a CTRA shorthand |
||
658 | -- Args: shorthand - shorthand you wish to register: rajoin => /rajoin |
||
659 | -- func - function to execute |
||
660 | -- system - when set to true will only enable the shorthand not register it again. |
||
661 | -- this flag is only used by the core itself. |
||
662 | |||
663 | function oRA:RegisterShorthand(shorthand, func, system) |
||
664 | if shorthand and shorthand ~= "" then |
||
665 | if self.db.profile.useshorthands then |
||
666 | local type = "ORA_SHORTHAND_"..strupper(shorthand) |
||
667 | SlashCmdList[type] = func |
||
668 | setglobal("SLASH_"..type.."1", "/"..strlower(shorthand)) |
||
669 | end |
||
670 | if not system then |
||
671 | self.shorthands[shorthand] = func |
||
672 | end |
||
673 | end |
||
674 | end |
||
675 | |||
676 | |||
677 | -- Unregisters a CTRA shorthand |
||
678 | -- Args: shorthand - the shorthand you wish to unregister |
||
679 | -- Returns true when succesful |
||
680 | |||
681 | function oRA:UnregisterShorthand( shorthand ) |
||
682 | if shorthand and shorthand ~= "" then |
||
683 | local s, f |
||
684 | for s, f in pairs(self.shorthands) do |
||
685 | if s == shorthand then |
||
686 | local type = "ORA_SHORTHAND_"..strupper(s) |
||
687 | SlashCmdList[type] = nil |
||
688 | setglobal("SLASH_"..type.."1", nil) |
||
689 | self.shorthands[s] = nil |
||
690 | return true |
||
691 | end |
||
692 | end |
||
693 | end |
||
694 | end |
||
695 | |||
696 |