Ver código fonte

Merge branch 'koishi' into mediaonly-koishi

Mike L 4 anos atrás
pai
commit
11df33e9f7
4 arquivos alterados com 12 adições e 8 exclusões
  1. 5 3
      dist/koishi.js
  2. 1 1
      dist/webshot.js
  3. 5 3
      src/koishi.ts
  4. 1 1
      src/webshot.ts

+ 5 - 3
dist/koishi.js

@@ -37,7 +37,8 @@ class default_1 {
         this.next = (type, id) => {
             const queue = this.messageQueues[`${type}:${id}`];
             if (queue && queue.length) {
-                queue[0]().then(() => queue.shift()).then(() => {
+                queue[0]().then(() => {
+                    queue.shift();
                     if (!queue.length)
                         delete this.messageQueues[`${type}:${id}`];
                     else
@@ -47,10 +48,11 @@ class default_1 {
         };
         this.enqueue = (type, id, resolver) => {
             var _a, _b;
-            const queue = (_a = this.messageQueues)[_b = `${type}:${id}`] || (_a[_b] = []);
+            let wasEmpty = false;
+            const queue = (_a = this.messageQueues)[_b = `${type}:${id}`] || (_a[_b] = (() => { wasEmpty = true; return []; })());
             queue.push(() => koishi_1.sleep(200).then(resolver));
             logger.debug(`no. of message currently queued for ${type}:${id}: ${queue.length}`);
-            if (queue.length === 1)
+            if (wasEmpty)
                 this.next(type, id);
         };
         this.getChat = (session) => __awaiter(this, void 0, void 0, function* () {

+ 1 - 1
dist/webshot.js

@@ -80,7 +80,7 @@ class Webshot extends CallableInstance {
                     })
                         .then(() => page.goto(url, { waitUntil: 'load', timeout: getTimeout() }))
                         .then(() => page.addStyleTag({
-                        content: 'header{display:none!important}div[role=\'button\'],[data-testid="tweet"]+*>[class*=" "]+*{display:none}',
+                        content: 'header{display:none!important}[data-testid="caret"],[data-testid="tweet"]+*>:nth-last-child(-n+2){display:none}',
                     }))
                         .then(() => page.addStyleTag({
                         content: '*{font-family:-apple-system,".Helvetica Neue DeskInterface",Hiragino Sans,Hiragino Sans GB,sans-serif!important}',

+ 5 - 3
src/koishi.ts

@@ -47,7 +47,8 @@ export default class {
   private next = (type: 'private' | 'group', id: string) => {
     const queue = this.messageQueues[`${type}:${id}`];
     if (queue && queue.length) {
-      queue[0]().then(() => queue.shift()).then(() => {
+      queue[0]().then(() => {
+        queue.shift();
         if (!queue.length) delete this.messageQueues[`${type}:${id}`];
         else this.next(type, id);
       });
@@ -55,10 +56,11 @@ export default class {
   };
 
   private enqueue = (type: 'private' | 'group', id: string, resolver: () => Promise<void>) => {
-    const queue = this.messageQueues[`${type}:${id}`] ||= [];
+    let wasEmpty = false;
+    const queue = this.messageQueues[`${type}:${id}`] ||= (() => { wasEmpty = true; return []; })();
     queue.push(() => sleep(200).then(resolver));
     logger.debug(`no. of message currently queued for ${type}:${id}: ${queue.length}`);
-    if (queue.length === 1) this.next(type, id);
+    if (wasEmpty) this.next(type, id);
   };
 
   private getChat = async (session: Session): Promise<IChat> => {

+ 1 - 1
src/webshot.ts

@@ -103,7 +103,7 @@ class Webshot extends CallableInstance<[Tweets, (...args) => void, number], Prom
             .then(() => page.goto(url, {waitUntil: 'load', timeout: getTimeout()}))
             // hide header, "more options" button, like and retweet count
             .then(() => page.addStyleTag({
-              content: 'header{display:none!important}div[role=\'button\'],[data-testid="tweet"]+*>[class*=" "]+*{display:none}',
+              content: 'header{display:none!important}[data-testid="caret"],[data-testid="tweet"]+*>:nth-last-child(-n+2){display:none}',
             }))
             .then(() => page.addStyleTag({
               content: '*{font-family:-apple-system,".Helvetica Neue DeskInterface",Hiragino Sans,Hiragino Sans GB,sans-serif!important}',