@@ -43,6 +43,7 @@ class LemmyBot {
43
43
#timeouts: NodeJS . Timeout [ ] = [ ] ;
44
44
#auth?: string ;
45
45
#markAsBot: boolean ;
46
+ #enableLogs: boolean ;
46
47
#defaultMinutesUntilReprocess?: number ;
47
48
#federationOptions: BotFederationOptions ;
48
49
#tasks: ScheduledTask [ ] = [ ] ;
@@ -391,7 +392,8 @@ class LemmyBot {
391
392
dbFile,
392
393
federation,
393
394
schedule,
394
- markAsBot = true
395
+ markAsBot = true ,
396
+ enableLogs = true
395
397
} : BotOptions ) {
396
398
switch ( federation ) {
397
399
case undefined :
@@ -468,6 +470,7 @@ class LemmyBot {
468
470
this . #defaultSecondsBetweenPolls = defaultSecondsBetweenPolls ;
469
471
this . #isRunning = false ;
470
472
this . #markAsBot = markAsBot ;
473
+ this . #enableLogs = enableLogs ;
471
474
this . #instance = instance ;
472
475
this . #defaultMinutesUntilReprocess = defaultMinutesUntilReprocess ;
473
476
this . #httpClient = new LemmyHttp (
@@ -540,7 +543,7 @@ class LemmyBot {
540
543
modBanFromSite : modBanFromSiteOptions
541
544
} = this . #handlers;
542
545
543
- await setupDB ( this . #dbFile) ;
546
+ await setupDB ( this . #log , this . # dbFile) ;
544
547
545
548
if ( this . #credentials) {
546
549
await this . #login( ) ;
@@ -678,9 +681,7 @@ class LemmyBot {
678
681
read : true
679
682
} ) ;
680
683
681
- console . log (
682
- `Marked private message ID ${ messageView . private_message . id } from ${ messageView . creator . id } as read`
683
- ) ;
684
+ this . #log( `Marked private message ID ${ messageView . private_message . id } from ${ messageView . creator . id } as read` ) ;
684
685
685
686
return promise ;
686
687
}
@@ -1151,29 +1152,29 @@ class LemmyBot {
1151
1152
}
1152
1153
1153
1154
start ( ) {
1154
- console . log ( 'Starting bot' ) ;
1155
+ this . # log( 'Starting bot' ) ;
1155
1156
this . #isRunning = true ;
1156
1157
this . #runBot( ) ;
1157
1158
}
1158
1159
1159
1160
stop ( ) {
1160
- console . log ( 'stopping bot' ) ;
1161
+ this . # log( 'Stopping bot' ) ;
1161
1162
this . #isRunning = false ;
1162
1163
}
1163
1164
1164
1165
async #login( ) {
1165
1166
if ( this . #credentials) {
1166
- console . log ( 'logging in' ) ;
1167
+ this . # log( 'Logging in' ) ;
1167
1168
const loginRes = await this . #httpClient. login ( {
1168
1169
password : this . #credentials. password ,
1169
1170
username_or_email : this . #credentials. username
1170
1171
} ) ;
1171
1172
this . #auth = loginRes . jwt ;
1172
1173
if ( this . #auth) {
1173
- console . log ( 'logged in' ) ;
1174
+ this . # log( 'Logged in' ) ;
1174
1175
1175
1176
if ( this . #markAsBot) {
1176
- console . log ( 'Marking account as bot account' ) ;
1177
+ this . # log( 'Marking account as bot account' ) ;
1177
1178
1178
1179
await this . #httpClient
1179
1180
. saveUserSettings ( {
@@ -1377,10 +1378,16 @@ class LemmyBot {
1377
1378
action : ( ) => Promise < T > ;
1378
1379
} ) {
1379
1380
if ( this . #auth) {
1380
- console . log ( logMessage ) ;
1381
+ this . # log( logMessage ) ;
1381
1382
await action ( ) ;
1382
1383
}
1383
1384
}
1385
+
1386
+ #log = ( output : string ) => {
1387
+ if ( this . #enableLogs) {
1388
+ console . log ( output ) ;
1389
+ }
1390
+ }
1384
1391
}
1385
1392
1386
1393
export default LemmyBot ;
0 commit comments