let message = require('./message'); let utility = require('./utility'); let { logger } = require('./logging'); let { modules } = require('./module/index') class Bot { constructor(config, buildInfo, modules) { this.config = config; this.buildInfo = buildInfo; this.connected = false; this.modules = modules; } initModules() { modules.forEach((module) => { logger.info("Loading module: %s", module.name); }); } sendStatusStartup() { let promises = [Promise.resolve(true)] if (this.connected) { this.config.statusRooms.forEach(roomId => { logger.debug("Notifying %s of startup", roomId); promises.push(this.client.sendMessage( roomId, message.createBasic("Started with version: " + this.buildInfo, message.types.NOTICE) ).then(() => { logger.debug("Notified %s of startup", roomId); })); }); } else { logger.warn("Attempting to send startup message while disconnected"); } return Promise.all(promises); } sendStatusShutdown() { let promises = [Promise.resolve(true)] if (this.connected) { this.config.statusRooms.forEach(roomId => { logger.debug("Notifying %s of shutdown", roomId); promises.push(this.client.sendMessage( roomId, message.createBasic("Shutting down", message.types.NOTICE) ).then(() => { logger.debug("Notified %s of shutdown", roomId); })); }); } else { logger.warn("Attempting to send shutdown message while disconnected"); } return Promise.all(promises); } } 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)); let buildInfo = utility.getBuildInfo("../build.info") logger.info("Running version: %s", buildInfo); return new Bot(config, buildInfo, modules); } exports.create = create;