Skip to content

Commit b773678

Browse files
Update to snoostorm 1.3.0
1 parent dab5206 commit b773678

File tree

4 files changed

+16
-32
lines changed

4 files changed

+16
-32
lines changed

.env.example

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
userAgent=example user agent string
2+
clientId=*************
3+
clientSecret=**************************
4+
username=example
5+
password=***

app.js

+8-22
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
11
import fs from 'fs';
22
import utf from 'utf-8';
33
import Snoowrap from 'snoowrap';
4-
import Snoostorm from 'snoostorm';
4+
import snoostorm from 'snoostorm';
55
import dotenv from 'dotenv';
66

7-
credentials = dotenv.config().parsed;
8-
7+
// Awaiting top level await 😭
98
let ignoredUsers;
10-
119
fs.promises
1210
.readFile('.userignore', { encoding: 'utf8' })
1311
.then((contents) => {
1412
ignoredUsers = contents.split('\n');
1513
});
1614

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);
2417

25-
const comments = client.CommentStream({
18+
const { CommentStream } = snoostorm;
19+
const comments = new CommentStream(client, {
2620
subreddit: 'all',
27-
results: 100,
21+
limit: 100,
2822
pollTime: 2000
2923
});
3024

3125
const botNotice = '\n\n^(I am a bot. I\'m sorry if I ruined your surprise.)';
3226

33-
comments.on('comment', (comment) => {
27+
comments.on('item', (comment) => {
3428
const body = comment.body.trim();
3529
const translated = decode(body);
3630
const authorIsIgnored = ignoredUsers.includes(comment.author.name);
@@ -40,7 +34,6 @@ comments.on('comment', (comment) => {
4034
}
4135
});
4236

43-
4437
function decode(string) {
4538
const delimited = /^(?:[01]{8} ){3,}$/gm;
4639
const nonDelimited = /^(?:[01]{8}){3,}$/gm;
@@ -67,10 +60,3 @@ function decodeBytes(bytes) {
6760

6861
return decoded;
6962
}
70-
71-
export default {
72-
credentials,
73-
client,
74-
comments,
75-
decode
76-
};

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "app.js",
66
"type": "module",
77
"scripts": {
8-
"start": "node app.js",
8+
"start": "node --experimental-modules app.js",
99
"test": "ava"
1010
},
1111
"keywords": [
@@ -19,7 +19,7 @@
1919
"license": "MIT",
2020
"dependencies": {
2121
"dotenv": "^6.0.0",
22-
"snoostorm": "1.3.0",
22+
"snoostorm": "^1.3.0",
2323
"snoowrap": "^1.15.2",
2424
"utf-8": "^2.0.0"
2525
},

readme.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@ The code for a reddit bot that decodes binary. I did this as a noob project to f
44

55
## Note
66

7-
A `.env` file with configuration variables is required in the root of the project.
8-
9-
```
10-
CLIENT_ID=**************
11-
CLIENT_SECRET=***************************
12-
REDDIT_USER=****
13-
REDDIT_PASS=****
14-
```
7+
A `.env` file with configuration variables is required in the root of the project. See `.env.example` for an example.
158

169
## License
1710

0 commit comments

Comments
 (0)