Prechádzať zdrojové kódy

:memo: doc and fix

Signed-off-by: LI JIAHAO <lijiahao99131@gmail.com>
LI JIAHAO 6 rokov pred
rodič
commit
fe92e261f8
5 zmenil súbory, kde vykonal 108 pridanie a 2 odobranie
  1. 7 0
      LICENSE
  2. 79 0
      README.md
  3. 3 1
      dist/twitter.js
  4. 15 0
      package.json
  5. 4 1
      src/twitter.ts

+ 7 - 0
LICENSE

@@ -0,0 +1,7 @@
+Copyright 2018 梨子
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 79 - 0
README.md

@@ -0,0 +1,79 @@
+# CQHTTP Twitter Bot
+
+是一个可以订阅 Twitter 并转发到 QQ 的 Bot。
+
+## 安装
+
+```bash
+npm install -g cqhttp-twitter-bot
+yarn global add  cqhttp-twitter-bot
+```
+
+当然还需要配合 [coolq-http-api](https://github.com/richardchien/coolq-http-api) 和 [酷Q](https://cqp.cc/) 才能工作。  
+它们是什么?  
+观察它们的文档:[https://cqhttp.cc/](https://cqhttp.cc/) [https://cqp.cc/t/15124](https://cqp.cc/t/15124)
+
+## 食用
+
+```bash
+$ cqhttp-twitter-bot config.json
+```
+
+## 配置
+
+它会从命令传入的 JSON 配置文件里读取配置,配置说明如下
+
+| 配置项 | 说明 | 默认 |
+| --- | --- | --- |
+| cq_ws_host | CQHTTP Websocket 服务端地址 | 127.0.0.1 |
+| cq_ws_port | CQHTTP Websocket 服务端口 | 6700 |
+| cq_access_token | CQHTTP access_token | (空) |
+| twitter_consumer_key | Twitter App consumer_key | (必填) |
+| twitter_consumer_secret |  Twitter App consumer_secret | (必填) |
+| twitter_access_token_key | Twitter App access_token_key | (必填) |
+| twitter_access_token_secret | Twitter App access_token_secret | (必填) |
+| work_interval | 对单个订阅两次拉取更新的最少间隔时间(秒) | 60 |
+| webshot_delay | 抓取网页截图时等待网页加载的延迟时长(毫秒) | 5000 |
+| lockfile | 本地保存订阅信息以便下次启动时恢复 | subscriber.lock |
+| loglevel | 日志调试等级 | info |
+
+示例文件在 `config.example.json`
+
+## 命令
+
+Bot 启动了以后就可以在 QQ 里用命令了。命令有:
+
+- /twitter - 列出当前会话的订阅
+- /twitter_subscribe [链接] - 订阅
+- /twitter_unsubscribe [链接] - 退订
+
+链接可以是一个个人的时间轴或者是列表, 例如:
+
+个人:https://twitter.com/Saito_Shuka  
+列表:https://twitter.com/rikakomoe/lists/lovelive
+
+必须是这个模式才行 qvq
+
+## 其他说明
+
+1. Twitter 这两个(时间轴和列表) API 对单个应用的限制是 900次/15min,
+也就是最快可以 1s 一次。这个 Bot 的工作方式是轮流拉取,即:
+每次从队首拿出任务,完成后放到队尾。在不达到 1s 一次的前提下,
+总体请求速度会随着订阅量的增加而加快:例如当 work_interval 设置为 60 时,
+如果只有 1 个订阅,那么每分钟只有 1 个请求。如果有 2 个订阅,每分钟则有 2 个请求。
+如果有 70 个订阅,每分钟仍然只有 60 个请求。
+
+2. 上面说的每分钟之类指的是休眠的时长,工作时间不算在内。因此实际的 API 调用
+频率要比这个低。
+
+3. webshot_delay 如果设成 0 的话肯定不行的,会出现正在加载的界面。这个具体多
+少最合适可以自己试,5 秒应该是比较保险了。
+
+4. 如果在同一个聊天里的会话有重复,不会被去重。例如在某聊天中同时订阅了特朗普和
+包含特朗普的列表 A,那么每次特朗普发推你都会收到两条一样的推送。这个是因为 API 的构造
+本身决定的,要是给你去重的话还得存给你推过哪些,很麻烦,懒得做,意义不大,就注意不要
+这样就好了。
+
+5. 列表中是没有回复的。实际上你看 Twitter 的列表本来也没有回复。个人的时间轴会显示
+回复。
+

+ 3 - 1
dist/twitter.js

@@ -64,8 +64,10 @@ class default_1 {
             });
             promise.then((tweets) => {
                 logger.debug(`api returned ${JSON.stringify(tweets)} for feed ${lock.feed[lock.workon]}`);
-                if (tweets.length === 0)
+                if (tweets.length === 0) {
+                    lock.threads[lock.feed[lock.workon]].updatedAt = new Date().toString();
                     return;
+                }
                 if (lock.threads[lock.feed[lock.workon]].offset === -1) {
                     lock.threads[lock.feed[lock.workon]].offset = tweets[0].id_str;
                     return;

+ 15 - 0
package.json

@@ -1,7 +1,22 @@
 {
+  "name": "cqhttp-twitter-bot",
+  "version": "1.0.0",
+  "description": "CQHTTP Twitter Bot",
+  "main": "./dist/main.js",
   "bin": {
     "cqhttp-twitter-bot": "./dist/main.js"
   },
+  "repository": {
+    "type": "git",
+    "url": "https://github.com/rikakomoe/cqhttp-twitter-bot.git"
+  },
+  "keywords": ["cq", "qq", "qqbot", "cqhttp", "twitter"],
+  "author": "Riko",
+  "license": "MIT",
+  "bugs": {
+    "url": "https://github.com/rikakomoe/cqhttp-twitter-bot/issues"
+  },
+  "homepage": "https://github.com/rikakomoe/cqhttp-twitter-bot",
   "scripts": {
     "build": "tsc --outDir dist",
     "lint": "tslint --fix -c tslint.json --project ./"

+ 4 - 1
src/twitter.ts

@@ -97,7 +97,10 @@ export default class {
 
     promise.then((tweets: any) => {
       logger.debug(`api returned ${JSON.stringify(tweets)} for feed ${lock.feed[lock.workon]}`);
-      if (tweets.length === 0) return;
+      if (tweets.length === 0) {
+        lock.threads[lock.feed[lock.workon]].updatedAt = new Date().toString();
+        return;
+      }
       if (lock.threads[lock.feed[lock.workon]].offset === -1) {
         lock.threads[lock.feed[lock.workon]].offset = tweets[0].id_str;
         return;