command.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.view = exports.parseCmd = void 0;
  4. const koishi_1 = require("./koishi");
  5. const twitter_1 = require("./twitter");
  6. function parseCmd(message) {
  7. message = message.trim();
  8. message = message.replace('\\\\', '\\0x5c');
  9. message = message.replace('\\\"', '\\0x22');
  10. message = message.replace('\\\'', '\\0x27');
  11. const strs = message.match(/'[\s\S]*?'|(?:\S+=)?"[\s\S]*?"|\S+/mg);
  12. const cmd = (strs === null || strs === void 0 ? void 0 : strs.length) ? strs[0].length ? strs[0].substring(0, 1) === '/' ? strs[0].substring(1) : '' : '' : '';
  13. const args = (strs !== null && strs !== void 0 ? strs : []).slice(1).map(arg => {
  14. arg = arg.replace(/^(\S+=)?["']+(?!.*=)|["']+$/g, '$1');
  15. arg = arg.replace('\\0x27', '\\\'');
  16. arg = arg.replace('\\0x22', '\\\"');
  17. arg = arg.replace('\\0x5c', '\\\\');
  18. return arg;
  19. });
  20. return {
  21. cmd,
  22. args,
  23. };
  24. }
  25. exports.parseCmd = parseCmd;
  26. function view(_chat, args, reply) {
  27. twitter_1.queryByRegExp('t7s_staff', /今週の『それゆけ!ナナスタ☆通信』第(\d+)話はこちら!/, 3600 * 24 * 6)
  28. .then(match => {
  29. if (!match)
  30. throw Error();
  31. let query = Number(args[0] || Number(match[1]));
  32. if (query < 0)
  33. query += Number(match[1]);
  34. if (args[0] === '0' || query < 0 || query > Number(match[1])) {
  35. return reply(`查询取值范围有误。当前可用的取值范围:1~${Number(match[1])}`);
  36. }
  37. reply(`第 ${query} 话:\n` +
  38. koishi_1.Message.Image(`https://d2n19nac4w0gh6.cloudfront.net/resource/images/webview/comic/story/comic_${String(query).padStart(3, '0')}.jpg`));
  39. }).catch((err) => reply(`查询失败,请稍后重试。${err.message ? `原因:${err}` : ''}`));
  40. }
  41. exports.view = view;