From 0a95dea1b6d2cae582ed8ef65eb6efcb656816ac Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Fri, 11 Mar 2022 18:23:24 -0700 Subject: trying to fix undefined again --- twitch-bot/bot.js | 48 ++++++++---------------------------------------- 1 file changed, 8 insertions(+), 40 deletions(-) (limited to 'twitch-bot') diff --git a/twitch-bot/bot.js b/twitch-bot/bot.js index d0220f7..f119771 100644 --- a/twitch-bot/bot.js +++ b/twitch-bot/bot.js @@ -1,48 +1,16 @@ const tmi = require('tmi.js'); const fs = require('fs'); -var settings, reacts, commands, mod_commands; // read settings and reactions json files -fs.readFileSync('./settings.json', 'utf8', (err, data) => { - if (err) { - console.log(`Error reading settings file from disk: ${err}`); - process.exit(1); - } else { - // parse JSON string to JSON object - settings = JSON.parse(data); - } -}); - -fs.readFileSync('./reacts.json', 'utf8', (err, data) => { - if (err) { - console.log(`Error reading reacts file from disk: ${err}`); - process.exit(1); - } else { - // parse JSON string to JSON object - reacts = JSON.parse(data); - } -}); - -fs.readFileSync('./commands.json', 'utf8', (err, data) => { - if (err) { - console.log(`Error reading commands file from disk: ${err}`); - process.exit(1); - } else { - // parse JSON string to JSON object - commands = JSON.parse(data); - } -}); - -fs.readFileSync('./mod_commands.json', 'utf8', (err, data) => { - if (err) { - console.log(`Error reading mod commands file from disk: ${err}`); - process.exit(1); - } else { - // parse JSON string to JSON object - mod_commands = JSON.parse(data); - } -}); +try { + const settings = fs.readFileSync('./settings.json', 'utf8'); + const reacts = fs.readFileSync('./reacts.json', 'utf8'); + const commands = fs.readFileSync('./commands.json', 'utf8'); + const mod_commands = fs.readFileSync('./mod_commands.json', 'utf8'); +} catch (err) { + console.error("An error occured trying to read the files for the Twitch bot: " + err); +} const opts = { identity: { -- cgit v1.2.3