"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.status = exports.unsub = exports.sub = exports.parseCmd = void 0; const fs = require("fs"); const path = require("path"); const datetime_1 = require("./datetime"); 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 sub(chat, args, reply, lock, lockfile) { if (chat.chatType === "temp") { return reply('请先添加机器人为好友。'); } const index = lock.subscribers.findIndex(({ chatID, chatType }) => chat.chatID === chatID && chat.chatType === chatType); if (index > -1) return reply('此聊天已订阅 IDOLY PRIDE BWIKI 更新提醒。'); lock.subscribers.push(chat); logger.warn(`chat ${JSON.stringify(chat)} has subscribed to updates`); fs.writeFileSync(path.resolve(lockfile), JSON.stringify(lock)); reply('已为此聊天订阅 IDOLY PRIDE BWIKI 更新提醒。'); } exports.sub = sub; function unsub(chat, args, reply, lock, lockfile) { if (chat.chatType === "temp") { return reply('请先添加机器人为好友。'); } const index = lock.subscribers.findIndex(({ chatID, chatType }) => chat.chatID === chatID && chat.chatType === chatType); if (index === -1) return reply('此聊天未订阅 IDOLY PRIDE BWIKI 更新提醒。'); lock.subscribers.splice(index, 1); logger.warn(`chat ${JSON.stringify(chat)} has unsubscribed from updates`); fs.writeFileSync(path.resolve(lockfile), JSON.stringify(lock)); reply('已为此聊天退订 IDOLY PRIDE BWIKI 更新提醒。'); } exports.unsub = unsub; function status(chat, _, reply, lock) { const lastAction = lock.lastActions.sort((a1, a2) => Date.parse(a2.timestamp) - Date.parse(a1.timestamp))[0]; reply(`IDOLY PRIDE 官方推特追踪情况: 上次更新时间:${(0, datetime_1.relativeDate)(lastAction.timestamp || '')} 上次更新内容:${(0, twitter_1.parseAction)(lastAction)} 上次检查时间:${(0, datetime_1.relativeDate)(lock.updatedAt || '')}`); } exports.status = status;