config.js 793 B

12345678910111213141516171819202122232425262728293031
  1. const path = require('path')
  2. const fs = require('mz/fs')
  3. const json = require('comment-json')
  4. module.exports = async () => {
  5. // try to open ./config.json
  6. let config = json.parse(await fs.readFile('config.json', 'utf8')
  7. .catch(async () => {
  8. // that didn't work
  9. console.error('antipath: failed to open config.json')
  10. // copy config.example.json -> ./config.json
  11. await fs.copyFile(
  12. path.join(__dirname, '..', 'config.example.json'),
  13. 'config.json')
  14. console.error('antipath: created config.json')
  15. // exit with error code
  16. process.exit(1)
  17. }))
  18. // TODO: sanitise more
  19. if (config.discord.botTokens.length === 0) {
  20. console.error('antipath: no discord bots configured, quitting')
  21. process.exit(1)
  22. }
  23. return config
  24. }