From 1f2c7fa8357fb32d803f18725d0d536ac2aaa3db Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Tue, 11 Dec 2012 20:23:31 +0000 Subject: [PATCH] added try/catch for no usage/string info, moved module load error back to default stringspace --- modules/admin/strings.json | 6 ------ run.js | 36 ++++++++++++++++++++++-------------- strings.json | 6 ++++++ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/modules/admin/strings.json b/modules/admin/strings.json index 553a096..8ecacd0 100644 --- a/modules/admin/strings.json +++ b/modules/admin/strings.json @@ -64,11 +64,5 @@ "spanish": "Cerrado la categoría: {category}", "na'vi": "{category}ìri oel 'upxareti fmoli", "welsh": "Categori wedi cloi: {category}" - }, - "module_load_error": { - "english": "Failed to load module: {moduleName}", - "spanish": "No se pudó cargar el módulo: {moduleName}", - "na'vi": "Oeru Oel {moduleName}it sung.", - "welsh": "Wedi methu a llwytho modiwl: {moduleName}" } } diff --git a/run.js b/run.js index 80b65e1..129518a 100644 --- a/run.js +++ b/run.js @@ -200,27 +200,35 @@ DBot.prototype.reloadModules = function() { } // Load the module usage data - var usage = JSON.parse(fs.readFileSync(moduleDir + 'usage.json', 'utf-8')); - for(key in usage) { - if(usage.hasOwnProperty(key)) { - if(this.usage.hasOwnProperty(key)) { - console.log('Usage key clash for ' + key + ' in ' + name); - } else { - this.usage[key] = usage[key]; + try { + var usage = JSON.parse(fs.readFileSync(moduleDir + 'usage.json', 'utf-8')); + for(key in usage) { + if(usage.hasOwnProperty(key)) { + if(this.usage.hasOwnProperty(key)) { + console.log('Usage key clash for ' + key + ' in ' + name); + } else { + this.usage[key] = usage[key]; + } } } + } catch(err) { + // Invalid or no usage info } // Load the module string data - var strings = JSON.parse(fs.readFileSync(moduleDir + 'strings.json', 'utf-8')); - for(key in strings) { - if(strings.hasOwnProperty(key)) { - if(this.strings.hasOwnProperty(key)) { - console.log('Strings key clash for ' + key + ' in ' + name); - } else { - this.strings[key] = strings[key]; + try { + var strings = JSON.parse(fs.readFileSync(moduleDir + 'strings.json', 'utf-8')); + for(key in strings) { + if(strings.hasOwnProperty(key)) { + if(this.strings.hasOwnProperty(key)) { + console.log('Strings key clash for ' + key + ' in ' + name); + } else { + this.strings[key] = strings[key]; + } } } + } catch(err) { + // Invalid or no string info } this.modules.push(module); diff --git a/strings.json b/strings.json index f7eb20c..630e213 100644 --- a/strings.json +++ b/strings.json @@ -5,6 +5,12 @@ "na'vi": "Srake sweylu nga pamrel sivi: ", "welsh": "A oeddech chi'n feddwl: " }, + "module_load_error": { + "english": "Failed to load module: {moduleName}", + "spanish": "No se pudó cargar el módulo: {moduleName}", + "na'vi": "Oeru Oel {moduleName}it sung.", + "welsh": "Wedi methu a llwytho modiwl: {moduleName}" + }, "url": { "english": "http://{host}:{port}/{path}" }