@@ -271,8 +271,17 @@ export class TwitchDropsBot extends EventEmitter {
271
271
} else if ( indexA === indexB ) { // Both games have the same priority. Give priority to the one that ends first.
272
272
const endTimeA = Date . parse ( campaignA . endAt ) ;
273
273
const endTimeB = Date . parse ( campaignB . endAt ) ;
274
- if ( endTimeA === endTimeB ) {
275
- return a < b ? - 1 : 1 ;
274
+ if ( endTimeA === endTimeB ) { // Both campaigns end at the same time. Give priority to the one that is in the broadcasters list
275
+ const broadcasterIndexA = this . #getFirstBroadcasterIndex( campaignA ) ;
276
+ const broadcasterIndexB = this . #getFirstBroadcasterIndex( campaignB ) ;
277
+ if ( broadcasterIndexA === - 1 && broadcasterIndexB !== - 1 ) {
278
+ return 1 ;
279
+ } else if ( broadcasterIndexA !== - 1 && broadcasterIndexB === - 1 ) {
280
+ return - 1 ;
281
+ } else if ( broadcasterIndexA === broadcasterIndexB ) {
282
+ return a < b ? - 1 : 1 ;
283
+ }
284
+ return Math . sign ( broadcasterIndexA - broadcasterIndexB ) ;
276
285
}
277
286
return endTimeA < endTimeB ? - 1 : 1 ;
278
287
}
@@ -549,6 +558,19 @@ export class TwitchDropsBot extends EventEmitter {
549
558
} ) ;
550
559
}
551
560
561
+ #getFirstBroadcasterIndex( campaign : DropCampaign ) {
562
+ for ( let i = 0 ; i < this . #broadcasterIds. length ; ++ i ) {
563
+ if ( campaign . allow && campaign . allow . isEnabled ) {
564
+ for ( const channel of campaign . allow . channels ) {
565
+ if ( channel . displayName . toLowerCase ( ) === this . #broadcasterIds[ i ] . toLowerCase ( ) ) {
566
+ return i ;
567
+ }
568
+ }
569
+ }
570
+ }
571
+ return - 1 ;
572
+ }
573
+
552
574
#isCampaignCompleted( dropCampaignDetails : DropCampaign , inventory : Inventory ) : boolean {
553
575
const timeBasedDrops = dropCampaignDetails . timeBasedDrops ;
554
576
if ( timeBasedDrops != null ) {
0 commit comments