From 25f68eb23dd53083e84608e2b1af2109d6a260ac Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Mon, 22 Jul 2024 10:43:21 +0200 Subject: Allow failing modules if they miss data files --- modules/email/email.js | 12 +++++++++--- modules/proxy/proxy.js | 8 +++++++- modules/statusbot/statusbot.js | 10 ++++++++-- modules/zelfoverhoor/zelfoverhoor.js | 10 +++++++++- 4 files changed, 33 insertions(+), 7 deletions(-) (limited to 'modules') diff --git a/modules/email/email.js b/modules/email/email.js index e4d342b..d7fe171 100644 --- a/modules/email/email.js +++ b/modules/email/email.js @@ -41,10 +41,16 @@ function sendEmail(recip, text) { } module.exports = function(app, io, moddir) { - var allowedRecipients = - fs.readFileSync(moddir + "/allowed_recipients.txt").toString().trim().split("\n"); + var allowedRecipients, password; - var password = fs.readFileSync(moddir + "/password.txt").toString().trim(); + try { + allowedRecipients = + fs.readFileSync(moddir + "/allowed_recipients.txt").toString().trim().split("\n"); + password = fs.readFileSync(moddir + "/password.txt").toString().trim(); + } catch (e) { + console.error(e); + return false; + } app.post("/email", bodyParser.json(), function(req, res) { var body = req.body; diff --git a/modules/proxy/proxy.js b/modules/proxy/proxy.js index 49caf54..ccec53a 100644 --- a/modules/proxy/proxy.js +++ b/modules/proxy/proxy.js @@ -29,9 +29,15 @@ function objectFromList(l){ } module.exports=function(app,io,moddir){ - var iddict=objectFromList( + var iddict; + try { + iddict=objectFromList( fs.readFileSync(moddir+"/idfile.txt").toString() .split("\n").map(function(r){return r.split(" ");})); + } catch (e) { + console.error(e); + return false; + } app.all("/proxy/:id/*",function(req,res){ var id=req.params.id; diff --git a/modules/statusbot/statusbot.js b/modules/statusbot/statusbot.js index 1af5804..a518b17 100644 --- a/modules/statusbot/statusbot.js +++ b/modules/statusbot/statusbot.js @@ -272,8 +272,14 @@ function matrixSendMsgLogin(text, cb) { module.exports = function(app, io, _moddir) { moddir = _moddir; - const config = require("./matrix.json"); - const accounts = require("./accounts.json"); + let config, accounts; + try { + config = require("./matrix.json"); + accounts = require("./accounts.json"); + } catch (e) { + console.error(e); + return false; + } const ratelimit = new PRatelimit(1000); diff --git a/modules/zelfoverhoor/zelfoverhoor.js b/modules/zelfoverhoor/zelfoverhoor.js index 03de63c..0acb322 100644 --- a/modules/zelfoverhoor/zelfoverhoor.js +++ b/modules/zelfoverhoor/zelfoverhoor.js @@ -6,7 +6,12 @@ var moddir; var dbdir=cmn.persistdir+"/zelfoverhoor"; mkdirp.sync(dbdir); -var accounts=require("./accounts.json"); +var accounts=null; +try { + accounts=require("./accounts.json"); +} catch (e) { + console.error(e); +} var SHUFFLE_QUESTIONS=false; @@ -97,6 +102,9 @@ function canAccessFile(fname){ module.exports=function(app,io,_moddir){ moddir=_moddir; + // Failed to load accounts.json + if(accounts==null)return false; + if(canAccessFile(dbdir+"/questiondb.json")&&canAccessFile(dbdir+"/questionsets.json")&&canAccessFile(dbdir+"/userlists.json")){ questiondb=JSON.parse(fs.readFileSync(dbdir+"/questiondb.json")); questionsets=JSON.parse(fs.readFileSync(dbdir+"/questionsets.json")); -- cgit v1.2.3-70-g09d2