Browse Source

Moved config into a seperate module

pull/10/head
Drew Short 5 years ago
parent
commit
41a63558fc
  1. 2
      .dockerignore
  2. 2
      .gitignore
  3. 11
      bot/bot.js
  4. 22
      bot/config.js
  5. 8
      bot/engine.js
  6. 8
      index.js

2
.dockerignore

@ -1,2 +1,2 @@
data/config.json
data/*config.json
log/

2
.gitignore

@ -2,7 +2,7 @@
node_modules/
# Config files
data/config.json
data/*config.json
# Log files
log/

11
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);

22
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

8
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;

8
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();
Loading…
Cancel
Save