Browse Source

add option to resume on start (fetch missed tweets)

Mike L 4 years ago
parent
commit
dc8ccfa206
4 changed files with 18 additions and 6 deletions
  1. 1 0
      README.md
  2. 1 0
      config.example.json
  3. 8 3
      dist/main.js
  4. 8 3
      src/main.ts

+ 1 - 0
README.md

@@ -25,6 +25,7 @@
 | twitter_access_token_key | Twitter App access_token_key | (必填) |
 | twitter_access_token_secret | Twitter App access_token_secret | (必填) |
 | mode | 工作模式,0 为图文模式,1 为纯文本模式,2 为文本附图模式 | 0 |
+| resume_on_start | 是否在启动时继续退出时的进度(拉取本应用非活动时期错过的推文) | false |
 | work_interval | 对单个订阅两次拉取更新的最少间隔时间(秒) | 60 |
 | webshot_delay | 抓取网页截图时等待网页加载的延迟时长(毫秒) | 5000 |
 | lockfile | 本地保存订阅信息以便下次启动时恢复 | subscriber.lock |

+ 1 - 0
config.example.json

@@ -8,6 +8,7 @@
   "twitter_access_token_key": "",
   "twitter_access_token_secret": "",
   "mode": 0,
+  "resume_on_start": false,
   "work_interval": 60,
   "webshot_delay": 5000,
   "lockfile": "subscriber.lock",

+ 8 - 3
dist/main.js

@@ -79,6 +79,9 @@ if (config.loglevel === undefined) {
 if (typeof config.mode !== 'number') {
     config.mode = 0;
 }
+if (typeof config.resume_on_start !== 'boolean') {
+    config.resume_on_start = false;
+}
 loggers_1.setLogLevels(config.loglevel);
 let lock;
 if (fs.existsSync(path.resolve(config.lockfile))) {
@@ -114,9 +117,11 @@ else {
         process.exit(1);
     }
 }
-Object.keys(lock.threads).forEach(key => {
-    lock.threads[key].offset = '-1';
-});
+if (!config.resume_on_start) {
+    Object.keys(lock.threads).forEach(key => {
+        lock.threads[key].offset = '-1';
+    });
+}
 const qq = new mirai_1.default({
     access_token: config.mirai_access_token,
     host: config.mirai_http_host,

+ 8 - 3
src/main.ts

@@ -86,6 +86,9 @@ if (config.loglevel === undefined) {
 if (typeof config.mode !== 'number') {
   config.mode = 0;
 }
+if (typeof config.resume_on_start !== 'boolean') {
+  config.resume_on_start = false;
+}
 
 setLogLevels(config.loglevel);
 
@@ -121,9 +124,11 @@ if (fs.existsSync(path.resolve(config.lockfile))) {
   }
 }
 
-Object.keys(lock.threads).forEach(key => {
-  lock.threads[key].offset = '-1';
-});
+if (!config.resume_on_start) {
+  Object.keys(lock.threads).forEach(key => {
+    lock.threads[key].offset = '-1';
+  });
+}
 
 const qq = new QQBot({
   access_token: config.mirai_access_token,