@@ -8,6 +8,7 @@ import {IgLoginTwoFactorRequiredError} from 'instagram-private-api/dist/errors/i
8
8
import { AccountRepository } from "instagram-private-api/dist/repositories/account.repository" ;
9
9
// import {inquirer} from "inquirer";
10
10
import { IgActionSpamError , IgResponseError , UserFeed } from "instagram-private-api" ;
11
+ const chalk = require ( 'chalk' ) ;
11
12
12
13
let ref , urlSegmentToInstagramId , instagramIdToUrlSegment ;
13
14
ref = require ( 'instagram-id-to-url-segment' ) ;
@@ -31,6 +32,7 @@ export class InstaAutoComment {
31
32
public account : AccountRepository ;
32
33
public idsToCommentOn = [ ] ;
33
34
private userPk : number ;
35
+ private throttleSeconds = 1000 ;
34
36
35
37
constructor ( userPk : number ) {
36
38
this . ig = new IgApiClient ( ) ;
@@ -139,8 +141,7 @@ export class InstaAutoComment {
139
141
do {
140
142
userFeedItems = await userFeed . items ( ) ;
141
143
// console.log("SETTING TIMEOUT PROMISE FOR: " + (waitSeconds) + " SECONDS", new Date().toLocaleTimeString());
142
- console . log ( '.' ) ;
143
- await new Promise ( r => setTimeout ( r , waitSeconds ) ) ;
144
+ await new Promise ( r => setTimeout ( r , this . throttleSeconds ) ) ;
144
145
for ( let userFeedItem of userFeedItems ) {
145
146
if ( ( nowTimestamp - userFeedItem . taken_at ) <= secondsOld || secondsOld === - 1 ) { // if the post isn't older than secondsOld
146
147
if ( doComment == DoComment . IfThereIsNoComment ) {
@@ -203,16 +204,14 @@ export class InstaAutoComment {
203
204
let mediaCommentsFeed = this . ig . feed . mediaComments ( feedItemId ) ;
204
205
let currentUser = await this . ig . account . currentUser ( ) ;
205
206
// console.log("SETTING TIMEOUT PROMISE FOR: " + (waitSeconds) + " SECONDS", new Date().toLocaleTimeString());
206
- console . log ( '.' ) ;
207
- await new Promise ( r => setTimeout ( r , waitSeconds ) ) ;
207
+ await new Promise ( r => setTimeout ( r , this . throttleSeconds ) ) ;
208
208
let subscription ;
209
209
let res = false ;
210
210
let feedItems ;
211
211
do {
212
212
feedItems = await mediaCommentsFeed . items ( ) ;
213
213
// console.log("SETTING TIMEOUT PROMISE FOR: " + (waitSeconds) + " SECONDS", new Date().toLocaleTimeString());
214
- console . log ( '.' ) ;
215
- await new Promise ( r => setTimeout ( r , waitSeconds ) ) ;
214
+ await new Promise ( r => setTimeout ( r , this . throttleSeconds ) ) ;
216
215
if ( feedItems !== undefined ) {
217
216
for ( let feedItem of feedItems ) {
218
217
if ( feedItem . user_id === currentUser . pk ) {
@@ -240,9 +239,8 @@ export class InstaAutoComment {
240
239
comment . text = InstaAutoComment . choseRandomComment ( commentsArray ) ;
241
240
try {
242
241
commentResult = await mediaRepo . comment ( comment ) ;
243
- console . log ( "Commented on " + "https://www.instagram.com/p/" + instagramIdToUrlSegment ( commentResult . media_id ) + " with the comment " + commentResult . text ) ;
242
+ console . log ( chalk . green ( "Commented on " + "https://www.instagram.com/p/" + instagramIdToUrlSegment ( commentResult . media_id ) + " with the comment " + commentResult . text ) ) ;
244
243
// console.log("SETTING TIMEOUT PROMISE FOR: " + (delayBetweenComments) + " SECONDS", new Date().toLocaleTimeString());
245
- console . log ( '.' ) ;
246
244
await new Promise ( r => setTimeout ( r , delayBetweenComments ) ) ;
247
245
} catch ( err ) {
248
246
if ( err instanceof IgActionSpamError ) {
@@ -309,7 +307,7 @@ export class InstaAutoComment {
309
307
}
310
308
}
311
309
312
- enum DoComment {
310
+ export enum DoComment {
313
311
IfThereIsNoComment ,
314
312
EvenIfThereIsAComment
315
313
}
0 commit comments