import { IgApiClient } from 'instagram-private-api' ; import { Config } from '../core/config' ; import { mediaFeed , likesForTags } from './utils' ; import { store } from '../core/store' ; import logger from '../core/logging' ; async function hashtag ( client , config ) { if ( config . likeLimit <= 0 ) { logger . error ( 'like limit has to be set for like by hashtag!' ) ; return ; } if ( ! config . tags ) { logger . error ( 'there are no tags given!' ) ; return ; } const likeBoundsForTags = likesForTags ( config ) ; let currentTagIndex = 0 ; let hashtagRunning = true ; let tagRunning = false ; store . pluck ( 'imageLikes' ) . subscribe ( likes => { if ( likes >= config . likeLimit ) { logger . info ( 'like limit reached for hashtag feed' ) ; hashtagRunning = false ; tagRunning = false ; return ; } if ( currentTagIndex == config . tags . length - 1 ) return ; const currentTagLimit = likeBoundsForTags . reduce ( ( acc , val , index ) => acc += index <= currentTagIndex ? val : 0 ) ; if ( likes >= currentTagLimit ) tagRunning = false ; } ) ; for ( const tag of config . tags ) { if ( ! hashtagRunning ) break ; tagRunning = true ; logger . info ( 'starting hashtag feed for tag: %s. randomized number of likes: %i.' , tag , likeBoundsForTags [ currentTagIndex ] ) ; await mediaFeed ( client , config , client . feed . tags ( tag , 'recent' ) , ( ) => tagRunning ) ; currentTagIndex ++ ; } } export default hashtag ;