Bladeren bron

leave out retweets and replies, fix date

Mike L 3 jaren geleden
bovenliggende
commit
749516c02c
2 gewijzigde bestanden met toevoegingen van 18 en 20 verwijderingen
  1. 9 10
      dist/twitter.js
  2. 9 10
      src/twitter.ts

+ 9 - 10
dist/twitter.js

@@ -37,12 +37,11 @@ const processTweetBody = (tweet) => {
         .replace(/((?<=\s)#.*?\s+)+$/g, '')
         .trim()
         .match(/(.*?)\n\n(.*)/s).slice(1);
-    const date = new Date(tweet.created_at);
-    const formatedDate = [[date.getFullYear(), 4], [date.getMonth(), 2], [date.getDate(), 2]]
-        .map(([value, padLength]) => value.toString().padStart(padLength, '0'))
-        .join('');
-    const pageTitle = title.replace(/[【】\/]/g, '') + `${exports.recurringKeywords.some(keyword => new RegExp(keyword).exec(title)) ? `-${formatedDate}` : ''}`;
-    return { title, body, pageTitle, date: formatedDate };
+    const date = new Date(tweet.created_at)
+        .toLocaleDateString('en-CA', { timeZone: 'Asia/Tokyo' })
+        .replace(/-/g, '');
+    const pageTitle = title.replace(/[【】\/]/g, '') + `${exports.recurringKeywords.some(keyword => new RegExp(keyword).exec(title)) ? `-${date}` : ''}`;
+    return { title, body, pageTitle, date };
 };
 exports.processTweetBody = processTweetBody;
 const parseAction = (action) => {
@@ -81,7 +80,8 @@ class default_1 {
                 if (match) {
                     config = {
                         screen_name: match[1],
-                        exclude_replies: false,
+                        exclude_replies: true,
+                        include_rts: false,
                         tweet_mode: 'extended',
                     };
                     endpoint = 'statuses/user_timeline';
@@ -145,11 +145,10 @@ class default_1 {
                                     const message = `已更新如下页面:${(0, exports.parseAction)(action)}`;
                                     return Promise.all(this.lock.subscribers.map(subscriber => this.bot.sendTo(subscriber, message)));
                                 }
-                            })
-                                .then(updateDate).then(updateOffset);
+                            });
                         }
                     }
-                }));
+                })).then(updateDate).then(updateOffset);
             })
                 .then(() => {
                 let timeout = this.workInterval * 1000;

+ 9 - 10
src/twitter.ts

@@ -62,14 +62,13 @@ export const processTweetBody = (tweet: Tweet) => {
     .replace(/((?<=\s)#.*?\s+)+$/g, '')
     .trim()
     .match(/(.*?)\n\n(.*)/s).slice(1);
-    const date = new Date(tweet.created_at);
-    const formatedDate = [[date.getFullYear(), 4], [date.getMonth(), 2], [date.getDate(), 2]]
-      .map(([value, padLength]) => value.toString().padStart(padLength, '0'))
-      .join('');
+    const date = new Date(tweet.created_at)
+      .toLocaleDateString('en-CA', {timeZone: 'Asia/Tokyo'})
+      .replace(/-/g, '');
     const pageTitle = title.replace(/[【】\/]/g, '') + `${recurringKeywords.some(
       keyword => new RegExp(keyword).exec(title)
-    ) ? `-${formatedDate}` : ''}`;
-  return {title, body, pageTitle, date: formatedDate};
+    ) ? `-${date}` : ''}`;
+  return {title, body, pageTitle, date};
 };
 
 export const parseAction = (action: WikiEditResult) => {
@@ -146,7 +145,8 @@ export default class {
       if (match) {
         config = {
           screen_name: match[1],
-          exclude_replies: false,
+          exclude_replies: true,
+          include_rts: false,
           tweet_mode: 'extended',
         };
         endpoint = 'statuses/user_timeline';
@@ -208,11 +208,10 @@ export default class {
                     this.lock.subscribers.map(subscriber => this.bot.sendTo(subscriber, message))
                   );
                 }
-              })
-              .then(updateDate).then(updateOffset);
+              });
           }
         }
-      }));
+      })).then(updateDate).then(updateOffset);
     })
       .then(() => {
         let timeout = this.workInterval * 1000;