main.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env node
  2. "use strict";
  3. Object.defineProperty(exports, "__esModule", { value: true });
  4. const commandLineUsage = require("command-line-usage");
  5. const log4js = require("log4js");
  6. const path = require("path");
  7. const logger = log4js.getLogger();
  8. logger.level = 'info';
  9. const sections = [
  10. {
  11. header: 'CQHTTP Twitter Bot',
  12. content: 'The QQ Bot that forwards twitters.'
  13. },
  14. {
  15. header: 'Synopsis',
  16. content: [
  17. '$ cqhttp-twitter-bot {underline config.json}',
  18. '$ cqhttp-twitter-bot {bold --help}'
  19. ]
  20. },
  21. {
  22. header: 'Documentation',
  23. content: [
  24. 'Project home: {underline https://github.com/rikakomoe/cqhttp-twitter-bot}',
  25. 'Example config: {underline https://qwqq.pw/b96yt}'
  26. ]
  27. }
  28. ];
  29. const usage = commandLineUsage(sections);
  30. const args = process.argv.slice(2);
  31. if (args.length === 0 || args[0] === 'help' || args[0] === '-h' || args[0] === '--help') {
  32. console.log(usage);
  33. process.exit(0);
  34. }
  35. const configPath = args[0];
  36. let config;
  37. try {
  38. config = require(path.resolve(configPath));
  39. }
  40. catch (e) {
  41. console.log("Failed to parse config file: ", configPath);
  42. console.log(usage);
  43. process.exit(1);
  44. }
  45. console.log(config);