Skip to content

Commit 9cf2653

Browse files
committed
Initial Code Commit
1 parent a7ef069 commit 9cf2653

5 files changed

Lines changed: 1175 additions & 1 deletion

File tree

.eslintrc.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
module.exports = {
3+
"env": {
4+
"es6": true,
5+
"node": true
6+
},
7+
"extends": "google",
8+
"rules": {
9+
"comma-dangle": "off",
10+
"indent": ["error", 4],
11+
"max-len": ["error", 100],
12+
"no-undef": "error",
13+
"no-use-before-define": "off",
14+
"object-curly-spacing": ["error", "always"],
15+
"one-var": "off"
16+
},
17+
"parserOptions": {
18+
"ecmaVersion": 8,
19+
"sourceType": "module",
20+
}
21+
};

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
11
# reddit-bot-stream-example
2-
An example of a Reddit bot that looks at new Reddit comments
2+
3+
## What is this?
4+
5+
This repo provides an example of a Reddit bot built in Node.js.
6+
7+
Specifically, we are looking at a stream of newly posted comments on reddit, and doing something with their contents.
8+
9+
This is achieved through [Snoowrap](https://www.npmjs.com/package/snoowrap) as a Node.js wrapper for the Reddit API, and [Snoostorm](https://www.npmjs.com/package/snoostorm) as a way to easily access the stream of Reddit comments through Snoowrap.
10+
11+
## Install
12+
13+
`npm i`
14+
15+
Create `.env` at root with the following variables, specific to your Reddit app: https://www.reddit.com/prefs/apps/
16+
17+
```
18+
CLIENT_ID=***
19+
CLIENT_SECRET=***
20+
REDDIT_USER=***
21+
REDDIT_PASS=***
22+
```
23+
24+
## Usage
25+
26+
Running the bot
27+
28+
`npm start`

app.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require('dotenv').config();
2+
3+
const Snoowrap = require('snoowrap');
4+
const Snoostorm = require('snoostorm');
5+
6+
// Build Snoowrap and Snoostorm clients
7+
const r = new Snoowrap({
8+
userAgent: 'reddit-bot-example-node',
9+
clientId: process.env.CLIENT_ID,
10+
clientSecret: process.env.CLIENT_SECRET,
11+
username: process.env.REDDIT_USER,
12+
password: process.env.REDDIT_PASS
13+
});
14+
const client = new Snoostorm(r);
15+
16+
// Configure options for stream: subreddit & results per query
17+
const streamOpts = {
18+
subreddit: 'all',
19+
results: 25
20+
};
21+
22+
// Create a Snoostorm CommentStream with the specified options
23+
const comments = client.CommentStream(streamOpts); // eslint-disable-line
24+
25+
// On comment, perform whatever logic you want to do
26+
comments.on('comment', (comment) => {
27+
if (comment.body === ':(') {
28+
comment.reply(':)');
29+
}
30+
});

0 commit comments

Comments
 (0)