diff --git a/package.json b/package.json index 2255cc7..e069b05 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "discord-bot", "type": "module", - "version": "0.3.2", + "version": "0.3.3", "description": "", "main": "index.js", "scripts": { diff --git a/src/bot.ts b/src/bot.ts index 10ea783..639f809 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -48,7 +48,11 @@ process.on("uncaughtException", (error) => { const client = new Client({ intents: [GatewayIntentBits.Guilds] }); const redisClient = createClient(redisConfig); + + redisClient.on("error", (err) => log.error("Redis Client Error", err)); + await redisClient.connect(); + redisClient.on("connect", () => log.info("Connected to Redis server")); const rest = new REST({ version: "10" }).setToken(discordConfig.token); diff --git a/src/config.js b/src/config.js index aacba8d..30b6ef4 100644 --- a/src/config.js +++ b/src/config.js @@ -1,4 +1,5 @@ import package_json from "../package.json" with { type: "json" }; +import log from "./logger"; import dotenv from "dotenv"; dotenv.config({ path: `.env.local`, override: true }); @@ -10,6 +11,16 @@ export const redisConfig = { socket: { host: process.env.REDIS_HOST, port: process.env.REDIS_PORT, + reconnectStrategy: function (retries) { + if (retries >= 20) { + log.error("Unable to reconnect to Redis reconnectStrategy"); + process.exit(1); + } + return Math.max(retries * 500, 4000); + }, + connectTimeout: 10000, + keepAlive: true, + keepAliveInterval: 5000, }, tls: true, }; diff --git a/src/lib/makeSurveyPost.js b/src/lib/makeSurveyPost.js index 23d3f82..cee575e 100644 --- a/src/lib/makeSurveyPost.js +++ b/src/lib/makeSurveyPost.js @@ -9,7 +9,11 @@ export const makeSurveyPost = async ( if (!(await redisClient.sIsMember("surveys", surveyName))) { return [{ content: "There is no survey with that name", ephemeral: true }]; } else { - const [msg, files] = await surveyToText(redisClient, surveyName, isSummaryCommand); + const [msg, files] = await surveyToText( + redisClient, + surveyName, + isSummaryCommand, + ); const lines = msg.split("\n"); const chunks = [];