command.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.status = exports.unsub = exports.sub = exports.parseCmd = void 0;
  4. const datetime_1 = require("./datetime");
  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 sub(chat, args, reply, lock, lockfile) {
  27. if (chat.chatType === "temp") {
  28. return reply('请先添加机器人为好友。');
  29. }
  30. const index = lock.subscribers.findIndex(({ chatID, chatType }) => chat.chatID === chatID && chat.chatType === chatType);
  31. if (index > -1)
  32. return reply('此聊天已订阅 IDOLY PRIDE BWIKI 更新提醒。');
  33. lock.subscribers.push(chat);
  34. reply('已为此聊天订阅 IDOLY PRIDE BWIKI 更新提醒。');
  35. }
  36. exports.sub = sub;
  37. function unsub(chat, args, reply, lock, lockfile) {
  38. if (chat.chatType === "temp") {
  39. return reply('请先添加机器人为好友。');
  40. }
  41. const index = lock.subscribers.findIndex(({ chatID, chatType }) => chat.chatID === chatID && chat.chatType === chatType);
  42. if (index === -1)
  43. return reply('此聊天未订阅 IDOLY PRIDE BWIKI 更新提醒。');
  44. lock.subscribers.splice(index, 1);
  45. reply('已为此聊天退订 IDOLY PRIDE BWIKI 更新提醒。');
  46. }
  47. exports.unsub = unsub;
  48. function status(chat, _, reply, lock) {
  49. const lastAction = lock.lastActions.sort((a1, a2) => Date.parse(a2.timestamp) - Date.parse(a1.timestamp))[0];
  50. reply(`IDOLY PRIDE 官方推特追踪情况:
  51. 上次更新时间:${(0, datetime_1.relativeDate)(lastAction.timestamp || '')}
  52. 上次更新内容:${(0, twitter_1.parseAction)(lastAction)}
  53. 上次检查时间:${(0, datetime_1.relativeDate)(lock.updatedAt || '')}`);
  54. }
  55. exports.status = status;