@@ -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,7 +681,7 @@ class LemmyBot {
678
681
read : true
679
682
} ) ;
680
683
681
- console . log (
684
+ this . # log(
682
685
`Marked private message ID ${ messageView . private_message . id } from ${ messageView . creator . id } as read`
683
686
) ;
684
687
@@ -1151,29 +1154,29 @@ class LemmyBot {
1151
1154
}
1152
1155
1153
1156
start ( ) {
1154
- console . log ( 'Starting bot' ) ;
1157
+ this . # log( 'Starting bot' ) ;
1155
1158
this . #isRunning = true ;
1156
1159
this . #runBot( ) ;
1157
1160
}
1158
1161
1159
1162
stop ( ) {
1160
- console . log ( 'stopping bot' ) ;
1163
+ this . # log( 'Stopping bot' ) ;
1161
1164
this . #isRunning = false ;
1162
1165
}
1163
1166
1164
1167
async #login( ) {
1165
1168
if ( this . #credentials) {
1166
- console . log ( 'logging in' ) ;
1169
+ this . # log( 'Logging in' ) ;
1167
1170
const loginRes = await this . #httpClient. login ( {
1168
1171
password : this . #credentials. password ,
1169
1172
username_or_email : this . #credentials. username
1170
1173
} ) ;
1171
1174
this . #auth = loginRes . jwt ;
1172
1175
if ( this . #auth) {
1173
- console . log ( 'logged in' ) ;
1176
+ this . # log( 'Logged in' ) ;
1174
1177
1175
1178
if ( this . #markAsBot) {
1176
- console . log ( 'Marking account as bot account' ) ;
1179
+ this . # log( 'Marking account as bot account' ) ;
1177
1180
1178
1181
await this . #httpClient
1179
1182
. saveUserSettings ( {
@@ -1383,6 +1386,12 @@ class LemmyBot {
1383
1386
throw new Error ( 'Not logged in' ) ;
1384
1387
}
1385
1388
}
1389
+
1390
+ #log = ( output : string ) => {
1391
+ if ( this . #enableLogs) {
1392
+ console . log ( output ) ;
1393
+ }
1394
+ } ;
1386
1395
}
1387
1396
1388
1397
export default LemmyBot ;
0 commit comments