@@ -9,6 +9,7 @@ const fs = require('fs');
9
9
10
10
const bot = new Discord . Client ( ) ;
11
11
12
+ let whitelist = fs . readFileSync ( 'HDWhitelist.txt' , 'utf8' )
12
13
let usageData = JSON . parse ( fs . readFileSync ( 'usage.json' , 'utf8' ) )
13
14
let ipfsid ;
14
15
@@ -38,28 +39,16 @@ bot.on('message', (message) => {
38
39
message . channel . send ( Config . PING_REPLY ) ;
39
40
} else if ( message . content . startsWith ( Config . commandPrefix + 'ipfs ' ) ) {
40
41
// Source video
41
- if ( Config . sdOnlyMode == true ) {
42
- sendMessage ( message , Config . ERROR_SD_ONLY_MODE ) ;
43
- return ;
44
- }
42
+ if ( Config . sdOnlyMode == true )
43
+ return sendMessage ( message , Config . ERROR_SD_ONLY_MODE )
45
44
46
- if ( Config . hdwhitelistEnabled == true ) {
47
- if ( fs . existsSync ( 'HDWhitelist.txt' ) ) {
48
- var readList = fs . readFileSync ( 'HDWhitelist.txt' , 'utf8' ) ;
49
- if ( readList . includes ( message . author . id ) != true ) {
50
- // Do not proceed if user is not in whitelist
51
- sendMessage ( message , Config . ERROR_NO_PIN_PERMISSION ) ;
52
- return ;
53
- }
54
- } else {
55
- sendMessage ( message , Config . WHITELIST_FILE404 ) ;
56
- return ;
57
- }
58
- }
45
+ if ( Config . hdwhitelistEnabled && ! whitelist . includes ( message . author . id ) )
46
+ // Do not proceed if user is not in whitelist
47
+ return sendMessage ( message , Config . ERROR_NO_PIN_PERMISSION )
59
48
60
- var command = message . content ;
61
- var steemitAuthorPermlink = command . split ( '/' ) . slice ( - 2 ) ;
62
- var author = steemitAuthorPermlink [ 0 ] ;
49
+ let command = message . content
50
+ let steemitAuthorPermlink = command . split ( '/' ) . slice ( - 2 )
51
+ let author = steemitAuthorPermlink [ 0 ]
63
52
64
53
if ( author . startsWith ( '@' ) ) {
65
54
// Remove @ symbol if it is a steemit/busy link
@@ -116,19 +105,9 @@ bot.on('message', (message) => {
116
105
} )
117
106
} ) ;
118
107
} else if ( message . content . startsWith ( Config . commandPrefix + 'ipfs240 ' ) ) {
119
- if ( Config . restrictedMode == true ) {
120
- if ( fs . existsSync ( 'HDWhitelist.txt' ) ) {
121
- var readList = fs . readFileSync ( 'HDWhitelist.txt' , 'utf8' ) ;
122
- if ( readList . includes ( message . author . id ) != true ) {
123
- // Do not proceed if user is not in whitelist
124
- sendMessage ( message , Config . ERROR_NO_PIN_PERMISSION_RESTRICTED ) ;
125
- return ;
126
- }
127
- } else {
128
- sendMessage ( message , Config . WHITELIST_FILE404 ) ;
129
- return ;
130
- }
131
- }
108
+ if ( Config . hdwhitelistEnabled && ! whitelist . includes ( message . author . id ) )
109
+ // Do not proceed if user is not in whitelist
110
+ return sendMessage ( message , Config . ERROR_NO_PIN_PERMISSION )
132
111
133
112
// 240p video
134
113
var command = message . content ;
@@ -188,24 +167,14 @@ bot.on('message', (message) => {
188
167
} )
189
168
} ) ;
190
169
} else if ( message . content . startsWith ( Config . commandPrefix + 'ipfs480 ' ) ) {
191
- if ( Config . restrictedMode == true ) {
192
- if ( fs . existsSync ( 'HDWhitelist.txt' ) ) {
193
- var readList = fs . readFileSync ( 'HDWhitelist.txt' , 'utf8' ) ;
194
- if ( readList . includes ( message . author . id ) != true ) {
195
- // Do not proceed if user is not in whitelist
196
- sendMessage ( message , Config . ERROR_NO_PIN_PERMISSION_RESTRICTED ) ;
197
- return ;
198
- }
199
- } else {
200
- sendMessage ( message , Config . WHITELIST_FILE404 ) ;
201
- return ;
202
- }
203
- }
170
+ if ( Config . hdwhitelistEnabled && ! whitelist . includes ( message . author . id ) )
171
+ // Do not proceed if user is not in whitelist
172
+ return sendMessage ( message , Config . ERROR_NO_PIN_PERMISSION )
204
173
205
174
// 480p video
206
- var command = message . content ;
207
- var steemitAuthorPermlink = command . split ( '/' ) . slice ( - 2 ) ;
208
- var author = steemitAuthorPermlink [ 0 ] ;
175
+ let command = message . content
176
+ let steemitAuthorPermlink = command . split ( '/' ) . slice ( - 2 )
177
+ let author = steemitAuthorPermlink [ 0 ]
209
178
210
179
if ( author . startsWith ( '@' ) ) {
211
180
// Remove @ symbol if it is a steemit/busy link
@@ -261,28 +230,16 @@ bot.on('message', (message) => {
261
230
} ) ;
262
231
} else if ( message . content . startsWith ( Config . commandPrefix + 'ipfs720 ' ) ) {
263
232
// 720p video
264
- if ( Config . sdOnlyMode == true ) {
265
- sendMessage ( message , Config . ERROR_SD_ONLY_MODE ) ;
266
- return ;
267
- }
233
+ if ( Config . sdOnlyMode == true )
234
+ return sendMessage ( message , Config . ERROR_SD_ONLY_MODE )
268
235
269
- if ( Config . hdwhitelistEnabled == true ) {
270
- if ( fs . existsSync ( 'HDWhitelist.txt' ) ) {
271
- var readList = fs . readFileSync ( 'HDWhitelist.txt' , 'utf8' ) ;
272
- if ( readList . includes ( message . author . id ) != true ) {
273
- // Do not proceed if user is not in whitelist
274
- sendMessage ( message , Config . ERROR_NO_PIN_PERMISSION ) ;
275
- return ;
276
- }
277
- } else {
278
- sendMessage ( message , Config . WHITELIST_FILE404 ) ;
279
- return ;
280
- }
281
- }
236
+ if ( Config . hdwhitelistEnabled && ! whitelist . includes ( message . author . id ) )
237
+ // Do not proceed if user is not in whitelist
238
+ return sendMessage ( message , Config . ERROR_NO_PIN_PERMISSION )
282
239
283
- var command = message . content ;
284
- var steemitAuthorPermlink = command . split ( '/' ) . slice ( - 2 ) ;
285
- var author = steemitAuthorPermlink [ 0 ] ;
240
+ let command = message . content
241
+ let steemitAuthorPermlink = command . split ( '/' ) . slice ( - 2 )
242
+ let author = steemitAuthorPermlink [ 0 ]
286
243
287
244
if ( author . startsWith ( '@' ) ) {
288
245
// Remove @ symbol if it is a steemit/busy link
@@ -338,30 +295,16 @@ bot.on('message', (message) => {
338
295
} ) ;
339
296
} else if ( message . content . startsWith ( Config . commandPrefix + 'ipfs1080 ' ) ) {
340
297
// 1080p video
341
- if ( Config . sdOnlyMode == true ) {
342
- sendMessage ( message , ERROR_SD_ONLY_MODE ) ;
343
- return ;
344
- }
345
-
346
- if ( Config . hdwhitelistEnabled == true ) {
347
- if ( fs . existsSync ( 'HDWhitelist.txt' ) ) {
348
- var readList = fs . readFileSync ( 'HDWhitelist.txt' , 'utf8' ) ;
349
- if ( readList . includes ( message . author . id ) != true ) {
350
- // Do not proceed if user is not in whitelist
351
- if ( Config . restrictedMode == true ) {
352
- sendMessage ( message , Config . ERROR_NO_PIN_PERMISSION ) ;
353
- return ;
354
- }
355
- }
356
- } else {
357
- sendMessage ( message , Config . WHITELIST_FILE404 ) ;
358
- return ;
359
- }
360
- }
298
+ if ( Config . sdOnlyMode == true )
299
+ return sendMessage ( message , Config . ERROR_SD_ONLY_MODE )
361
300
362
- var command = message . content ;
363
- var steemitAuthorPermlink = command . split ( '/' ) . slice ( - 2 ) ;
364
- var author = steemitAuthorPermlink [ 0 ] ;
301
+ if ( Config . hdwhitelistEnabled && ! whitelist . includes ( message . author . id ) )
302
+ // Do not proceed if user is not in whitelist
303
+ return sendMessage ( message , Config . ERROR_NO_PIN_PERMISSION )
304
+
305
+ let command = message . content
306
+ let steemitAuthorPermlink = command . split ( '/' ) . slice ( - 2 )
307
+ let author = steemitAuthorPermlink [ 0 ]
365
308
366
309
if ( author . startsWith ( '@' ) ) {
367
310
// Remove @ symbol if it is a steemit/busy link
@@ -417,25 +360,26 @@ bot.on('message', (message) => {
417
360
} ) ;
418
361
} else if ( message . content . startsWith ( Config . commandPrefix + 'ipfssound ' ) ) {
419
362
// DSound audio
420
- var command = message . content ;
421
- var steemitAuthorPermlink = command . split ( '/' ) . slice ( - 2 ) ;
422
- var author = steemitAuthorPermlink [ 0 ] ;
363
+ if ( Config . hdwhitelistEnabled && ! whitelist . includes ( message . author . id ) )
364
+ // Do not proceed if user is not in whitelist
365
+ return sendMessage ( message , Config . ERROR_NO_PIN_PERMISSION_AUDIO )
366
+
367
+ let command = message . content
368
+ let steemitAuthorPermlink = command . split ( '/' ) . slice ( - 2 )
369
+ let author = steemitAuthorPermlink [ 0 ]
423
370
424
371
if ( author . startsWith ( '@' ) ) {
425
372
// Remove @ symbol if it is a steemit/busy link
426
373
author = steemitAuthorPermlink [ 0 ] . slice ( 1 , steemitAuthorPermlink [ 0 ] . length ) ;
427
374
}
428
375
429
376
Steem . api . getContent ( author , steemitAuthorPermlink [ 1 ] , function ( err , result ) {
430
- if ( err != null ) {
431
- sendMessage ( message , Config . ERROR_STEEM_GETCONTENT + err ) ;
432
- return ;
433
- }
377
+ if ( err != null )
378
+ return sendMessage ( message , Config . ERROR_STEEM_GETCONTENT + err )
434
379
435
380
// Get JSON metadata of post
436
- var jsonmeta = JSON . parse ( result . json_metadata ) ;
437
-
438
- var dsoundhash = jsonmeta . audio . files . sound ;
381
+ let jsonmeta = JSON . parse ( result . json_metadata )
382
+ let dsoundhash = jsonmeta . audio . files . sound
439
383
440
384
IPFS . pin . ls ( dsoundhash , { type : 'recursive' } , ( err , pinset ) => {
441
385
if ( err == null && pinset [ 0 ] . hash === dsoundhash ) {
@@ -546,33 +490,22 @@ bot.on('message', (message) => {
546
490
}
547
491
} else if ( message . content == ( Config . commandPrefix + 'hdwhitelist check' ) ) {
548
492
// Check if user is in whitelist
549
- if ( fs . existsSync ( 'HDWhitelist.txt' ) ) {
550
- var readList = fs . readFileSync ( 'HDWhitelist.txt' , 'utf8' ) ;
551
- if ( readList . includes ( message . author . id ) == true ) {
552
- replyMessage ( message , Config . WHITELIST_TRUE ) ;
553
- } else {
554
- replyMessage ( message , Config . WHITELIST_FALSE ) ;
555
- }
493
+ if ( whitelist . includes ( message . author . id ) ) {
494
+ replyMessage ( message , Config . WHITELIST_TRUE ) ;
556
495
} else {
557
- message . channel . send ( Config . WHITELIST_FILE404 ) ;
496
+ replyMessage ( message , Config . WHITELIST_FALSE ) ;
558
497
}
559
498
} else if ( message . content . startsWith ( Config . commandPrefix + 'hdwhitelist add ' ) ) {
560
499
// Add user to whitelist
561
500
if ( message . member . hasPermission ( 'ADMINISTRATOR' ) == true ) {
562
501
let uidToWhitelist = message . mentions . members . first ( ) . user . id ;
563
502
564
- if ( fs . existsSync ( 'HDWhitelist.txt' ) ) {
565
- var readList = fs . readFileSync ( 'HDWhitelist.txt' , 'utf8' ) ;
566
- if ( readList . includes ( uidToWhitelist ) == true ) {
567
- sendMessage ( message , Config . WHITELIST_ALREADY_IN ) ;
568
- return ;
569
- }
570
- fs . writeFileSync ( 'HDWhitelist.txt' , readList + uidToWhitelist + '\n' ) ;
571
- } else {
572
- fs . writeFileSync ( 'HDWhitelist.txt' , uidToWhitelist + '\n' ) ;
573
- }
503
+ if ( whitelist . includes ( uidToWhitelist ) )
504
+ return sendMessage ( message , Config . WHITELIST_ALREADY_IN )
574
505
575
- sendMessage ( message , '<@' + uidToWhitelist + '> ' + Config . WHITELIST_ADD_SUCCESS ) ;
506
+ whitelist = whitelist + uidToWhitelist + '\n'
507
+ fs . writeFileSync ( 'HDWhitelist.txt' , whitelist )
508
+ sendMessage ( message , '<@' + uidToWhitelist + '> ' + Config . WHITELIST_ADD_SUCCESS )
576
509
} else {
577
510
sendMessage ( message , Config . ERROR_NO_PERMISSION ) ;
578
511
}
@@ -581,42 +514,33 @@ bot.on('message', (message) => {
581
514
if ( message . member . hasPermission ( 'ADMINISTRATOR' ) == true ) {
582
515
let uidToRemove = message . mentions . members . first ( ) . user . id ;
583
516
584
- if ( fs . existsSync ( 'HDWhitelist.txt' ) ) {
585
- var readList = fs . readFileSync ( 'HDWhitelist.txt' , 'utf8' ) ;
586
- if ( readList . includes ( uidToRemove ) == true ) {
587
- var newList = readList . replace ( uidToRemove + '\n' , '' ) ;
588
- fs . writeFileSync ( 'HDWhitelist.txt' , newList ) ;
589
- sendMessage ( message , '<@' + uidToRemove + '> ' + Config . WHITELIST_RM_SUCCESS ) ;
590
- } else {
591
- sendMessage ( message , Config . WHITELIST_RM_UID404 ) ;
592
- }
517
+ if ( whitelist . includes ( uidToRemove ) ) {
518
+ let newList = whitelist . replace ( uidToRemove + '\n' , '' )
519
+ whitelist = newList
520
+ fs . writeFileSync ( 'HDWhitelist.txt' , whitelist )
521
+ sendMessage ( message , '<@' + uidToRemove + '> ' + Config . WHITELIST_RM_SUCCESS )
593
522
} else {
594
- sendMessage ( message , Config . WHITELIST_FILE404 ) ;
523
+ sendMessage ( message , Config . WHITELIST_RM_UID404 )
595
524
}
596
525
} else {
597
526
sendMessage ( message , Config . ERROR_NO_PERMISSION ) ;
598
527
}
599
528
} else if ( message . content == ( Config . commandPrefix + 'hdwhitelist ls' ) ) {
600
529
// List all users in whitelist in DM
601
530
if ( message . member . hasPermission ( 'ADMINISTRATOR' ) == true && Config . silentModeEnabled != true ) {
602
- if ( fs . existsSync ( 'HDWhitelist.txt' ) ) {
603
- var readList = fs . readFileSync ( 'HDWhitelist.txt' , 'utf8' ) ;
604
- var uidListArray = readList . split ( '\n' ) ;
605
-
606
- for ( var i = 0 ; i < uidListArray . length ; i ++ ) {
607
- uidListArray [ i ] = '<@' + uidListArray [ i ] + '>' ;
608
- }
609
-
610
- var uidList = uidListArray . toString ( ) ;
611
- var finalListToDM = uidList . replace ( / , / g, '\n' ) ;
612
- finalListToDM = finalListToDM . slice ( 0 , - 4 ) ;
613
- finalListToDM = 'Whitelisted users: \n' + finalListToDM ;
614
- if ( Config . silentModeEnabled != true ) {
615
- message . react ( '📬' )
616
- message . member . send ( finalListToDM ) ;
617
- }
618
- } else {
619
- sendMessage ( message , Config . WHITELIST_FILE404 ) ;
531
+ let uidListArray = whitelist . split ( '\n' )
532
+
533
+ for ( var i = 0 ; i < uidListArray . length ; i ++ ) {
534
+ uidListArray [ i ] = '<@' + uidListArray [ i ] + '>'
535
+ }
536
+
537
+ let uidList = uidListArray . toString ( )
538
+ let finalListToDM = uidList . replace ( / , / g, '\n' )
539
+ finalListToDM = finalListToDM . slice ( 0 , - 4 )
540
+ finalListToDM = 'Whitelisted users: \n' + finalListToDM
541
+ if ( Config . silentModeEnabled != true ) {
542
+ message . react ( '📬' )
543
+ message . member . send ( finalListToDM )
620
544
}
621
545
} else {
622
546
sendMessage ( message , Config . ERROR_NO_PERMISSION ) ;
0 commit comments