Forráskód Böngészése

fix not saving lockfile after subscription

Mike L 3 éve
szülő
commit
6b829694f6
2 módosított fájl, 17 hozzáadás és 0 törlés
  1. 8 0
      dist/command.js
  2. 9 0
      src/command.ts

+ 8 - 0
dist/command.js

@@ -1,8 +1,12 @@
 "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');
@@ -31,6 +35,8 @@ function sub(chat, args, reply, lock, lockfile) {
     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;
@@ -42,6 +48,8 @@ function unsub(chat, args, reply, lock, lockfile) {
     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;

+ 9 - 0
src/command.ts

@@ -1,10 +1,15 @@
 /* eslint-disable @typescript-eslint/no-unsafe-return */
 /* eslint-disable @typescript-eslint/member-delimiter-style */
 /* eslint-disable prefer-arrow/prefer-arrow-functions */
+import * as fs from 'fs';
+import * as path from 'path';
 
 import { relativeDate } from './datetime';
+import { getLogger } from './loggers';
 import { parseAction } from './twitter';
 
+const logger = getLogger('command');
+
 function parseCmd(message: string): {
   cmd: string;
   args: string[];
@@ -39,6 +44,8 @@ function sub(chat: IChat, args: string[], reply: (msg: string) => any,
   );
   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 更新提醒。');
 }
 
@@ -53,6 +60,8 @@ function unsub(chat: IChat, args: string[], reply: (msg: string) => any,
   );
   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 更新提醒。');
 }