Advertisement
AffeMitWaffe07

Untitled

Apr 20th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 2.04 KB | None | 0 0
  1. const fs = require('fs')
  2. const Logger = require('../util/logger')
  3. const util = require('util')
  4.  
  5. const CONF_TEMPLATE = {
  6.     token: "NDM2ODkzMzAzMTMzMzA2ODkw********Gjge7M-2-NojTULANli7IhSTbXQ",
  7.     giphy_key: "",
  8.     youtube_api_key: "",
  9.     pastebin_api_key: "",
  10.     prefix: "zb:",
  11.     hostid: "",
  12.     logcmds: true,
  13.     mysql: {
  14.         host: "localhost",
  15.         user: "",
  16.         password: "",
  17.         database: "",
  18.     },
  19.     exp: {
  20.         interval: 10,
  21.         xpinterval: 15,
  22.         xpmsgmultiplier: 150,
  23.         flatter: 100,
  24.         cap: 0.8,
  25.         delta: 1.2,
  26.         startlvl: 1000,
  27.         reports: [
  28.             10000,
  29.             5
  30.         ]
  31.     }
  32. }
  33.  
  34.  
  35. class Config {
  36.  
  37.     constructor(conf_file) {
  38.         this.conf_file = conf_file ? conf_file : "config.json"
  39.         this.load()
  40.     }
  41.  
  42.     load() {
  43.         if (fs.existsSync(this.conf_file)) {
  44.             let config_raw = fs.readFileSync(this.conf_file, 'utf8')
  45.                 .replace(/((\/\*)((.|\n)[^\*\/])*(\*\/))|(\s*(\/\/).*)/gm, '')
  46.             try {
  47.                 this.config = JSON.parse(config_raw)
  48.             }
  49.             catch (e) {
  50.                 Logger.error("Could not parse config.json. Please delete or rename the file and restart the porgram to regenerate a new template.")
  51.                 process.exit()
  52.             }
  53.         }
  54.         else {
  55.             this.create()
  56.             Logger.error("Config file not existent and was generated. Please edit the config and restart.")
  57.             process.exit()
  58.         }
  59.     }
  60.  
  61.     create() {
  62.         let out = '/*\n' +
  63.                   '    If you need help creating the config, take a look into the wiki page:\n' +
  64.                   '    https://github.com/zekroTJA/zekroBot2/wiki/Config-Explaination\n' +
  65.                   '*/\n\n\n';
  66.         out += JSON.stringify(CONF_TEMPLATE, null, 2)
  67.         fs.writeFileSync(this.conf_file, out)
  68.     }
  69.  
  70.     getConfig() {
  71.         Logger.debug(util.inspect(this.config))
  72.         return this.config
  73.     }
  74.  
  75. }
  76.  
  77. exports.Config = Config
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement