123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.view = exports.parseCmd = void 0;
- const koishi_1 = require("./koishi");
- const twitter_1 = require("./twitter");
- function parseCmd(message) {
- message = message.trim();
- message = message.replace('\\\\', '\\0x5c');
- message = message.replace('\\\"', '\\0x22');
- message = message.replace('\\\'', '\\0x27');
- const strs = message.match(/'[\s\S]*?'|(?:\S+=)?"[\s\S]*?"|\S+/mg);
- const cmd = (strs === null || strs === void 0 ? void 0 : strs.length) ? strs[0].length ? strs[0].substring(0, 1) === '/' ? strs[0].substring(1) : '' : '' : '';
- const args = (strs !== null && strs !== void 0 ? strs : []).slice(1).map(arg => {
- arg = arg.replace(/^(\S+=)?["']+(?!.*=)|["']+$/g, '$1');
- arg = arg.replace('\\0x27', '\\\'');
- arg = arg.replace('\\0x22', '\\\"');
- arg = arg.replace('\\0x5c', '\\\\');
- return arg;
- });
- return {
- cmd,
- args,
- };
- }
- exports.parseCmd = parseCmd;
- function view(_chat, args, reply) {
- let query = Number(args[0]);
- if (args[0] && !Number.isInteger(query))
- return reply('查询格式有误。\n格式:/nanatsuu_view [〈整数〉]');
- twitter_1.queryByRegExp('t7s_staff', /の『それゆけ!ナナスタ☆通信』第(\d+)話はこちら!/, 3600 * 24 * 7)
- .then(match => {
- if (!match)
- throw Error();
- if (!args[0])
- query = Number(match[1]);
- if (query < 0)
- query += Number(match[1]);
- if (query < 0 || query > Number(match[1])) {
- return reply(`查询取值范围有误。当前可用的取值范围:${-Number(match[1])}~${Number(match[1])}`);
- }
- reply(`第 ${query} 话:\n` +
- koishi_1.Message.Image(`https://d2n19nac4w0gh6.cloudfront.net/resource/images/webview/comic/story/comic_${String(query).padStart(3, '0')}.jpg`));
- }).catch((err) => reply(`查询失败,请稍后重试。${err.message ? `原因:${err}` : ''}`));
- }
- exports.view = view;
|