command.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. function sub(chat, args, lock) {
  4. if (args.length === 0) {
  5. return '找不到要订阅的链接。';
  6. }
  7. const link = args[0];
  8. let flag = false;
  9. let match = link.match(/https:\/\/twitter.com\/([^\/]+)\/lists\/([^\/]+)/);
  10. if (match)
  11. flag = true;
  12. else {
  13. match = link.match(/https:\/\/twitter.com\/([^\/]+)/);
  14. if (match)
  15. flag = true;
  16. }
  17. if (!flag) {
  18. return `订阅链接格式错误:
  19. 示例:
  20. https://twitter.com/Saito_Shuka
  21. https://twitter.com/rikakomoe/lists/lovelive`;
  22. }
  23. flag = false;
  24. lock.feed.forEach(fl => {
  25. if (fl === link)
  26. flag = true;
  27. });
  28. if (!flag)
  29. lock.feed.push(link);
  30. if (!lock.threads[link]) {
  31. lock.threads[link] = {
  32. offset: 0,
  33. subscribers: [],
  34. };
  35. }
  36. flag = false;
  37. lock.threads[link].subscribers.forEach(c => {
  38. if (c.chatID === chat.chatID && c.chatType === chat.chatType)
  39. flag = true;
  40. });
  41. if (!flag)
  42. lock.threads[link].subscribers.push(chat);
  43. return `已为此聊天订阅 ${link}`;
  44. }
  45. exports.sub = sub;
  46. function unsub(chat, args, lock) {
  47. if (args.length === 0) {
  48. return '找不到要退订的链接。';
  49. }
  50. const link = args[0];
  51. if (!lock.threads[link]) {
  52. return '您没有订阅此链接。\n' + list(chat, args, lock);
  53. }
  54. let flag = false;
  55. lock.threads[link].subscribers.forEach((c, index) => {
  56. if (c.chatID === chat.chatID && c.chatType === chat.chatType) {
  57. flag = true;
  58. lock.threads[link].subscribers.splice(index, 1);
  59. }
  60. });
  61. if (flag) {
  62. return `已为此聊天退订 ${link}`;
  63. }
  64. return '您没有订阅此链接。\n' + list(chat, args, lock);
  65. }
  66. exports.unsub = unsub;
  67. function list(chat, args, lock) {
  68. const links = [];
  69. Object.keys(lock.threads).forEach(key => {
  70. lock.threads[key].subscribers.forEach(c => {
  71. if (c.chatID === chat.chatID && c.chatType === chat.chatType)
  72. links.push(key);
  73. });
  74. });
  75. return '此聊天中订阅的链接:\n' + links.join('\n');
  76. }
  77. exports.list = list;