fix ratelimit bug, hopefully

This commit is contained in:
2022-03-08 00:27:10 +01:00
parent e74a88ac77
commit 3f38b1504d
4 changed files with 11 additions and 10 deletions
+6 -4
View File
@@ -1,3 +1,5 @@
const debug = process.env.NODE_ENV !== "production";
const axios = require("axios");
const streamConfigCreator = require("../creator/streamConfigCreator");
@@ -17,8 +19,8 @@ const maxCommentLength = 10000;
module.exports = class GenericBot {
constructor(botConfig) {
this.botConfig = botConfig;
this.streamHandler = new StreamHandler(streamConfigCreator.createStreamConfig(botConfig));
this.logger = loggerCreator.createLogger(botConfig.name);
this.streamHandler = new StreamHandler(streamConfigCreator.createStreamConfig(botConfig, debug));
this.logger = loggerCreator.createLogger(botConfig.name, debug);
}
async inboxLoop() {
@@ -32,7 +34,7 @@ module.exports = class GenericBot {
const commentHandler = new CommentHandler(comment, this.logger);
messageHandler.getTextToRespond()
.then(text => this.#getModifiedText(text))
.then(modifiedText => commentHandler.reply(modifiedText))
.then(modifiedText => commentHandler.reply(modifiedText, debug))
.then(reply => {
this.logger.info("Text of reply was: " + reply);
messageHandler.markMessageAsRead();
@@ -53,7 +55,7 @@ module.exports = class GenericBot {
const commentHandler = new CommentHandler(comment, this.logger);
this.logger.info("Post should be replied to.");
this.#getModifiedText(postHandler.getText())
.then(modifiedText => commentHandler.reply(modifiedText))
.then(modifiedText => commentHandler.reply(modifiedText, debug))
.then(reply => this.logger.info("Text of reply was" + reply))
.catch(this.logger.error);
}).catch(this.logger.info);
+1 -3
View File
@@ -1,12 +1,10 @@
const debug = process.env.NODE_ENV === "development";
module.exports = class CommentHandler {
constructor(comment, logger) {
this.comment = comment;
this.logger = logger;
}
async reply(text) {
async reply(text, debug) {
return new Promise((resolve, reject) => {
if (debug) {
reject("Not replying because you are developing");
+2 -2
View File
@@ -1,6 +1,6 @@
const { createLogger, format, transports } = require("winston");
function _createLogger(botName){
function _createLogger(botName,debug){
let logger = createLogger({
level: "info",
format: format.combine(
@@ -31,7 +31,7 @@ function _createLogger(botName){
// If we're in development mode then **ALSO** log to the `console`
// with the colorized simple format.
//
if (process.env.NODE_ENV === "development") {
if (debug) {
logger.add(
new transports.Console({
format: format.combine(format.colorize(), format.simple()),
+2 -1
View File
@@ -3,7 +3,7 @@ const { SubmissionStream, InboxStream } = require("snoostorm");
const Snoowrap = require("snoowrap");
const Snoostorm = require("snoostorm");
function createStreamConfig(botConfig){
function createStreamConfig(botConfig, debug){
const snoowrap = new Snoowrap({
userAgent:
"linux:" + botConfig.name + ":1.0 (by " + botConfig.developers + ")",
@@ -11,6 +11,7 @@ function createStreamConfig(botConfig){
clientSecret: botConfig.clientSecret,
refreshToken: botConfig.refreshToken,
});
snoowrap.config({continueAfterRatelimitError: true, debug})
const submissionStream = new SubmissionStream(snoowrap, {
subreddit: botConfig.subreddit,