Skip to content

Commit

Permalink
feat: Formatted using gts
Browse files Browse the repository at this point in the history
  • Loading branch information
GalaxyGamingBoy committed Feb 18, 2023
1 parent 09ebf23 commit 18a6db0
Show file tree
Hide file tree
Showing 10 changed files with 4,954 additions and 157 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/gts/"
}
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('gts/.prettierrc.json')
}
128 changes: 64 additions & 64 deletions index.ts
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);
Loading

0 comments on commit 18a6db0

Please sign in to comment.