diff --git a/.dockerignore b/.dockerignore index 0b2e08c..ba561b3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,2 @@ -data/config.json +data/*config.json log/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index cf70976..bc3e975 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ node_modules/ # Config files -data/config.json +data/*config.json # Log files log/ diff --git a/bot/bot.js b/bot/bot.js index 437d8a2..37a1d92 100644 --- a/bot/bot.js +++ b/bot/bot.js @@ -92,16 +92,7 @@ class Bot { } } -function sanitizeConfig(config) { - let clonedConfig = { ...config }; - clonedConfig.accessToken = "******" - return clonedConfig; -} - -function create(configFile) { - let config = require(configFile); - logger.info("Running with config:"); - logger.debug("%o", sanitizeConfig(config)); +function create(config) { let buildInfo = utility.getBuildInfo("../build.info") logger.info("Running version: %s", buildInfo); return new Bot(config, buildInfo); diff --git a/bot/config.js b/bot/config.js new file mode 100644 index 0000000..ad6fb89 --- /dev/null +++ b/bot/config.js @@ -0,0 +1,22 @@ +let { logger } = require('./logging'); + +var configPath = null; +var config = null; + +function sanitizeConfig(config) { + let clonedConfig = { ...config }; + clonedConfig.accessToken = "******" + return clonedConfig; +} + +function getConfig(configFile) { + if (config === null) { + configPath = configFile; + config = require(configFile); + logger.info("Leaded config:"); + logger.debug("%o", sanitizeConfig(config)); + } + return config; +} + +exports.getConfig = getConfig \ No newline at end of file diff --git a/bot/engine.js b/bot/engine.js index a55fb84..3627dff 100644 --- a/bot/engine.js +++ b/bot/engine.js @@ -2,7 +2,8 @@ let { logger } = require('./logging'); let { modules } = require('./module/index') class Engine { - constructor(bot, modules) { + constructor(config, bot, modules) { + this.config = config this.bot = bot; this.modules = modules; } @@ -14,6 +15,7 @@ class Engine { /* Bind Message Parsing */ let handleMessages = function (event, room, toStartOfTimeline) { if (event.getType() !== "m.room.message") { + logger.debug("Recieved message of type: %s", event.getType()); return; // only use messages } logger.debug("[%s] %s", room.name, event.event.content.body); @@ -53,8 +55,8 @@ class Engine { } } -function create(bot) { - return new Engine(bot, modules) +function create(config, bot) { + return new Engine(config, bot, modules) } exports.create = create; \ No newline at end of file diff --git a/index.js b/index.js index f03dfd1..56f2eaa 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,10 @@ let bot = require('./bot/bot'); -let engine = require('./bot/engine') +let { getConfig } = require('./bot/config'); +let engine = require('./bot/engine'); + +let config = getConfig("../data/config.json") engine.create( - bot.create("../data/config.json") + config, + bot.create(config) ).init().run();