"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.picSearch = exports.search = exports.parseCmd = void 0; const loggers_1 = require("./loggers"); const twitter_1 = require("./twitter"); const logger = (0, loggers_1.getLogger)('command'); 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 search(chat, args, reply) { if (args.length === 0 || !args[0]) { return reply('未输入自定义查询表达式。'); } const conf = { query: args[0] }; const confZH = { count: '数量上限', since: '起始点', until: '结束点', }; for (const arg of args.slice(1)) { const optMatch = /^(count|since|until)=(.*)/.exec(arg); if (!optMatch) return reply(`未定义的查询参数:${arg}。`); const optKey = optMatch[1]; if (optMatch.length === 1) return reply(`查询${confZH[optKey]}参数格式有误。`); conf[optKey] = optMatch[2]; if (optMatch[2] === '') return reply(`查询${confZH[optKey]}参数值不可为空。`); } if (conf.count !== undefined && !Number(conf.count) || Number(conf.count) > 100) { return reply('查询数量上限参数非正、非数值或超出取值范围。'); } try { (0, twitter_1.doSearch)(conf, chat); } catch (e) { logger.error(`error querying timeline, error: ${e}`); reply('推特机器人尚未加载完毕,请稍后重试。'); } } exports.search = search; function picSearch(chat, args, reply) { search(chat, [args[0] && args[0] + '(filter:media)', ...args.slice(1)], reply); } exports.picSearch = picSearch;