-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathITTsRosterBot.lua
684 lines (571 loc) · 25.7 KB
/
ITTsRosterBot.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
ITTsRosterBot = ZO_CallbackObject:New()
ITTsRosterBot.name = "ITTsRosterBot"
local db = {}
ITTsRosterBot.db = db
local logger = LibDebugLogger( ITTsRosterBot.name )
-- local LH = LibHistoire
logger:SetEnabled( false )
local chat = LibChatMessage( "ITTsRosterBot", "ITTs-RB" )
local SECONDS_IN_HOUR = 60 * 60
local SECONDS_IN_DAY = SECONDS_IN_HOUR * 24
local SECONDS_IN_WEEK = SECONDS_IN_DAY * 7
local defaults = {
settings = {
guilds = {
{ name = "Guild Slot #1", id = 0, disabled = true, selected = false },
{ name = "Guild Slot #2", id = 0, disabled = true, selected = false },
{ name = "Guild Slot #3", id = 0, disabled = true, selected = false },
{ name = "Guild Slot #4", id = 0, disabled = true, selected = false },
{ name = "Guild Slot #5", id = 0, disabled = true, selected = false }
},
guildsCache = {
{ name = "Guild Slot #1", id = 0, disabled = true, selected = false },
{ name = "Guild Slot #2", id = 0, disabled = true, selected = false },
{ name = "Guild Slot #3", id = 0, disabled = true, selected = false },
{ name = "Guild Slot #4", id = 0, disabled = true, selected = false },
{ name = "Guild Slot #5", id = 0, disabled = true, selected = false }
},
services = {
sales = "MM3"
},
historyHighlighting = true,
applications = {
applicationAttachment = true,
sales = 14,
rankIcon = true,
donations = true,
guildName = true
}
},
newcomer = 7,
oldNumber = 180,
UI = {
history = {
item = true,
gold = true
}
},
timeFrameIndex = 4
}
local worldName = GetWorldName()
-- --------------------
-- Application Append
-- --------------------
local function GetApplicationAppendage( guildId, displayName )
local memberInfo = ITTsRosterBot.Utils:GetRelatedGuildInfo( displayName )
--/esoui/art/miscellaneous/wide_divider_left.dds
local guildName = ""
local rankIconString = "x"
--logger:Debug( #memberInfo )
local text = ""
local salesString = ""
local sales = 0
local donations = 0
local donationString = ""
local t1 = {}
local divider = "" -- "|t500:5:/esoui/art/charactercreate/windowdivider.dds|t
for i = 1, #memberInfo do
local timeframe = ITTsRosterBot.db.settings.applications.sales
donations = ITTsDonationBot:QueryValues( memberInfo[ i ].guildId, displayName,
GetTimeStamp() - (timeframe * SECONDS_IN_DAY),
GetTimeStamp() )
if ITTsRosterBot.SalesAdapter:Selected() ~= nil then
sales = ITTsRosterBot.SalesAdapter:GetSaleInformation( memberInfo[ i ].guildId, displayName,
GetTimeStamp() - (timeframe * SECONDS_IN_DAY),
GetTimeStamp() ).sales
end
if ITTsRosterBot.db.settings.applications.guildName == true then
guildName = GetGuildName( memberInfo[ i ].guildId )
end
if ITTsRosterBot.db.settings.applications.rankIcon == true then
rankIconString = memberInfo[ i ].rankIconString
end
if ITTsRosterBot.db.settings.applications.sales > 0 then
salesString = "|r\n\t\t\t\t\t\t\tSales: " ..
ZO_CommaDelimitNumber( sales ) .. " |t20:20:EsoUI/Art/currency/currency_gold.dds|t"
end
if ITTsRosterBot.db.settings.applications.donations == true then
donationString = "|r\n\t\t\t\t\t\t\tDonations: " ..
ZO_CommaDelimitNumber( donations ) .. " |t20:20:EsoUI/Art/currency/currency_gold.dds|t"
end
-- logger:Warn( rankIconString )
t1[ i ] = "|c" ..
memberInfo[ i ].guildColor ..
rankIconString ..
guildName ..
salesString ..
donationString
-- text = text .. "|c" .. memberInfo[ i ].guildColor .. memberInfo[ i ].guildName .. memberInfo[ i ].rankIconString
end
if ITTsRosterBot.db.settings.applications.applicationAttachment == true then
text = table.concat( t1, "\n|t200:10:/esoui/art/miscellaneous/wide_divider_left.dds|t\n" )
end
-- logger:Debug( text )
-- local relatedGuilds = ITTsRosterBot:BuildRelatedGuilds( displayName, GetGuildName(GUILD_ROSTER_MANAGER.guildId) )
local relatedGuilds, test = ITTsRosterBot.Utils:BuildInlineRelatedGuilds( displayName, guildId )
--logger:Warn( test )
if relatedGuilds ~= "" then
text = "\n|C4bc8ebRelated Guilds:|C999999 \n" .. text
end
return text
end
function ZO_GuildRecruitment_ApplicationsList_Row_OnMouseEnter( control )
GUILD_RECRUITMENT_APPLICATIONS_KEYBOARD:GetSubcategoryManager(
ZO_GUILD_RECRUITMENT_APPLICATIONS_SUBCATEGORY_KEYBOARD_RECEIVED ):Row_OnMouseEnter( control )
local originalMessage = GUILD_FINDER_MANAGER.applicationKeyboardTooltipInfo.messageControl:GetText()
local guildId = GUILD_ROSTER_MANAGER.guildId
local displayName = control:GetNamedChild( "Name" ):GetText()
local text = GetApplicationAppendage( guildId, displayName )
GUILD_FINDER_MANAGER.applicationKeyboardTooltipInfo.messageControl:SetText( originalMessage .. text )
end
-- --------------------
-- Event Callbacks
-- --------------------
local function OnPlayerActivated( eventCode )
EVENT_MANAGER:UnregisterForEvent( ITTsRosterBot.name, eventCode )
ITTsRosterBot:Initialize()
end
local function OnHistoryResponseReceived( ev, guildId, category )
if category == GUILD_HISTORY_GENERAL and ITTsRosterBot:IsGuildEnabled( guildId ) then
ITTsRosterBot:RunScanCycle( guildId )
end
-- logger:Info('---------------------------------')
end
local function ITTsRosterBot_OnAddOnLoaded( eventCode, addOnName )
if addOnName == ITTsRosterBot.name then
logger:Info( "ITTsRosterBot_OnAddOnLoaded" )
db = ZO_SavedVars:NewAccountWide( "ITTsRosterBotSettings", 2, nil, defaults )
ITTsRosterBot.db = db
--MyChatHandlersMessageChannelFormatter()
EVENT_MANAGER:UnregisterForEvent( ITTsRosterBot.name, eventCode )
end
end
-- --------------------
-- Methods
-- --------------------
function ITTsRosterBot:Initialize()
logger:Info( "ITTsRosterBot:Initialize()", self.name )
EVENT_MANAGER:RegisterForEvent( ITTsRosterBot.name, EVENT_GUILD_HISTORY_RESPONSE_RECEIVED, OnHistoryResponseReceived )
EVENT_MANAGER:RegisterForEvent(
ITTsRosterBot.name,
EVENT_GUILD_SELF_JOINED_GUILD,
function( _, _, newGuildId )
logger:Info( "EVENT_GUILD_SELF_JOINED_GUILD" )
ITTsRosterBot:CheckGuildPermissions( newGuildId )
end
)
EVENT_MANAGER:RegisterForEvent(
ITTsRosterBot.name,
EVENT_GUILD_SELF_LEFT_GUILD,
function()
logger:Info( "EVENT_GUILD_SELF_LEFT_GUILD" )
ITTsRosterBot:CheckGuildPermissions()
end
)
self.memberCache = {}
self.SalesAdapter:Initialize()
self.Settings:Initialize()
self:CheckGuildPermissions()
self:RequestAllHistory()
self.Utils:CacheMembers()
self.UI:Setup()
-- self:CreateStatusBox()
GUILD_ROSTER_KEYBOARD.DisplayName_OnMouseEnter = function( self, control )
local row = control:GetParent()
local data = ZO_ScrollList_GetData( row )
local timeString = nil
local joinString = nil
local importString = nil
local text = ""
local color = "FFFFFF"
if ITTsRosterBotData[ worldName ].guilds[ GUILD_ROSTER_MANAGER.guildId ].join_records and
ITTsRosterBotData[ worldName ].guilds[ GUILD_ROSTER_MANAGER.guildId ].join_records[ data.displayName ] and
ITTsRosterBotData[ worldName ].guilds[ GUILD_ROSTER_MANAGER.guildId ].join_records[ data.displayName ].first
then
local joinedFirst = ITTsRosterBotData[ worldName ].guilds[ GUILD_ROSTER_MANAGER.guildId ].join_records[
data.displayName ].first
local formatedTime = os.date( "*t", joinedFirst )
local hour = formatedTime.hour
local min = formatedTime.min
if hour < 10 then
hour = "0" .. tostring( hour )
end
if min < 10 then
min = "0" .. tostring( min )
end
timeString =
"|cF49B22Joined first: |C" ..
color ..
ZO_FormatDurationAgo( (GetTimeStamp() - joinedFirst) ) ..
" |c858585( " .. formatedTime.day .. "/" .. formatedTime.month .. "/" .. formatedTime.year .. " )" .. "\n"
end
if ITTsRosterBotData[ worldName ].guilds[ GUILD_ROSTER_MANAGER.guildId ].join_records and
ITTsRosterBotData[ worldName ].guilds[ GUILD_ROSTER_MANAGER.guildId ].join_records[ data.displayName ] and
ITTsRosterBotData[ worldName ].guilds[ GUILD_ROSTER_MANAGER.guildId ].join_records[ data.displayName ].last
then
local joinedLast = ITTsRosterBotData[ worldName ].guilds[ GUILD_ROSTER_MANAGER.guildId ].join_records[
data.displayName ].last
local formatedTime = os.date( "*t", joinedLast )
local hour = formatedTime.hour
local min = formatedTime.min
local newcomer = ITTsRosterBot.db.newcomer * 86400 -- seconds in day
local oldNumber = ITTsRosterBot.db.oldNumber * 86400
if GetTimeStamp() - joinedLast < newcomer then
color = "FA5858"
end
if GetTimeStamp() - joinedLast > oldNumber then
color = "A9F5A9"
end
if hour < 10 then
hour = "0" .. tostring( hour )
end
if min < 10 then
min = "0" .. tostring( min )
end
joinString =
"|c00FFBFLatest join: |C" ..
color ..
ZO_FormatDurationAgo( (GetTimeStamp() - joinedLast) ) ..
" |c858585( " .. formatedTime.day .. "/" .. formatedTime.month .. "/" .. formatedTime.year .. " )" .. "\n"
end
if ITTsRosterBotData[ worldName ].guilds[ GUILD_ROSTER_MANAGER.guildId ].join_records and
ITTsRosterBotData[ worldName ].guilds[ GUILD_ROSTER_MANAGER.guildId ].join_records[ data.displayName ] and
ITTsRosterBotData[ worldName ].guilds[ GUILD_ROSTER_MANAGER.guildId ].join_records[ data.displayName ].import
then
local import = ITTsRosterBotData[ worldName ].guilds[ GUILD_ROSTER_MANAGER.guildId ].join_records
[ data.displayName ].import
local formatedTime = os.date( "*t", import )
local hour = formatedTime.hour
local min = formatedTime.min
if hour < 10 then
hour = "0" .. tostring( hour )
end
if min < 10 then
min = "0" .. tostring( min )
end
importString =
"|c00FFB2Imported: |CFFFFFF" ..
ZO_FormatDurationAgo( (GetTimeStamp() - import) ) ..
" |c858585( " .. formatedTime.day .. "/" .. formatedTime.month .. "/" .. formatedTime.year .. " )" .. "\n"
end
if timeString ~= nil then
text = timeString
end
if joinString ~= nil then
text = joinString
end
if importString ~= nil then
text = importString
end
if timeString ~= nil and joinString ~= nil then
text = timeString .. joinString
end
if importString ~= nil and joinString ~= nil then
text = importString .. joinString
end
if timeString ~= nil and importString ~= nil then
text = timeString .. importString
end
if timeString ~= nil and joinString ~= nil and importString ~= nil then
if timeString == joinString then
return
elseif timeString == importString then
return
elseif joinString == importString then
return
else
text = timeString .. joinString .. importString
end
end
local relatedGuilds = ITTsRosterBot.Utils:BuildInlineRelatedGuilds( data.displayName, GUILD_ROSTER_MANAGER.guildId )
if data.displayName ~= GetDisplayName() and relatedGuilds ~= "" then
text = text .. "|C4bc8ebRelated Guilds:|C999999 " .. relatedGuilds .. "\n"
end
text = text .. "|C0095bfCharacter: |C999999" .. ZO_FormatUserFacingCharacterName( data.characterName )
if (text ~= "") then
InitializeTooltip( InformationTooltip )
SetTooltipText( InformationTooltip, text )
InformationTooltip:ClearAnchors()
InformationTooltip:SetAnchor( BOTTOM, control, TOPLEFT, control:GetTextDimensions() * 0.5, 0 )
end
self:EnterRow( row )
end
end
function ITTsRosterBot:SelectSalesService( choice )
if choice ~= "None" then
for k, v in pairs( ITTsRosterBot.SalesAdapter.adapters ) do
logger:Info( choice )
if ITTsRosterBot.SalesAdapter.adapters[ k ].settingsLabel == choice then
choice = ITTsRosterBot.SalesAdapter.adapters[ k ].name
if ITTsRosterBot.SalesAdapter.adapters[ k ]:Available() then
ITTsRosterBot.SalesAdapter.adapters[ k ]:ShowUI()
ITTsRosterBot.UI:ConfigureDropdown()
ITTsRosterBot.UI:CheckServiceStatus()
end
end
end
end
ITTsRosterBot.db.settings.services.sales = choice
if ITTsRosterBot.db.settings.services.sales ~= "None" then
ITTsRosterBot_SalesTotalTitle:SetText(
"|t20:20:EsoUI/Art/Guild/guild_tradingHouseAccess.dds|t SALES |c66ffc2[ " ..
ITTsRosterBot.db.settings.services.sales .. " ]"
)
else
ITTsRosterBot_SalesTotalTitle:SetText( "|t20:20:EsoUI/Art/Guild/guild_tradingHouseAccess.dds|t SALES" )
end
end
function ITTsRosterBot:CacheMembers()
for i = 1, GetNumGuilds() do
local guildId = GetGuildId( i )
local gname = GetGuildName( guildId )
local total = GetNumGuildMembers( guildId )
if gname ~= "" then
for l = 1, total do
local displayName, _, _, _, _ = GetGuildMemberInfo( guildId, l )
if self.memberCache[ displayName ] == nil then
self.memberCache[ displayName ] = {}
end
table.insert( self.memberCache[ displayName ], gname )
end
end
end
end
function ITTsRosterBot:CreateStatusBox()
local statusBox = WINDOW_MANAGER:CreateControl( "ITT_StatusBox", ZO_ChatWindow, CT_LABEL )
statusBox:SetFont( "$(MEDIUM_FONT)|$(KB_16)|soft-shadow-thin" )
statusBox:SetText(
"|t42:42:esoui/art/tutorial/guild-tabicon_roster_up.dds|t |C277fa8Writing guild notes ( |C38cff548|C277fa8 / 118 ) ~ 27 mins |t18:18:esoui/art/buttons/decline_up.dds|t"
)
statusBox:SetDimensions( ZO_ChatWindow:GetWidth(), 48 )
statusBox:SetHorizontalAlignment( 0 )
statusBox:SetVerticalAlignment( 1 )
statusBox:SetAnchor( BOTTOM, ZO_ChatWindow, TOP, 0, -50 )
local statusBoxBG = WINDOW_MANAGER:CreateControl( "ITT_StatusBoxBG", statusBox, CT_BACKDROP )
statusBoxBG:SetDimensions( statusBox:GetWidth(), statusBox:GetHeight() )
statusBoxBG:SetAnchor( CENTER, statusBox, CENTER, 0, 0 )
statusBoxBG:SetAlpha( 0.7 )
statusBoxBG:SetCenterColor( ZO_ColorDef:New( 0, 0, 0, 1 ):UnpackRGBA() )
statusBoxBG:SetEdgeColor( ZO_ColorDef:New( 0, 0, 0, 0 ):UnpackRGBA() )
end
function ITTsRosterBot:BuildRelatedGuilds( displayName, currentGuild )
local guilds = self.memberCache[ displayName ]
local gtext = ""
if guilds ~= nil then
for k, v in pairs( guilds ) do
if currentGuild ~= nil and v == currentGuild then
else
if gtext ~= "" then
gtext = gtext .. ", "
end
gtext = gtext .. v
end
end
if gtext ~= "" then
gtext = gtext .. "."
end
end
return gtext
end
function ITTsRosterBot:CheckGuildPermissions( newGuildId )
logger:Info( "ITTsRosterBot:CheckGuildPermissions()" )
for i = 1, 5 do
local guildId = GetGuildId( i )
logger:Info( "-----" )
logger:Info( "Guild #" .. tostring( i ) .. " ", GetGuildName( guildId ), guildId )
local control = _G[ "ITTsRosterBotSettingsGuild" .. tostring( i ) ]
if guildId > 0 then
-- end
local guildName = GetGuildName( guildId )
local cachedSetting = ITTsRosterBot.db.settings.guilds[ i ].selected
if guildId ~= ITTsRosterBot.db.settings.guildsCache[ i ].id then
logger:Info( "#" .. tostring( i ) .. " is a mis-match" )
for inc = 1, 5 do
logger:Info(
"CACHE CHECK for slot #" .. tostring( i ) .. " - [" .. tostring( inc ) .. "]",
ITTsRosterBot.db.settings.guildsCache[ inc ].id,
guildId,
ITTsRosterBot.db.settings.guildsCache[ inc ].id == guildId
)
if ITTsRosterBot.db.settings.guildsCache[ inc ].id == guildId then
cachedSetting = ITTsRosterBot.db.settings.guildsCache[ inc ].selected
logger:Info( "The previous value was", cachedSetting )
end
end
end
ITTsRosterBot.db.settings.guilds[ i ].name = guildName
ITTsRosterBot.db.settings.guilds[ i ].id = guildId
if newGuildId and ITTsRosterBot.db.settings.guilds[ i ].id == newGuildId then
ITTsRosterBot.db.settings.guilds[ i ].selected = true
ITTsRosterBot.db.settings.guilds[ i ].disabled = false
elseif "Guild Slot #" .. tostring( i ) == ITTsRosterBot.db.settings.guildsCache[ i ].name then
ITTsRosterBot.db.settings.guilds[ i ].selected = true
ITTsRosterBot.db.settings.guilds[ i ].disabled = false
end
-- else
-- ITTsRosterBot.db.settings.guilds[i].selected = false
ITTsRosterBot.db.settings.guilds[ i ].disabled = false
else
ITTsRosterBot.db.settings.guilds[ i ].name = "Guild Slot #" .. tostring( i )
ITTsRosterBot.db.settings.guilds[ i ].id = 0
ITTsRosterBot.db.settings.guilds[ i ].disabled = true
ITTsRosterBot.db.settings.guilds[ i ].selected = false
end
if control then
control.label:SetText( ITTsRosterBot.db.settings.guilds[ i ].name )
control:UpdateValue()
-- control.UpdateDisabled()
end
end
ZO_DeepTableCopy( ITTsRosterBot.db.settings.guilds, ITTsRosterBot.db.settings.guildsCache )
end
function ITTsRosterBot:SaveEvent( guildId, eventIndex )
local timeStamp = GetTimeStamp()
local eventType, secsSinceEvent, displayName, amount, arg1, _, _, _, id = GetGuildEventInfo( guildId,
GUILD_HISTORY_GENERAL,
eventIndex )
-- logger:Info(eventIndex, eventType)
if eventType == GUILD_EVENT_GUILD_JOIN and secsSinceEvent >= 0 then
local eventTimestamp = timeStamp - secsSinceEvent
if eventTimestamp < 0 then
eventTimestamp = timeStamp
end
local eventId = GetGuildEventId( guildId, category, eventIndex )
logger:Info( "ITTsRosterBot:SaveEvent()", "#" .. tostring( eventIndex ), displayName, eventTimestamp, id )
if not ITTsRosterBotData[ worldName ].guilds[ guildId ].join_records[ displayName ] then
ITTsRosterBotData[ worldName ].guilds[ guildId ].join_records[ displayName ] = {}
ITTsRosterBotData[ worldName ].guilds[ guildId ].join_records[ displayName ].last = eventTimestamp
end
if ITTsRosterBotData[ worldName ].guilds[ guildId ].join_records[ displayName ].last ~= nil then
if eventTimestamp < ITTsRosterBotData[ worldName ].guilds[ guildId ].join_records[ displayName ].last - 86400 then
ITTsRosterBotData[ worldName ].guilds[ guildId ].join_records[ displayName ].first = eventTimestamp
else
ITTsRosterBotData[ worldName ].guilds[ guildId ].join_records[ displayName ].last = eventTimestamp
end
end
end
end
function ITTsRosterBot:RunScanCycle( guildId, forceIndex )
self.scanHistory = self.scanHistory or {}
local start = self.scanHistory[ guildId ] or 1
local numGuildEvents = GetNumGuildEvents( guildId, GUILD_HISTORY_GENERAL_ROSTER )
if forceIndex then
start = 1
end
logger:Info( "start:", start )
logger:Info( "scanHistory:", self.scanHistory[ guildId ] )
for index = start, numGuildEvents do
self:SaveEvent( guildId, index )
end
self.scanHistory[ guildId ] = numGuildEvents + 1
end
function ITTsRosterBot:GetGuildMap()
local guilds = {}
for i = 1, GetNumGuilds() do
local guildId = GetGuildId( i )
if ITTsRosterBot.db.settings.guilds[ i ].selected and not ITTsRosterBot.db.settings.guilds[ i ].disabled then
guilds[ #guilds + 1 ] = ITTsRosterBot.db.settings.guilds[ i ].id
if not ITTsRosterBotData then
ITTsRosterBotData = {}
end
if not ITTsRosterBotData[ worldName ] then
ITTsRosterBotData[ worldName ] = {}
end
if not ITTsRosterBotData[ worldName ].guilds then
ITTsRosterBotData[ worldName ].guilds = {}
end
if not ITTsRosterBotData[ worldName ].guilds[ guildId ] then
ITTsRosterBotData[ worldName ].guilds[ guildId ] = {}
end
if not ITTsRosterBotData[ worldName ].guilds[ guildId ].join_records then
ITTsRosterBotData[ worldName ].guilds[ guildId ].join_records = {}
end
end
end
return guilds
end
function ITTsRosterBot:IsGuildEnabled( guildId )
local list = self:GetGuildMap()
local condition = false
for i = 1, #list do
if guildId == list[ i ] then
condition = true
break
end
end
return condition
end
function ITTsRosterBot:RequestAllHistory()
for _, guildId in pairs( self:GetGuildMap() ) do
self:RequestHistory( guildId, GUILD_HISTORY_GENERAL )
end
end
function ITTsRosterBot:RequestHistory( gID, guildHistoryCategory )
local cooldown = 1000 * 60
logger:Info( "ITTsRosterBot:RequestHistory() running -", GetGuildName( gID ) .. "-" .. guildHistoryCategory )
if DoesGuildHistoryCategoryHaveOutstandingRequest( gID, guildHistoryCategory ) == false and
IsGuildHistoryCategoryRequestQueued( gID, guildHistoryCategory ) == false
then
if DoesGuildHistoryCategoryHaveMoreEvents( gID, guildHistoryCategory ) then
logger:Info( "More history exists for ", GetGuildName( gID ) .. "-" .. guildHistoryCategory )
if RequestMoreGuildHistoryCategoryEvents( gID, guildHistoryCategory ) then
logger:Info( "Requesting Guild History:", GetGuildName( gID ) .. "-" .. guildHistoryCategory )
zo_callLater(
function()
ITTsRosterBot:RequestHistory( gID, guildHistoryCategory )
end,
cooldown
)
else
logger:Info(
"Request cooldown for ",
GetGuildName( gID ) .. "-" .. guildHistoryCategory,
" has not expired yet, re-calling in a few minutes"
)
zo_callLater(
function()
ITTsRosterBot:RequestHistory( gID, guildHistoryCategory )
end,
cooldown
)
end
else
logger:Info( "No more history exists for ", GetGuildName( gID ) .. "-" .. guildHistoryCategory )
logger:Info( "Total:", GetNumGuildEvents( gID, guildHistoryCategory ) )
if GetNumGuildEvents( gID, guildHistoryCategory ) > 0 and
ITTsRosterBotData[ worldName ].guilds[ gID ].join_records == nil then -- ITTsRosterBotData[worldName].guilds[guildId].join_records
self:RunScanCycle( gID, 1 )
end
end
else
logger:Info( "Scan requirements not met: Trying again in 1m" )
zo_callLater(
function()
ITTsRosterBot:RequestHistory( gID, guildHistoryCategory )
end,
cooldown
)
end
end
function ITTsRosterBot:GetTimestampOfDayStart( offset )
local timeObject = os.date( "*t", os.time() - (24 * offset) * 60 * 60 )
local hours = timeObject.hour
local mins = timeObject.min
local secs = timeObject.sec
local UTCMidnightOffset = (hours * SECONDS_IN_HOUR) + (mins * 60) + secs
local recordTimestamp = os.time( timeObject )
return recordTimestamp - UTCMidnightOffset
end
function ITTsRosterBot:GetTraderWeekEnd()
local _, time, _ = GetGuildKioskCycleTimes()
return time
end
function ITTsRosterBot:GetTraderWeekStart()
local time = self:GetTraderWeekEnd()
return time - SECONDS_IN_WEEK
end
-- --------------------
-- Attach Listeners
-- --------------------
EVENT_MANAGER:RegisterForEvent( ITTsRosterBot.name, EVENT_ADD_ON_LOADED, ITTsRosterBot_OnAddOnLoaded )
EVENT_MANAGER:RegisterForEvent( ITTsRosterBot.name, EVENT_PLAYER_ACTIVATED, OnPlayerActivated )