command.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.view = exports.parseCmd = void 0;
  4. const koishi_1 = require("./koishi");
  5. function parseCmd(message) {
  6. message = message.trim();
  7. message = message.replace('\\\\', '\\0x5c');
  8. message = message.replace('\\\"', '\\0x22');
  9. message = message.replace('\\\'', '\\0x27');
  10. const strs = message.match(/'[\s\S]*?'|(?:\S+=)?"[\s\S]*?"|\S+/mg);
  11. const cmd = (strs === null || strs === void 0 ? void 0 : strs.length) ? strs[0].length ? strs[0].substring(0, 1) === '/' ? strs[0].substring(1) : '' : '' : '';
  12. const args = (strs !== null && strs !== void 0 ? strs : []).slice(1).map(arg => {
  13. arg = arg.replace(/^(\S+=)?["']+(?!.*=)|["']+$/g, '$1');
  14. arg = arg.replace('\\0x27', '\\\'');
  15. arg = arg.replace('\\0x22', '\\\"');
  16. arg = arg.replace('\\0x5c', '\\\\');
  17. return arg;
  18. });
  19. return {
  20. cmd,
  21. args,
  22. };
  23. }
  24. exports.parseCmd = parseCmd;
  25. function view(chat, args, reply) {
  26. if (args.length === 0) {
  27. return reply('找不到要查看的回数。');
  28. }
  29. const match = Number(args[0]);
  30. if (match < 1 || match > 999) {
  31. return reply('链接格式有误。');
  32. }
  33. try {
  34. reply(koishi_1.Message.Image(`https://d2n19nac4w0gh6.cloudfront.net/resource/images/webview/comic/story/comic_${String(match).padStart(3, '0')}.jpg`));
  35. }
  36. catch (e) {
  37. reply('机器人尚未加载完毕,请稍后重试。');
  38. }
  39. }
  40. exports.view = view;