-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoosePortalCore.lua
961 lines (837 loc) · 33.6 KB
/
MoosePortalCore.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
local ADDONNAME, WIC = ...
-- luacheck: globals LibStub ItemRefTooltip
LibStub("AceAddon-3.0"):NewAddon(WIC, ADDONNAME, "AceConsole-3.0", "AceEvent-3.0", "AceHook-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale(ADDONNAME)
local _G = _G
local GetTime = GetTime
local find, split, lower, format, len, join =
strfind, strsplit, strlower, format, strlen, strjoin
local type, select, pairs, error, wipe =
type, select, pairs, error, wipe
-- L["CHAT_MSG_CHANNEL"] = "All Channels"
WIC.RegisteredModules = {}
WIC.RegisteredModulesWithLoadOnDemand = {}
WIC.RegisteredModulesDescription = {}
WIC.RegisteredModulesTranslatedName = {}
WIC.RegisteredModulesList = L["No Modules Registered"]
function WIC:RegisterModule(name, handle, addonName)
self.RegisteredModules[name] = handle
if type(addonName) == "string" then
self.RegisteredModulesWithLoadOnDemand[name] = addonName
end
end
function WIC:AddTranslatedNameToModule(name, localeName)
self.RegisteredModulesTranslatedName[name] = localeName
end
function WIC:AddDescriptionToModule(name, description)
self.RegisteredModulesDescription[name] = description
end
do-- Adding modules
WIC:RegisterModule("Advanced", "MoosePortalAdvanced", "MoosePortalAdvanced")
WIC:AddTranslatedNameToModule("Advanced" ,L["Advanced"])
WIC:AddDescriptionToModule("Advanced" ,L["Invite player when they whisper you with a defined keyword where they are allowed to use."])
-- Search for third-party Modules
-- Add this to your TOC-File:
--[[
RequiredDeps: MoosePortal
X-MoosePortal-Name: ModuleName
X-MoosePortal-Handle: AddonName -> used as in LibStub("AceAddon-3.0"):GetAddon(AddonName, true) or Global Variable Name
X-MoosePortal-Version: Version -> See MODULEVERSION
X-MoosePortal-Description: Small Description
LoadOnDemand: 1 -> for when you only want be loaded when needed
--]]
--Name and Description supports localization e.g: X-MoosePortal-Description-deDE
-- Needed functions when not a AceAddon:
--[[
Module:Enable()
Module:Disable()
Module:IsEnabled()
--]]
local tonumber, tinsert =
tonumber, tinsert
local GetAddOnInfo, GetAddOnMetadata =
GetAddOnInfo, GetAddOnMetadata
local MODULEVERSION = 0
local locale = GAME_LOCALE or GetLocale()-- luacheck: ignore
for index=1, GetNumAddOns() do
local addonName, title, notes, enabled, loadable, reason, security = GetAddOnInfo(index)
local version = GetAddOnMetadata(addonName, "X-MoosePortal-Version")
if version and tonumber(version) == MODULEVERSION and loadable then
local name = GetAddOnMetadata(addonName, "X-MoosePortal-Name")
local localeName = GetAddOnMetadata(addonName, "X-MoosePortal-Name-"..locale) or name
local description = GetAddOnMetadata(addonName, "X-MoosePortal-Description-"..locale) or GetAddOnMetadata(addonName, "X-MoosePortal-Description") or L["No description for this module."]
local handle = GetAddOnMetadata(addonName, "X-MoosePortal-Handle")
if name and handle then
WIC:RegisterModule(name, handle, addonName)
WIC:AddTranslatedNameToModule(name, name)
end
if name and localeName then
WIC:AddTranslatedNameToModule(name, localeName)
end
if name and description then
WIC:AddDescriptionToModule(name, description)
else
WIC:AddDescriptionToModule(name, L["No description for this module."])
end
end
end
local list = {}
for moduleName in pairs(WIC.RegisteredModules) do
local name = moduleName--(WIC.RegisteredModulesTranslatedName[name] or name).."<"..name..">"
tinsert(list, name)
end
WIC.RegisteredModulesList = join(", ", unpack(list) )
end
local LF_QUEUE_PVP = "PVP"
local LF_QUEUES = {
['**'] = {
blockInvites = true,
sendMessage = false,
returnMessage = L["I'm currently in a LF-Queue"],
},
[LF_QUEUE_PVP] = {},
}
for id, name in pairs(LFG_CATEGORY_NAMES) do
LF_QUEUES[id] = {}
end
local defaults = {
global = {},
char = {
info = {
['*'] = 0,
},
infoMax = {
['*'] = 3,
setup = 5,
lfr_block = 9,
},
},
profile = {
active = true,
selectedModuleName = false,
convertGroupToRaid = true,
inviteThrottleTime = 10, -- seconds
queueProtection = LF_QUEUES,
statusProtection = {
AFK = {
blockInvites = false,
sendMessage = false,
returnMessage = L["I'm currently AFK"],
},
DND = {
blockInvites = false,
sendMessage = false,
returnMessage = L["I'm currently DND"],
},
},
},
}
WIC.TYPES = {
LINK = "MoosePortal",
H_LINK = "|HMoosePortal|h",
}
WIC.LOOKUP_LOCALIZED_CLASS_NAMES = {}
-- TODO: handling of profile.active
function WIC:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("MoosePortalCoreDB", defaults, true)
self.db.RegisterCallback(self, "OnProfileChanged", "CheckEnabledState")
self.db.RegisterCallback(self, "OnProfileCopied", "CheckEnabledState")
self:RegisterConfig()
-- To enable MoosePortal when disabled
self:RegisterChatCommand("mooseportalenable", "Enable", true)
self:RegisterChatCommand("mpenable", "Enable", true)
self:RegisterChatCommand("mooseportaldisable", "Disable", true)
self:RegisterChatCommand("mpdisable", "Disable", true)
self:RegisterChatCommand("mp", "CMD", true)
self:RegisterChatCommand("moostportal", "CMD", true)
-- build localized lookup table for class names
for class, classLocalized in pairs(_G.LOCALIZED_CLASS_NAMES_MALE) do
self.LOOKUP_LOCALIZED_CLASS_NAMES[classLocalized] = class
end
for class, classLocalized in pairs(_G.LOCALIZED_CLASS_NAMES_FEMALE) do
self.LOOKUP_LOCALIZED_CLASS_NAMES[classLocalized] = class
end
self:SetEnabledState(self.db.profile.active)
if not self:IsEnabled() and self.db.char.info.enable < self.db.char.infoMax.enable then
self.db.char.info.enable = self.db.char.info.enable + 1
self:Print(L["You can run /mpenable to enable MoosePortal."])
end
end
function WIC:Enable_ModuleHandling()
local showInfo = true
if type(self.db.profile.selectedModuleName) == "string" then
local isEnabled = self:EnableSelectedModule()
if isEnabled or self:SelectModuleIsEnabled() then
-- Module is registered and enabled
showInfo = false
end
end
if showInfo then
if self.db.char.info.setup < self.db.char.infoMax.setup then
self.db.char.info.setup = self.db.char.info.setup + 1
self:Print(L["Run /mp modules or /mp options to setup MoosePortal."])
end
end
end
function PrintWelcomeMsg()
local realm = GetRealmName()
local faction = UnitFactionGroup("player")
local msg = format("|cffAAAAAAversion: %s, bugs & features: github.com/Sp5rky/MoosePortal|r\n|cff209f9b", GetAddOnMetadata(addonName, "Version"))
if (realm == "Arugal" and faction == "Horde") then
msg = msg .. format("You are lucky enough to play with MoosePortal author on one |cffFFFFFF%s |cff209f9brealm! Feel free to mail me (|cff8787edQk|cff209f9b) a supportive gold tip or kind word!", realm)
end
Print(msg .. "|r")
end
function WIC:OnEnable()
self:Enable_ModuleHandling()
-- Hooking
self:SecureHook("ChatFrame_OnHyperlinkShow")
self:RawHook("HandleModifiedItemClick", true)
self:RawHook(ItemRefTooltip, "SetHyperlink", "ItemRefTooltip_SetHyperlink", true)
end
function WIC:ItemRefTooltip_SetHyperlink(frame, link, ...)
if link and find(link, self.TYPES.LINK) then
return false
else
return self.hooks[frame].SetHyperlink(frame, link, ...)
end
end
function WIC:HandleModifiedItemClick(link, ...)
if link and find(link, self.TYPES.H_LINK) then
return false
else
return self.hooks.HandleModifiedItemClick(link, ...)
end
end
function WIC:ChatFrame_OnHyperlinkShow(frame, linkData, link, button, ...)
if split(":", linkData) == self.TYPES.LINK then
local _, toonID, toonName, presenceName, presenceID, debug = split(":", linkData)
--[===[@debug@
if debug == "DEBUG" then
self:Printf("Invite: %s(%s), id:%s", toonName, presenceName, toonID)
return
end
--@end-debug@]===]
local result, code = self:InviteToon(toonID, toonName, presenceName, presenceID)
--[===[@debug@
self:Printf("Invite Sent: %s", result and "OK" or "Error: "..code )
--@end-debug@]===]
--else
--self.hooks.ChatFrame_OnHyperlinkShow(frame, linkData, link, button, ...)
end
end
function WIC:Disable_ModuleHandling()
self:DisableSelectedModule()
end
function WIC:OnDisable()
self:Disable_ModuleHandling()
end
function WIC:CheckEnabledState(event, db)
db = db or self.db
if db.profile.active then
--[===[@debug@
self:Print("Active")
--@end-debug@]===]
if not self:IsEnabled() then
--[===[@debug@
self:Print("Enable")
--@end-debug@]===]
self:Enable()
else
--[===[@debug@
self:Print("Enable->Module")
--@end-debug@]===]
self:Enable_ModuleHandling()
end
elseif self:IsEnabled() then
--[===[@debug@
self:Print("Disable")
--@end-debug@]===]
self:Disable()
end
end
do-- CMD
local InterfaceOptionsFrame_OpenToCategory, InterfaceOptionsFrameAddOnsListScrollBar =
InterfaceOptionsFrame_OpenToCategory, InterfaceOptionsFrameAddOnsListScrollBar
function WIC:CMD(input, editBox)
--GetArgs(str, numargs, startpos)
local arg1, lastPos = self:GetArgs(input, 1)
arg1 = arg1 and lower(arg1) or ""
if arg1 == "modules" then
local moduleName = self:GetArgs(input, 1, lastPos)
if self.RegisteredModules[moduleName] then
self:SelectModule(moduleName)
else
self:Printf(L["Usage: /mp modules moduleName (case sensitive)"])
self:Printf(L["Modules: %s"], self.RegisteredModulesList )
end
elseif arg1 == "enable" or arg1 == "on" or arg1 == L["enable"] or arg1 == L["on"] then
self.db.profile.active = true
self:NotifyChange()
WIC:CheckEnabledState("", self.db)
self:Print(L["Enabled"])
elseif arg1 == "disable" or arg1 == "off" or arg1 == L["disable"] or arg1 == L["off"] then
self.db.profile.active = false
self:NotifyChange()
WIC:CheckEnabledState("", self.db)
self:Print(L["Disabled"])
elseif arg1 == "toggle" or arg1 == L["toggle"] then
self.db.profile.active = not self.db.profile.active
self:NotifyChange()
WIC:CheckEnabledState("", self.db)
if self.db.profile.active then
self:Print(L["Enabled"])
else
self:Print(L["Disabled"])
end
elseif not arg1 or arg1 == "" or arg1 == "help" or arg1 == "usage" or arg1 == L["help"] or arg1 == L["usage"] then
self:Print(L["Usage: /mp <command>\nCommands: modules, options"])
elseif arg1 == "options" or arg1 == "op" then
-- Load InterfaceOptionsFrameAddOns frame...
InterfaceOptionsFrame_OpenToCategory(ADDONNAME)
-- Let's scroll down, so your page can be open
InterfaceOptionsFrameAddOnsListScrollBar:SetValue(select(2, InterfaceOptionsFrameAddOnsListScrollBar:GetMinMaxValues() ) )
InterfaceOptionsFrame_OpenToCategory(ADDONNAME)
else
LibStub("AceConfigCmd-3.0").HandleCommand(self, "mp", ADDONNAME.."Options", input)
end
end
end
function WIC:SelectModule(moduleName)
if self.RegisteredModules[moduleName] then
local profile = self.db.profile
profile.selectedModuleName = moduleName
if profile.active then
return self:EnableSelectedModule()
end
return true
end
return false
end
do-- Module handling
local IsAddOnLoaded, LoadAddOn =
IsAddOnLoaded, LoadAddOn
local oldModule
function WIC:EnableSelectedModule()
local name = self.db.profile.selectedModuleName
local addonName = self.RegisteredModulesWithLoadOnDemand[name]
if name and addonName then
if not IsAddOnLoaded(addonName) then
local loaded, resason = LoadAddOn(self.RegisteredModulesWithLoadOnDemand[name])
if not loaded then
self:Printf(L["Can't load module %s because %s"], name, _G["ADDON_"..resason] or resason)
return false, resason
end
end
local handle = self.RegisteredModules[name]
local selectModule = LibStub("AceAddon-3.0"):GetAddon(handle, true) or _G[handle]
if selectModule and type(selectModule.Enable) == "function" then
if oldModule and type(oldModule.Disable) == "function" then
oldModule:Disable()
end
oldModule = selectModule
return selectModule:Enable()
else
self:Print(not selectModule and L["Module not found."] or L["Module hasn't needed functions."] )
return false
end
else
self:Printf(L["Can't load module. %s"], (not name and L["No module selected!"] or not addonName and L["Addon name not found!"] or "") )
return false
end
end
function WIC:SelectModuleIsEnabled()
local activeModule = oldModule
if not activeModule then
local name = self.db.profile.selectedModuleName
local handle = self.RegisteredModules[name]
activeModule = LibStub("AceAddon-3.0"):GetAddon(handle, true) or _G[handle]
end
if type(activeModule.IsEnabled) == "function" then
return activeModule:IsEnabled()
end
return false
end
end
function WIC:DisableSelectedModule()
local name = self.db.profile.selectedModuleName
--[===[@debug@
self:Print("Disable Module: ", name)
--@end-debug@]===]
if name then
local handle = self.RegisteredModules[name]
local selectModule = LibStub("AceAddon-3.0"):GetAddon(handle, true) or _G[handle]
--[===[@debug@
self:Print("selectModule: ", selectModule, ", type: ", type(selectModule), ", selectModule.Disable type: ", type(selectModule.Disable))
--@end-debug@]===]
if selectModule and type(selectModule.Disable) == "function" then
selectModule:Disable()
--[===[@debug@
self:Print("Module disabled")
--@end-debug@]===]
end
end
end
do-- CanInvite
local IsInGroup, UnitIsGroupLeader, UnitIsGroupAssistant, GetInstanceInfo =
IsInGroup, UnitIsGroupLeader, UnitIsGroupAssistant, GetInstanceInfo
local LE_PARTY_CATEGORY_INSTANCE = LE_PARTY_CATEGORY_INSTANCE
function WIC:CanInvite()
--if _G.IsInGroup(_G.LE_PARTY_CATEGORY_INSTANCE) and select(3, _G.GetInstanceInfo() ) ~= 14 then
--if select(3, _G.GetInstanceInfo() ) ~= 7 then
if IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
-- we can not invite when in a instance group or can we?
local _, _, difficultyID = GetInstanceInfo()
if difficultyID ~= 7 -- LFR
and difficultyID ~= 17 -- LFR 10-30
and difficultyID ~= 1 -- Normal
and difficultyID ~= 2 --[[Heroic]] then
-- Print infos only a limit time
if self.db.char.info.lfr_block < self.db.char.infoMax.lfr_block then
self:Printf(L["You are in an instance group and not in LFR or LFG group. When you can invite here players let me know it."])
local name, instanceType, difficultyName, maxPlayers, dynamicDifficulty, isDynamic, instanceMapID, instanceGroupSize
name, instanceType, difficultyID, difficultyName, maxPlayers, dynamicDifficulty, isDynamic, instanceMapID, instanceGroupSize = _G.GetInstanceInfo()
local info = "instanceType:"..instanceType..", difficultyID:"..difficultyID..", difficultyName:"..difficultyName
self:Printf(L["And show me this infos: %s"], info)
self.db.char.info.lfr_block = self.db.char.info.lfr_block + 1
end
-- hope nothing explodes..
return UnitIsGroupLeader("player") or UnitIsGroupAssistant("player") or not IsInGroup()
end
return false
else
return UnitIsGroupLeader("player") or UnitIsGroupAssistant("player") or not IsInGroup()
end
end
end
do-- CheckGroupSize
local ConvertToRaid, IsInRaid, GetNumGroupMembers
= ConvertToRaid, IsInRaid, GetNumGroupMembers
local LE_PARTY_CATEGORY_HOME, MAX_PARTY_MEMBERS
= LE_PARTY_CATEGORY_HOME, MAX_PARTY_MEMBERS
function WIC:CheckGroupSize()
if not IsInRaid() and GetNumGroupMembers(LE_PARTY_CATEGORY_HOME) > MAX_PARTY_MEMBERS then
if self.db.profile.convertGroupToRaid then
ConvertToRaid()
return true
else
return false
end
end
return true
end
end
--- InviteErrorCodeList
-- 1: Player is not allowed to invite other players
-- 2: No BNet/RealID friend is online with this presenceID
-- 3: Invalid parameters
-- 4: Maximal group size reached
-- 5: No WoW toon is online
-- 6: Invite for this key was throttled
-- 7: Invite was blocked because of a LF-Queue or Status (AFK/DND)
do-- InvitePlayer
local InviteUnit, Ambiguate =
InviteUnit, Ambiguate
local playerName_Throttle = {}
--- Invite player with name
-- @param (String) name
-- @return1 (Boolean) true == Invite sent, false == Invite not possible
-- @return2 (Number) errorCode @see InviteErrorCodeList
function WIC:InvitePlayer(name)
if not name then
return false, 3
end
if self:CanInvite() then
if self:CheckGroupSize() then
local time = GetTime()
if (playerName_Throttle[name] or 0) < time then
playerName_Throttle[name] = time + self.db.profile.inviteThrottleTime
InviteUnit( Ambiguate(name, "none") )
return true
else
return false, 6
end
else
self:Printf(L["Maximal group size reached. Can't invite %s"], name)
return false, 4
end
else
return false, 1
end
end
end
do-- InviteBNet
local BNGetFriendIndex, BNGetNumFriendGameAccounts, BNGetFriendGameAccountInfo, BNGetFriendInfo, UnitFactionGroup =
BNGetFriendIndex, BNGetNumFriendGameAccounts, BNGetFriendGameAccountInfo, BNGetFriendInfo, UnitFactionGroup
local BNET_CLIENT_WOW, RAID_CLASS_COLORS =
BNET_CLIENT_WOW, RAID_CLASS_COLORS
local toonCache = {}
--- Invite player over Battle.net
-- @paramsig presenceID [, friendIndex]
-- @paramsig nil, friendIndex
-- @param (presenceID) presenceID
-- @param (Number) friendIndex
-- @return1 (Boolean) true: Invite sent, false: Invite not possible
-- @return2 (Number) errorCode @see InviteErrorCodeList
--[===[@debug@
function WIC:InviteBNet(presenceID, friendIndex, debug)
--@end-debug@]===]
--@non-debug@
function WIC:InviteBNet(presenceID, friendIndex)
--@end-non-debug@
if not self:CanInvite() then
return false, 1
end
if type(friendIndex) ~= "number" and presenceID then
friendIndex = BNGetFriendIndex(presenceID)
if not friendIndex then
return false, 2
end
elseif type(friendIndex) ~= "number" then
return false, 3
end
local numToons = BNGetNumFriendGameAccounts(friendIndex)
local toonCount = 0
for toonIndex=1, numToons do
local hasFocus, toonName, client, realmName, realmID, faction, race, classLocalized, guild, zoneName, level, gameText, broadcastText, broadcastTime, canSoR, toonID = BNGetFriendGameAccountInfo(friendIndex, toonIndex)
if client == BNET_CLIENT_WOW then
toonCount = toonCount + 1
toonCache[toonCount] = toonCache[toonCount] or {}
toonCache[toonCount].class = self.LOOKUP_LOCALIZED_CLASS_NAMES[classLocalized] or "WARRIOR"
toonCache[toonCount].toonID = toonID
toonCache[toonCount].faction = faction
toonCache[toonCount].toonName = toonName
toonCache[toonCount].realmName = realmName
toonCache[toonCount].presenceID, toonCache[toonCount].presenceName = BNGetFriendInfo(friendIndex)
end
end
--[===[@debug@
if debug then
toonCount = 3
toonCache[1] = toonCache[1] or {}
toonCache[1].class = "DRUID"
toonCache[1].toonID = 0
toonCache[1].faction = "Alliance"
toonCache[1].toonName = "Areko"
toonCache[1].realmName = "Alleria"
toonCache[1].presenceName = "Areko#0000"
toonCache[1].presenceID = 0
toonCache[2] = toonCache[2] or {}
toonCache[2].class = "HUNTER"
toonCache[2].toonID = 0
toonCache[2].faction = "Alliance"
toonCache[2].toonName = "Tânuri"
toonCache[2].realmName = "Alleria"
toonCache[2].presenceName = "Tanuri#0000"
toonCache[2].presenceID = 0
toonCache[3] = toonCache[3] or {}
toonCache[3].class = "MAGE"
toonCache[3].toonID = 0
toonCache[3].faction = "Horde"
toonCache[3].toonName = "Keks"
toonCache[3].realmName = "Alleria"
toonCache[3].presenceName = "Keks#0000"
toonCache[3].presenceID = 0
end
--@end-debug@]===]
if toonCount > 0 then
if toonCount == 1 then
local toon = toonCache[1]
return self:InviteToon(toon.toonID, toon.toonName, toon.presenceName, toon.presenceID)
else
-- \124 > |
local linkTemplate = "[|H%s:%s|h%s|h]"
local colourTemplate = "|c%s%s|r"
local alliance
local horde
local colours = _G.CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS
for i=1,toonCount do
local toon = toonCache[i]
local linkData = toon.toonID..":"..toon.toonName..":"..toon.presenceName..":"..toon.presenceID
local name = self:UniformPlayerName(toon.toonName, toon.realmName)
local colour = colours[toon.class].colorStr or "FFFFFFFF"
--[===[@debug@
if debug then
linkData = linkData..":DEBUG"
end
--@end-debug@]===]
local msg = format(colourTemplate, colour, format(linkTemplate, self.TYPES.LINK, linkData, name) )
if toon.faction == "Horde" then
horde = horde and horde..", "..msg or msg
elseif toon.faction == "Alliance" then
alliance = alliance and alliance..", "..msg or msg
else
horde = horde and horde..", "..msg or msg
alliance = alliance and alliance..", "..msg or msg
end
end
local factionGroup = UnitFactionGroup("player")
self:Printf(L["%s is with more then one toon online. Choose which toons should be invited. Click on the name to invite."], toonCache[1].presenceName )
if factionGroup == "Alliance" then
if alliance then
self:Printf(L["Alliance toons: %s"], alliance )
end
if horde then
self:Printf(L["Horde toons: %s"], horde )
end
else
if horde then
self:Printf(L["Horde toons: %s"], horde )
end
if alliance then
self:Printf(L["Alliance toons: %s"], alliance )
end
end
return true, toonCount
end
else
local _, presenceName = BNGetFriendInfo(friendIndex)
self:Printf(L["%s is not online in World of Warcraft."], presenceName)
return false, 5
end
end
end
do-- InviteToon
local BNInviteFriend = BNInviteFriend
local battleNet_Throttle = {}
function WIC:InviteToon(toonID, toonName, presenceName, presenceID)
if not toonID then
return false, 3
end
if self:IsQueueProtected(toonName, presenceName, presenceID) or self:IsStatusProtected(toonName, presenceName, presenceID) then
return false, 7
elseif self:CheckGroupSize() then
local time = GetTime()
if (battleNet_Throttle[toonID] or 0) < time then
battleNet_Throttle[toonID] = time + self.db.profile.inviteThrottleTime
BNInviteFriend( toonID )
return true
else
return false, 6
end
else
self:Printf(L["Maximal group size reached. Can't invite %s"], format(L["%s (%s)"], presenceName or L["<No name given>"], toonName or L["<No toon name given>"]) )
return false, 4
end
end
end
--- Returns uniformed player or guild name
-- @paramsig playerName [, realmOverride]
-- @param (String) playerName/guildName
-- @param (String, optional) realmOverride
--
-- @return "Name-Realm", "Name", "Realm"
do
local homeRealm = GetRealmName()
local dash = "-"
function WIC:UniformPlayerName(playerName, realmOverride)
local name = playerName
local realm = homeRealm
if find(playerName, dash) then
name, realm = split(dash, playerName, 2)
end
realm = realmOverride or realm
return name..dash..realm, name, realm
end
function WIC:UniformGuildName(guildName, realmOverride)
-- same as player
return self:UniformPlayerName(guildName, realmOverride)
end
end
local optionHandler = {}
function optionHandler:Set(info, value, ...)
local name = info[#info]
WIC.db.profile[name] = value
end
function optionHandler:Get(info, value, ...)
local name = info[#info]
return WIC.db.profile[name]
end
function optionHandler:SetActive(info, value, ...)
self:Set(info, value, ...)
WIC:CheckEnabledState("", WIC.db)
end
function optionHandler:SetModule(info, value, ...)
self:Set(info, value, ...)
if WIC:IsEnabled() then
WIC:EnableSelectedModule()
end
end
function optionHandler:GetStatus(info, value, ...)
local name = info[#info]
return WIC.db.profile.statusProtection[info.arg][name]
end
local options = {
type = "group",
name = L["MoosePortal Core Settings"],
handler = optionHandler,
set = "Set",
get = "Get",
args = {
active = {
type = "toggle",
name = L["Active"],
desc = L["Is this profile enabled."],
width = "full",
set = "SetActive",
order = 1,
},
selectedModuleName = {
type = "select",
name = L["Active module"],
desc = L["Choose active module."],
values = WIC.RegisteredModulesTranslatedName,
set = "SetModule",
order = 2,
},
convertGroupToRaid = {
type = "toggle",
name = L["Auto convert"],
desc = L["Convert group to raid when group has reached maximal size."],
width = "full",
order = 3,
},
inviteThrottleTime = {
type = "range",
name = L["Invite Throttle"],
desc = L["Delay(seconds) needed between to invites of the same player before, MoosePortal can send a new invite."],
min = 0.5,
max = 120,
softMin = 5,
softMax = 30,
bigStep = 1,
step = 0.1,
--width = "full",
order = 4,
},
statusProtection = {
type = "group",
inline = true,
name = L["AFK/DND Protection"],
set = "SetStatus",
get = "GetStatus",
args = {
descriptionText = {
type = "description",
name = L["Choose when you don't want to automatic invite other players when you are AFK or DND.\nAnd if to send a message."],
fontSize = "normal",
order = 0,
},
AFK = {
type = "group",
name = DEFAULT_AFK_MESSAGE,
inline = true,
args = {
blockInvites = {
type = "toggle",
name = L["Block invites"],
desc = L["Block invites when you are AFK"],
arg = "AFK",
order = 1,
},
sendMessage = {
type = "toggle",
name = L["Send an answer"],
desc = L["Send a message to inform that you are AFK."],
arg = "AFK",
order = 2,
},
returnMessage = {
type = "input",
name = L["Answer"],
desc = L["The message you will send."],
width = "full",
arg = "AFK",
order = 3,
},
},
},
DND = {
type = "group",
name = DEFAULT_DND_MESSAGE,
inline = true,
args = {
blockInvites = {
type = "toggle",
name = L["Block invites"],
desc = L["Block invites when you are DND"],
arg = "DND",
order = 1,
},
sendMessage = {
type = "toggle",
name = L["Send an answer"],
desc = L["Send a message to inform that you are DND."],
arg = "DND",
order = 2,
},
returnMessage = {
type = "input",
name = L["Answer"],
desc = L["The message you will send."],
width = "full",
arg = "DND",
order = 3,
},
},
},
},
},
},
}
local updateConfig
do-- updateConfig
local LFG_CATEGORY_NAMES, QUEUED_STATUS_UNKNOWN, PVP =
LFG_CATEGORY_NAMES, QUEUED_STATUS_UNKNOWN, PVP
function updateConfig()
for id in pairs(WIC.db.profile.queueProtection) do
local name
if type(id) == "number" then
name = LFG_CATEGORY_NAMES[id] or QUEUED_STATUS_UNKNOWN
else
name = PVP
end
end
end
end
local configIsRegistered = false
local unregisteredConfigs = {}
function WIC:RegisterConfig()
updateConfig()
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable(ADDONNAME.."Options", options)
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(ADDONNAME.."Options", ADDONNAME)
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable(ADDONNAME.."Profile", LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db) )
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(ADDONNAME.."Profile", L["Profile"], ADDONNAME)
configIsRegistered = true
for appName, name in pairs(unregisteredConfigs) do
self:AddModuleConfig(appName, name)
end
wipe(unregisteredConfigs)
end
--- Use to register your DB as namespace of the core DB
-- @param (String) name
-- @param (table) defaults
function WIC:RegisterNamespace(name, namespaceDefaults)
if type(namespaceDefaults) ~= "table" then
namespaceDefaults = nil
end
return self.db:RegisterNamespace(name, namespaceDefaults)
end
--- Add your config to BlizzOptions as child of MoosePortal
-- @param (String) appName - same as used in AceConfigRegistry:RegisterOptionsTable()
-- @param (String) name - Display name
function WIC:AddModuleConfig(appName, name)
if configIsRegistered then
if appName and LibStub("AceConfigRegistry-3.0"):GetOptionsTable(appName) then
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(appName, name or appName, ADDONNAME)
return true
else
return false
end
else
unregisteredConfigs[appName] = name or appName
end
end
function WIC:NotifyChange()
LibStub("AceConfigRegistry-3.0"):NotifyChange(ADDONNAME.."Options")
end