-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09ebf23
commit 18a6db0
Showing
10 changed files
with
4,954 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "./node_modules/gts/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
...require('gts/.prettierrc.json') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,64 @@ | ||
import * as dotenv from "dotenv"; | ||
import Snoowrap from "snoowrap"; | ||
import { Commands } from "./src/Commands"; | ||
dotenv.config(); | ||
|
||
const r = new Snoowrap({ | ||
userAgent: process.env.R_USERAGENT || "", | ||
clientId: process.env.R_CLIENTID || "", | ||
password: process.env.R_PASSWORD || "", | ||
username: process.env.R_USERNAME || "", | ||
clientSecret: process.env.R_SECRET || "", | ||
}); | ||
|
||
const runCommand = (comment: Snoowrap.Comment) => { | ||
// Loop through each command | ||
Commands.forEach((command) => { | ||
// Check if the comment body contains the `command` handler | ||
if (comment.body.indexOf(command.handler) != -1) { | ||
// Run the command in `command` | ||
command.command(comment); | ||
} | ||
}); | ||
}; | ||
|
||
const listenForCommands = () => { | ||
// Get the new comments in the specified subreddit | ||
r.getSubreddit("test") | ||
.getNewComments() | ||
.then((newComments) => { | ||
let newValidComments: Array<Snoowrap.Comment> = []; | ||
|
||
// Get All Valid Comments | ||
newComments.forEach((comment) => { | ||
Commands.forEach((command) => { | ||
// If the command body includes a handler then push it to `newValidComments` | ||
if (comment.body.indexOf(command.handler) != 0) { | ||
newValidComments.push(comment); | ||
} | ||
}); | ||
}); | ||
|
||
// Filter the already replied once | ||
newValidComments.forEach((comment) => { | ||
let hasPrevReplied = false; | ||
|
||
// Check each reply | ||
comment.replies.forEach((rep) => { | ||
// If a reply is authored by the bot username, then ignore it | ||
if (rep.author.name == r.username) { | ||
hasPrevReplied = true; | ||
} | ||
}); | ||
|
||
// If no previous reply, then run the command | ||
if (!hasPrevReplied) { | ||
runCommand(comment); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
setInterval(() => { | ||
listenForCommands(); | ||
}, Number(process.env.B_CHECKDELAY) || 60000); | ||
import * as dotenv from 'dotenv'; | ||
import Snoowrap from 'snoowrap'; | ||
import {Commands} from './src/Commands'; | ||
dotenv.config(); | ||
|
||
const r = new Snoowrap({ | ||
userAgent: process.env.R_USERAGENT || '', | ||
clientId: process.env.R_CLIENTID || '', | ||
password: process.env.R_PASSWORD || '', | ||
username: process.env.R_USERNAME || '', | ||
clientSecret: process.env.R_SECRET || '', | ||
}); | ||
|
||
const runCommand = (comment: Snoowrap.Comment) => { | ||
// Loop through each command | ||
Commands.forEach(command => { | ||
// Check if the comment body contains the `command` handler | ||
if (comment.body.indexOf(command.handler) !== -1) { | ||
// Run the command in `command` | ||
command.command(comment); | ||
} | ||
}); | ||
}; | ||
|
||
const listenForCommands = () => { | ||
// Get the new comments in the specified subreddit | ||
r.getSubreddit('test') | ||
.getNewComments() | ||
.then(newComments => { | ||
const newValidComments: Array<Snoowrap.Comment> = []; | ||
|
||
// Get All Valid Comments | ||
newComments.forEach(comment => { | ||
Commands.forEach(command => { | ||
// If the command body includes a handler then push it to `newValidComments` | ||
if (comment.body.indexOf(command.handler) !== 0) { | ||
newValidComments.push(comment); | ||
} | ||
}); | ||
}); | ||
|
||
// Filter the already replied once | ||
newValidComments.forEach(comment => { | ||
let hasPrevReplied = false; | ||
|
||
// Check each reply | ||
comment.replies.forEach(rep => { | ||
// If a reply is authored by the bot username, then ignore it | ||
if (rep.author.name === r.username) { | ||
hasPrevReplied = true; | ||
} | ||
}); | ||
|
||
// If no previous reply, then run the command | ||
if (!hasPrevReplied) { | ||
runCommand(comment); | ||
} | ||
}); | ||
}); | ||
}; | ||
|
||
setInterval(() => { | ||
listenForCommands(); | ||
}, Number(process.env.B_CHECKDELAY) || 60000); |
Oops, something went wrong.