1
1
import fs from 'fs' ;
2
2
import utf from 'utf-8' ;
3
3
import Snoowrap from 'snoowrap' ;
4
- import Snoostorm from 'snoostorm' ;
4
+ import snoostorm from 'snoostorm' ;
5
5
import dotenv from 'dotenv' ;
6
6
7
- credentials = dotenv . config ( ) . parsed ;
8
-
7
+ // Awaiting top level await 😭
9
8
let ignoredUsers ;
10
-
11
9
fs . promises
12
10
. readFile ( '.userignore' , { encoding : 'utf8' } )
13
11
. then ( ( contents ) => {
14
12
ignoredUsers = contents . split ( '\n' ) ;
15
13
} ) ;
16
14
17
- const client = new Snoostorm ( new Snoowrap ( {
18
- userAgent : credentials . REDDIT_USER ,
19
- clientId : credentials . CLIENT_ID ,
20
- clientSecret : credentials . CLIENT_SECRET ,
21
- username : credentials . REDDIT_USER ,
22
- password : credentials . REDDIT_PASS
23
- } ) ) ;
15
+ const credentials = dotenv . config ( ) . parsed ;
16
+ const client = new Snoowrap ( credentials ) ;
24
17
25
- const comments = client . CommentStream ( {
18
+ const { CommentStream } = snoostorm ;
19
+ const comments = new CommentStream ( client , {
26
20
subreddit : 'all' ,
27
- results : 100 ,
21
+ limit : 100 ,
28
22
pollTime : 2000
29
23
} ) ;
30
24
31
25
const botNotice = '\n\n^(I am a bot. I\'m sorry if I ruined your surprise.)' ;
32
26
33
- comments . on ( 'comment ' , ( comment ) => {
27
+ comments . on ( 'item ' , ( comment ) => {
34
28
const body = comment . body . trim ( ) ;
35
29
const translated = decode ( body ) ;
36
30
const authorIsIgnored = ignoredUsers . includes ( comment . author . name ) ;
@@ -40,7 +34,6 @@ comments.on('comment', (comment) => {
40
34
}
41
35
} ) ;
42
36
43
-
44
37
function decode ( string ) {
45
38
const delimited = / ^ (?: [ 0 1 ] { 8 } ) { 3 , } $ / gm;
46
39
const nonDelimited = / ^ (?: [ 0 1 ] { 8 } ) { 3 , } $ / gm;
@@ -67,10 +60,3 @@ function decodeBytes(bytes) {
67
60
68
61
return decoded ;
69
62
}
70
-
71
- export default {
72
- credentials,
73
- client,
74
- comments,
75
- decode
76
- } ;
0 commit comments