summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorTom Smeding <t.j.smeding@uu.nl>2024-07-22 10:43:21 +0200
committerTom Smeding <t.j.smeding@uu.nl>2024-07-22 10:43:21 +0200
commit25f68eb23dd53083e84608e2b1af2109d6a260ac (patch)
tree1d3f7e8b64e5cac8c23dc57bb68b214e26c77569 /modules
parent9a41d980622b449d41999dc8f46226c1879e00ef (diff)
Allow failing modules if they miss data files
Diffstat (limited to 'modules')
-rw-r--r--modules/email/email.js12
-rw-r--r--modules/proxy/proxy.js8
-rw-r--r--modules/statusbot/statusbot.js10
-rw-r--r--modules/zelfoverhoor/zelfoverhoor.js10
4 files changed, 33 insertions, 7 deletions
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"));