@@ -124,9 +124,7 @@ export default class Autokeys {
124
124
125
125
check ( ) : void {
126
126
log . debug ( `checking autokeys (Enabled: ${ String ( this . isEnabled ) } )` ) ;
127
- if ( this . isEnabled === false ) {
128
- return ;
129
- }
127
+ if ( this . isEnabled === false ) return ;
130
128
131
129
const userPure = this . userPure ;
132
130
@@ -319,7 +317,6 @@ export default class Autokeys {
319
317
if ( setMaxKeys === currKeys ) {
320
318
setMaxKeys += 1 ;
321
319
}
322
-
323
320
if ( currKeys >= setMaxKeys ) {
324
321
setMaxKeys = currKeys + 1 ;
325
322
}
@@ -354,152 +351,107 @@ export default class Autokeys {
354
351
rKeysCanSell !== this . oldAmount . keysCanSell ||
355
352
currKeys !== this . oldAmount . ofKeys ) ;
356
353
357
- if ( this . isActive ) {
358
- // if Autokeys already running
354
+ const alertLowPure = ( ) => {
355
+ const msg = 'I am now low on both keys and refs.' ;
356
+ if ( opt . sendAlert . enable && opt . sendAlert . autokeys . lowPure ) {
357
+ if ( opt . discordWebhook . sendAlert . enable && opt . discordWebhook . sendAlert . url . main !== '' )
358
+ sendAlert ( 'lowPure' , this . bot , msg ) ;
359
+ else this . bot . messageAdmins ( msg , [ ] ) ;
360
+ }
361
+ } ;
362
+
363
+ const common1 = ( ) => {
364
+ this . setOverallStatus = [ false , true , false , true , false , false ] ;
365
+ this . setOldAmount = [ 0 , 0 , rKeysCanBankMin , rKeysCanBankMax , currKeys ] ;
366
+ this . setActiveStatus = true ;
367
+ } ;
368
+
369
+ const common2 = ( ) => {
370
+ this . setOverallStatus = [ true , false , false , false , true , false ] ;
371
+ this . setOldAmount = [ 0 , rKeysCanBankMax , 0 , 0 , currKeys ] ;
372
+ this . setActiveStatus = true ;
373
+ } ;
374
+
375
+ const common3 = ( ) => {
376
+ this . setOverallStatus = [ true , false , false , false , true , false ] ;
377
+ this . setOldAmount = [ 0 , rKeysCanBuy , 0 , 0 , currKeys ] ;
378
+ this . setActiveStatus = true ;
379
+ } ;
380
+
381
+ const common4 = ( ) => {
382
+ this . setOverallStatus = [ false , false , false , false , false , true ] ;
383
+ this . setOldAmount = [ rKeysCanSell , 0 , 0 , 0 , currKeys ] ;
384
+ this . setActiveStatus = true ;
385
+ } ;
386
+
387
+ const common5 = ( ) => {
388
+ this . setOverallStatus = [ false , false , true , false , false , false ] ;
389
+ this . setActiveStatus = false ;
390
+ alertLowPure ( ) ;
391
+ } ;
392
+
393
+ const isNotInPricelist = this . bot . pricelist . getPrice ( { priceKey : '5021;6' , onlyEnabled : false } ) === null ;
394
+
395
+ if ( this . isActive || ( ! this . isActive && ! isNotInPricelist ) ) {
396
+ // if Autokeys already running OR Not running and exist in pricelist
359
397
if ( isBanking ) {
360
398
// enable keys banking - if banking conditions to enable banking matched and banking is enabled
361
- this . setOverallStatus = [ false , true , false , true , false , false ] ;
362
- this . setOldAmount = [ 0 , 0 , rKeysCanBankMin , rKeysCanBankMax , currKeys ] ;
363
- this . setActiveStatus = true ;
399
+ common1 ( ) ;
364
400
this . updateToBank ( setMinKeys , setMaxKeys , currKeyPrice ) ;
365
401
//
366
402
} else if ( isTooManyRefWhileBanking ) {
367
403
// enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys.
368
- this . setOverallStatus = [ true , false , false , false , true , false ] ;
369
- this . setOldAmount = [ 0 , rKeysCanBankMax , 0 , 0 , currKeys ] ;
370
- this . setActiveStatus = true ;
404
+ common2 ( ) ;
371
405
this . update ( setMinKeys , setMaxKeys , currKeyPrice , 'buy' ) ;
372
406
//
373
407
} else if ( buyKeys ) {
374
408
// enable Autokeys - Buying - if buying keys conditions matched
375
- this . setOverallStatus = [ true , false , false , false , true , false ] ;
376
- this . setOldAmount = [ 0 , rKeysCanBuy , 0 , 0 , currKeys ] ;
377
- this . setActiveStatus = true ;
409
+ common3 ( ) ;
378
410
this . update ( setMinKeys , setMaxKeys , currKeyPrice , 'buy' ) ;
379
411
//
380
412
} else if ( sellKeys ) {
381
413
// enable Autokeys - Selling - if selling keys conditions matched
382
- this . setOverallStatus = [ false , false , false , false , false , true ] ;
383
- this . setOldAmount = [ rKeysCanSell , 0 , 0 , 0 , currKeys ] ;
384
- this . setActiveStatus = true ;
414
+ common4 ( ) ;
385
415
this . update ( setMinKeys , setMaxKeys , currKeyPrice , 'sell' ) ;
386
416
//
387
- } else if ( isRemoveBankingKeys && isEnableKeyBanking ) {
417
+ } else if (
418
+ this . isActive &&
419
+ ( ( isRemoveBankingKeys && isEnableKeyBanking ) || ( isRemoveAutoKeys && ! isEnableKeyBanking ) )
420
+ ) {
388
421
// disable keys banking - if to conditions to disable banking matched and banking is enabled
389
422
this . setOverallStatus = [ false , false , false , false , false , false ] ;
390
423
this . setActiveStatus = false ;
391
424
void this . disable ( currKeyPrice ) ;
392
425
//
393
- } else if ( isRemoveAutoKeys && ! isEnableKeyBanking ) {
394
- // disable Autokeys when conditions to disable Autokeys matched
395
- this . setOverallStatus = [ false , false , false , false , false , false ] ;
396
- this . setActiveStatus = false ;
397
- void this . disable ( currKeyPrice ) ;
398
- //
399
426
} else if ( isAlertAdmins && ! this . status . checkAlertOnLowPure ) {
400
427
// alert admins when low pure
401
- this . setOverallStatus = [ false , false , true , false , false , false ] ;
402
- this . setActiveStatus = false ;
403
-
404
- const msg = 'I am now low on both keys and refs.' ;
405
- if ( opt . sendAlert . enable && opt . sendAlert . autokeys . lowPure ) {
406
- if ( opt . discordWebhook . sendAlert . enable && opt . discordWebhook . sendAlert . url . main !== '' ) {
407
- sendAlert ( 'lowPure' , this . bot , msg ) ;
408
- } else {
409
- this . bot . messageAdmins ( msg , [ ] ) ;
410
- }
411
- }
428
+ common5 ( ) ;
412
429
}
413
- } else {
414
- // if Autokeys is not running/disabled
415
- if ( this . bot . pricelist . getPrice ( { priceKey : '5021;6' , onlyEnabled : false } ) === null ) {
416
- // if Mann Co. Supply Crate Key entry does not exist in the pricelist.json
417
- if ( isBankingKeys && isEnableKeyBanking ) {
418
- //create new Key entry and enable keys banking - if banking conditions to enable banking matched and banking is enabled
419
- this . setOverallStatus = [ false , true , false , true , false , false ] ;
420
- this . setOldAmount = [ 0 , 0 , rKeysCanBankMin , rKeysCanBankMax , currKeys ] ;
421
- this . setActiveStatus = true ;
422
- this . createToBank ( setMinKeys , setMaxKeys , currKeyPrice ) ;
423
- //
424
- } else if ( isBankingBuyKeysWithEnoughRefs && isEnableKeyBanking ) {
425
- // enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys.
426
- this . setOverallStatus = [ true , false , false , false , true , false ] ;
427
- this . setOldAmount = [ 0 , rKeysCanBankMax , 0 , 0 , currKeys ] ;
428
- this . setActiveStatus = true ;
429
- this . create ( setMinKeys , setMaxKeys , currKeyPrice , 'buy' ) ;
430
- //
431
- } else if ( isBuyingKeys ) {
432
- // create new Key entry and enable Autokeys - Buying - if buying keys conditions matched
433
- this . setOverallStatus = [ true , false , false , false , true , false ] ;
434
- this . setOldAmount = [ 0 , rKeysCanBuy , 0 , 0 , currKeys ] ;
435
- this . setActiveStatus = true ;
436
- this . create ( setMinKeys , setMaxKeys , currKeyPrice , 'buy' ) ;
437
- //
438
- } else if ( isSellingKeys ) {
439
- // create new Key entry and enable Autokeys - Selling - if selling keys conditions matched
440
- this . setOverallStatus = [ false , false , false , false , false , true ] ;
441
- this . setOldAmount = [ rKeysCanSell , 0 , 0 , 0 , currKeys ] ;
442
- this . setActiveStatus = true ;
443
- this . create ( setMinKeys , setMaxKeys , currKeyPrice , 'sell' ) ;
444
- //
445
- } else if ( isAlertAdmins && ! this . status . checkAlertOnLowPure ) {
446
- // alert admins when low pure
447
- this . setOverallStatus = [ false , false , true , false , false , false ] ;
448
- this . setActiveStatus = false ;
449
-
450
- const msg = 'I am now low on both keys and refs.' ;
451
- if ( opt . sendAlert . enable && opt . sendAlert . autokeys . lowPure ) {
452
- if ( opt . discordWebhook . sendAlert . enable && opt . discordWebhook . sendAlert . url . main !== '' ) {
453
- sendAlert ( 'lowPure' , this . bot , msg ) ;
454
- } else {
455
- this . bot . messageAdmins ( msg , [ ] ) ;
456
- }
457
- }
458
- }
459
- } else {
460
- // if Mann Co. Supply Crate Key entry already in the pricelist.json
461
- if ( isBanking ) {
462
- // enable keys banking - if banking conditions to enable banking matched and banking is enabled
463
- this . setOverallStatus = [ false , true , false , true , false , false ] ;
464
- this . setOldAmount = [ 0 , 0 , rKeysCanBankMin , rKeysCanBankMax , currKeys ] ;
465
- this . setActiveStatus = true ;
466
- this . updateToBank ( setMinKeys , setMaxKeys , currKeyPrice ) ;
467
- //
468
- } else if ( isTooManyRefWhileBanking ) {
469
- // enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys.
470
- this . setOverallStatus = [ true , false , false , false , true , false ] ;
471
- this . setOldAmount = [ 0 , rKeysCanBankMax , 0 , 0 , currKeys ] ;
472
- this . setActiveStatus = true ;
473
- this . update ( setMinKeys , setMaxKeys , currKeyPrice , 'buy' ) ;
474
- //
475
- } else if ( buyKeys ) {
476
- // enable Autokeys - Buying - if buying keys conditions matched
477
- this . setOverallStatus = [ true , false , false , false , true , false ] ;
478
- this . setOldAmount = [ 0 , rKeysCanBuy , 0 , 0 , currKeys ] ;
479
- this . setActiveStatus = true ;
480
- this . update ( setMinKeys , setMaxKeys , currKeyPrice , 'buy' ) ;
481
- //
482
- } else if ( sellKeys ) {
483
- // enable Autokeys - Selling - if selling keys conditions matched
484
- this . setOverallStatus = [ false , false , false , false , false , true ] ;
485
- this . setOldAmount = [ rKeysCanSell , 0 , 0 , 0 , currKeys ] ;
486
- this . setActiveStatus = true ;
487
- this . update ( setMinKeys , setMaxKeys , currKeyPrice , 'sell' ) ;
488
- //
489
- } else if ( isAlertAdmins && ! this . status . checkAlertOnLowPure ) {
490
- // alert admins when low pure
491
- this . setOverallStatus = [ false , false , true , false , false , false ] ;
492
- this . setActiveStatus = false ;
493
-
494
- const msg = 'I am now low on both keys and refs.' ;
495
- if ( opt . sendAlert . enable && opt . sendAlert . autokeys . lowPure ) {
496
- if ( opt . discordWebhook . sendAlert . enable && opt . discordWebhook . sendAlert . url . main !== '' ) {
497
- sendAlert ( 'lowPure' , this . bot , msg ) ;
498
- } else {
499
- this . bot . messageAdmins ( msg , [ ] ) ;
500
- }
501
- }
502
- }
430
+ } else if ( isNotInPricelist ) {
431
+ // if Autokeys is not running/disabled AND not exist in pricelist
432
+ if ( isBankingKeys && isEnableKeyBanking ) {
433
+ //create new Key entry and enable keys banking - if banking conditions to enable banking matched and banking is enabled
434
+ common1 ( ) ;
435
+ this . createToBank ( setMinKeys , setMaxKeys , currKeyPrice ) ;
436
+ //
437
+ } else if ( isBankingBuyKeysWithEnoughRefs && isEnableKeyBanking ) {
438
+ // enable keys banking - if refs > minRefs but Keys < minKeys, will buy keys.
439
+ common2 ( ) ;
440
+ this . create ( setMinKeys , setMaxKeys , currKeyPrice , 'buy' ) ;
441
+ //
442
+ } else if ( isBuyingKeys ) {
443
+ // create new Key entry and enable Autokeys - Buying - if buying keys conditions matched
444
+ common3 ( ) ;
445
+ this . create ( setMinKeys , setMaxKeys , currKeyPrice , 'buy' ) ;
446
+ //
447
+ } else if ( isSellingKeys ) {
448
+ // create new Key entry and enable Autokeys - Selling - if selling keys conditions matched
449
+ common4 ( ) ;
450
+ this . create ( setMinKeys , setMaxKeys , currKeyPrice , 'sell' ) ;
451
+ //
452
+ } else if ( isAlertAdmins && ! this . status . checkAlertOnLowPure ) {
453
+ // alert admins when low pure
454
+ common5 ( ) ;
503
455
}
504
456
}
505
457
log . debug (
@@ -689,11 +641,7 @@ export default class Autokeys {
689
641
disable ( keyPrices : KeyPrices ) : Promise < void > {
690
642
return new Promise ( ( resolve , reject ) => {
691
643
const match = this . bot . pricelist . getPrice ( { priceKey : '5021;6' , onlyEnabled : false } ) ;
692
- if ( match === null ) {
693
- return resolve ( ) ;
694
- }
695
-
696
- if ( ! match . enabled ) {
644
+ if ( match === null || ! match . enabled ) {
697
645
return resolve ( ) ;
698
646
}
699
647
0 commit comments