Ver código fonte

:ambulance: restrict concurrency

Signed-off-by: LI JIAHAO <lijiahao99131@gmail.com>
LI JIAHAO 6 anos atrás
pai
commit
839dce43ec
4 arquivos alterados com 13 adições e 4 exclusões
  1. 3 1
      dist/twitter.js
  2. 4 1
      dist/webshot.js
  3. 2 1
      src/twitter.ts
  4. 4 1
      src/webshot.ts

+ 3 - 1
dist/twitter.js

@@ -24,7 +24,7 @@ class default_1 {
             if (!lock.threads[lock.feed[lock.workon]] ||
                 !lock.threads[lock.feed[lock.workon]].subscribers ||
                 lock.threads[lock.feed[lock.workon]].subscribers.length === 0) {
-                logger.error(`nobody subscribes thread ${lock.feed[lock.workon]}, removing from feed`);
+                logger.warn(`nobody subscribes thread ${lock.feed[lock.workon]}, removing from feed`);
                 lock.feed.splice(lock.workon, 1);
                 fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
                 this.work();
@@ -64,6 +64,8 @@ class default_1 {
                 if (tweets.length === 0)
                     return;
                 if (lock.threads[lock.feed[lock.workon]].offset !== -1) {
+                    if (lock.threads[lock.feed[lock.workon]].offset === 0)
+                        tweets.splice(1);
                     webshot_1.default(tweets, msg => {
                         lock.threads[lock.feed[lock.workon]].subscribers.forEach(subscriber => {
                             this.bot.bot('send_msg', {

+ 4 - 1
dist/webshot.js

@@ -76,10 +76,13 @@ function fetchImage(url) {
     });
 }
 function default_1(tweets, callback, webshotDelay) {
+    let promise = new Promise(resolve => {
+        resolve();
+    });
     tweets.forEach(twi => {
         let cqstr = '';
         const url = `https://mobile.twitter.com/${twi.user.screen_name}/status/${twi.id_str}`;
-        let promise = renderWebshot(url, 1920, webshotDelay)
+        promise = promise.then(() => renderWebshot(url, 1920, webshotDelay))
             .then(base64Webshot => {
             if (base64Webshot)
                 cqstr += `[CQ:image,file=base64://${base64Webshot}]`;

+ 2 - 1
src/twitter.ts

@@ -57,7 +57,7 @@ export default class {
     if (!lock.threads[lock.feed[lock.workon]] ||
       !lock.threads[lock.feed[lock.workon]].subscribers ||
       lock.threads[lock.feed[lock.workon]].subscribers.length === 0) {
-      logger.error(`nobody subscribes thread ${lock.feed[lock.workon]}, removing from feed`);
+      logger.warn(`nobody subscribes thread ${lock.feed[lock.workon]}, removing from feed`);
       lock.feed.splice(lock.workon, 1);
       fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
       this.work();
@@ -95,6 +95,7 @@ export default class {
     promise.then((tweets: any) => {
       if (tweets.length === 0) return;
       if (lock.threads[lock.feed[lock.workon]].offset !== -1) {
+        if (lock.threads[lock.feed[lock.workon]].offset === 0) tweets.splice(1);
         webshot(tweets, msg => {
           lock.threads[lock.feed[lock.workon]].subscribers.forEach(subscriber => {
             this.bot.bot('send_msg', {

+ 4 - 1
src/webshot.ts

@@ -74,10 +74,13 @@ function fetchImage(url: string): Promise<string> {
 }
 
 export default function (tweets, callback, webshotDelay: number) {
+  let promise = new Promise<void>(resolve => {
+    resolve();
+  });
   tweets.forEach(twi => {
     let cqstr = '';
     const url = `https://mobile.twitter.com/${twi.user.screen_name}/status/${twi.id_str}`;
-    let promise = renderWebshot(url, 1920, webshotDelay)
+    promise = promise.then(() => renderWebshot(url, 1920, webshotDelay))
       .then(base64Webshot => {
         if (base64Webshot) cqstr += `[CQ:image,file=base64://${base64Webshot}]`;
       });