瀏覽代碼

:bug: bug

Signed-off-by: LI JIAHAO <lijiahao99131@gmail.com>
LI JIAHAO 6 年之前
父節點
當前提交
9f0775197e
共有 4 個文件被更改,包括 56 次插入29 次删除
  1. 28 13
      dist/twitter.js
  2. 1 1
      dist/webshot.js
  3. 26 14
      src/twitter.ts
  4. 1 1
      src/webshot.ts

+ 28 - 13
dist/twitter.js

@@ -111,21 +111,36 @@ class default_1 {
                     lock.threads[lock.feed[lock.workon]].subscribers.forEach(subscriber => {
                         logger.info(`pushing data of thread ${lock.feed[lock.workon]} to ${JSON.stringify(subscriber)}`);
                         const hash = sha1(JSON.stringify(subscriber) + text);
-                        if (this.redisClient && this.redisClient.exists(hash)) {
-                            logger.info('key hash exists, skip this subscriber');
-                            return;
-                        }
-                        this.bot.bot('send_msg', {
-                            message_type: subscriber.chatType,
-                            user_id: subscriber.chatID,
-                            group_id: subscriber.chatID,
-                            discuss_id: subscriber.chatID,
-                            message: msg,
-                        });
+                        const send = () => {
+                            this.bot.bot('send_msg', {
+                                message_type: subscriber.chatType,
+                                user_id: subscriber.chatID,
+                                group_id: subscriber.chatID,
+                                discuss_id: subscriber.chatID,
+                                message: msg,
+                            });
+                        };
                         if (this.redisClient) {
-                            this.redisClient.set(hash, 'true');
-                            this.redisClient.expire(hash, this.redisConfig.redisExpireTime);
+                            this.redisClient.exists(hash, (err, res) => {
+                                logger.debug('redis: ', res);
+                                if (err) {
+                                    logger.error('redis error: ', err);
+                                }
+                                else if (res) {
+                                    logger.info('key hash exists, skip this subscriber');
+                                    return;
+                                }
+                                send();
+                                this.redisClient.set(hash, 'true', 'EX', this.redisConfig.redisExpireTime, (err, res) => {
+                                    logger.debug('redis: ', res);
+                                    if (err) {
+                                        logger.error('redis error: ', err);
+                                    }
+                                });
+                            });
                         }
+                        else
+                            send();
                     });
                 }, this.webshotDelay)
                     .then(() => {

+ 1 - 1
dist/webshot.js

@@ -167,7 +167,7 @@ class Webshot extends CallableInstance {
                     }
                 });
             }
-            promise.then(() => callback(cqstr, twi.full_text));
+            promise.then(() => callback(cqstr, (twi.retweeted_status || twi).full_text));
         });
         return promise;
     }

+ 26 - 14
src/twitter.ts

@@ -149,21 +149,33 @@ export default class {
         lock.threads[lock.feed[lock.workon]].subscribers.forEach(subscriber => {
           logger.info(`pushing data of thread ${lock.feed[lock.workon]} to ${JSON.stringify(subscriber)}`);
           const hash = sha1(JSON.stringify(subscriber) + text);
-          if (this.redisClient && this.redisClient.exists(hash)) {
-            logger.info('key hash exists, skip this subscriber');
-            return;
-          }
-          this.bot.bot('send_msg', {
-            message_type: subscriber.chatType,
-            user_id: subscriber.chatID,
-            group_id: subscriber.chatID,
-            discuss_id: subscriber.chatID,
-            message: msg,
-          });
+          const send = () => {
+            this.bot.bot('send_msg', {
+              message_type: subscriber.chatType,
+              user_id: subscriber.chatID,
+              group_id: subscriber.chatID,
+              discuss_id: subscriber.chatID,
+              message: msg,
+            });
+          };
           if (this.redisClient) {
-            this.redisClient.set(hash, 'true');
-            this.redisClient.expire(hash, this.redisConfig.redisExpireTime);
-          }
+            this.redisClient.exists(hash, (err, res) => {
+              logger.debug('redis: ', res);
+              if (err) {
+                logger.error('redis error: ', err);
+              } else if (res) {
+                logger.info('key hash exists, skip this subscriber');
+                return;
+              }
+              send();
+              this.redisClient.set(hash, 'true', 'EX', this.redisConfig.redisExpireTime, (err, res) => {
+                logger.debug('redis: ', res);
+                if (err) {
+                  logger.error('redis error: ', err);
+                }
+              });
+            });
+          } else send();
         });
       }, this.webshotDelay)
         .then(() => {

+ 1 - 1
src/webshot.ts

@@ -168,7 +168,7 @@ class Webshot extends CallableInstance {
           }
         });
       }
-      promise.then(() => callback(cqstr, twi.full_text));
+      promise.then(() => callback(cqstr, (twi.retweeted_status || twi).full_text));
     });
     return promise;
   }