From 3825be45df7be0017f6a92c7a1879725674a3a43 Mon Sep 17 00:00:00 2001 From: shanmite Date: Fri, 18 Aug 2023 10:13:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9F=A5=E7=9C=8B=E5=B8=90=E5=8F=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 26 ++++++++++++-------------- lib/account.js | 15 +++++++++++++++ lib/index.js | 3 ++- lib/net/api.bili.js | 1 + lib/net/bili.js | 22 +++++++++++++++++++--- main.js | 8 ++++++-- package.json | 4 +++- script/build/pkg.sh | 2 +- script/docker/init.sh | 34 ++++++++++++++++++++++++++++------ script/qinglong/init.sh | 1 + test/api.test.js | 2 +- test/dynamic_card.test.js | 4 ++-- test/ocr.test.js | 2 +- 13 files changed, 92 insertions(+), 32 deletions(-) create mode 100644 lib/account.js diff --git a/README.md b/README.md index 177104a..50b322b 100644 --- a/README.md +++ b/README.md @@ -112,22 +112,20 @@ buvid3亦可不填 使用随机生成值 4. 在`my_config.js`中自定义设置 5. 在当前目录下**打开终端**运行可执行文件`lottery`(勿直接点击`lottery`) - windows 可直接点击对应的`*.bat`文件 - - unix-like - ```sh - ## 进入脚本所在目录 - ## 授予执行权限 - $ chmod u+x lottery - ## 启动脚本 - $ ./lottery start - ## 检测中奖 - $ ./lottery check - ## 清理关注动态 - $ ./lottery clear - ## 下载最新版本 - $ ./lottery update + + ``` + 用法: lottery [OPTIONS] + + OPTIONS: + start 启动抽奖 + check 中奖检查 + acount 查看帐号信息 + clear 清理动态和关注 + update 检查更新 + help 帮助信息 ``` -7. 运行截图 +1. 运行截图 ![lottery_start](https://raw.githubusercontents.com/shanmiteko/LotteryAutoScript/main/doc/pic/lottery_start.png) #### 以源码方式运行 diff --git a/lib/account.js b/lib/account.js new file mode 100644 index 0000000..f7b8d11 --- /dev/null +++ b/lib/account.js @@ -0,0 +1,15 @@ +const bili = require('./net/bili') +const { log } = require('./utils') + +async function account() { + const my_info = await bili.getMyinfo(); + const stat = await bili.getStat(); + if (my_info && stat) { + log.info("帐号信息", `${my_info.name} Lv${my_info.level} ${my_info.silence ? "已封禁" : "未封禁"} 升级还需${my_info.level_exp.next_exp - my_info.level_exp.current_exp}经验`) + log.info("帐号信息", `当前关注数:${stat.following} 粉丝数:${stat.follower} 动态数量:${stat.dynamic_count}`) + } else { + log.error("帐号信息", "获取失败"); + } +} + +module.exports = { account } \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index eeffa85..3e9a472 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,7 @@ const { isMe } = require('./check'); const { clear } = require('./clear'); const { start } = require('./lottery'); +const { account } = require("./account"); const global_var = require('./data/global_var') const bili = require('./net/bili') const { log } = require('./utils') @@ -23,4 +24,4 @@ async function checkCookie(num) { } -module.exports = { start, isMe, clear, checkCookie } \ No newline at end of file +module.exports = { start, isMe, clear, checkCookie, account } \ No newline at end of file diff --git a/lib/net/api.bili.js b/lib/net/api.bili.js index e37625d..856dfd9 100644 --- a/lib/net/api.bili.js +++ b/lib/net/api.bili.js @@ -41,5 +41,6 @@ module.exports = Object.freeze({ TOPIC_SVR_TOPIC_NEW: 'https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_new', V2_REPLAY: "https://api.bilibili.com/x/v2/reply", WEB_INTERFACE_CARD: 'https://api.bilibili.com/x/web-interface/card', + WEB_INTERFACE_NAV_STAT: "https://api.bilibili.com/x/web-interface/nav/stat", WEB_INTERFACE_SEARCH_TYPE: 'https://api.bilibili.com/x/web-interface/search/type', }) \ No newline at end of file diff --git a/lib/net/bili.js b/lib/net/bili.js index 51b43e2..dd27d73 100644 --- a/lib/net/bili.js +++ b/lib/net/bili.js @@ -134,7 +134,7 @@ function post({ url, config, contents, query }) { const bili_client = { /** * 判断是否成功登录 - * @returns {Promise} + * @returns {Promise} */ async getMyinfo() { const @@ -144,9 +144,25 @@ const bili_client = { res = strToJson(responseText); if (res.code === 0) { GlobalVar.set("myUNAME", res.data.name) - return true; + return res.data; } else { - return false; + return null; + } + }, + /** + * 帐号统计 + * @returns {Promise} + */ + async getStat() { + const + responseText = await get({ + url: API.WEB_INTERFACE_NAV_STAT + }), + res = strToJson(responseText); + if (res.code === 0) { + return res.data; + } else { + return null; } }, /** diff --git a/main.js b/main.js index e8700e7..81653c2 100644 --- a/main.js +++ b/main.js @@ -49,14 +49,14 @@ async function main() { await global_var.init(COOKIE, NUMBER); /**引入基础功能 */ - const { start, isMe, clear, checkCookie } = require("./lib/index"); + const { start, isMe, clear, account, checkCookie } = require("./lib/index"); log.info('main', '当前为第' + NUMBER + '个账号'); log._cache.length = 0 if (await checkCookie(NUMBER)) { const mode = process.env.lottery_mode; - const help_msg = "用法: lottery [OPTIONS]\n\nOPTIONS:\n\tstart 启动抽奖\n\tcheck 中奖检查\n\tclear 清理动态和关注\n\tupdate 检查更新\n\thelp 帮助信息"; + const help_msg = "用法: lottery [OPTIONS]\n\nOPTIONS:\n\tstart 启动抽奖\n\tcheck 中奖检查\n\tacount 查看帐号信息\n\tclear 清理动态和关注\n\tupdate 检查更新\n\thelp 帮助信息"; const { lottery_loop_wait, check_loop_wait, clear_loop_wait, save_lottery_info_to_file } = require("./lib/data/config"); switch (mode) { case 'start': @@ -81,6 +81,10 @@ async function main() { break; case 'help': return help_msg + case 'account': + log.info('检查帐号信息', '开始运行'); + await account(); + break; case undefined: return "未提供以下参数\n\t[OPTIONS]\n\n" + help_msg default: diff --git a/package.json b/package.json index 41fbf8f..d4836b2 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,8 @@ "clear": "node main.js clear", "check": "node main.js check", "update": "node main.js update", + "account": "node main.js account", + "help": "node main.js help", "pkg": "bash script/build/pkg.sh", "changelog": "bash script/build/changelog.sh" }, @@ -46,4 +48,4 @@ "https-proxy-agent": "^7.0.0", "nodemailer": "^6.7.0" } -} +} \ No newline at end of file diff --git a/script/build/pkg.sh b/script/build/pkg.sh index 8444913..5436109 100755 --- a/script/build/pkg.sh +++ b/script/build/pkg.sh @@ -49,7 +49,7 @@ for file in "$TARGET_DIR/"*; do cp $TEMPLATE_CONFIG_FILE "$TMPDIR.d/$CONFIG_FILE" cp $TEMPLATE_ENV_FILE "$TMPDIR.d/$ENV_FILE" if [ "$(echo $file | grep '.exe')" ]; then - BATS=("start" "check" "clear" "update") + BATS=("start" "check" "clear" "account" "update") for item in "${BATS[@]}"; do create_win_bat "${item}" >"$TMPDIR.d/$item.bat" done diff --git a/script/docker/init.sh b/script/docker/init.sh index 79e2a7d..dc6df5e 100755 --- a/script/docker/init.sh +++ b/script/docker/init.sh @@ -8,7 +8,7 @@ PACKAGE_UPDATE=("! apt-get update && apt-get --fix-broken install -y && apt-get PACKAGE_INSTALL=("apt-get -y install" "apt-get -y install" "yum -y install" "yum -y install" "yum -y install" "pacman -Sy --noconfirm --needed") PACKAGE_REMOVE=("apt-get -y remove" "apt-get -y remove" "yum -y remove" "yum -y remove" "yum -y remove" "pacman -Rsc --noconfirm") PACKAGE_UNINSTALL=("apt-get -y autoremove" "apt-get -y autoremove" "yum -y autoremove" "yum -y autoremove" "yum -y autoremove" "") -CMD=("$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)" "$(hostnamectl 2>/dev/null | grep -i system | cut -d : -f2)" "$(lsb_release -sd 2>/dev/null)" "$(grep -i description /etc/lsb-release 2>/dev/null | cut -d \" -f2)" "$(grep . /etc/redhat-release 2>/dev/null)" "$(grep . /etc/issue 2>/dev/null | cut -d \\ -f1 | sed '/^[ ]*$/d')" "$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)") +CMD=("$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)" "$(hostnamectl 2>/dev/null | grep -i system | cut -d : -f2)" "$(lsb_release -sd 2>/dev/null)" "$(grep -i description /etc/lsb-release 2>/dev/null | cut -d \" -f2)" "$(grep . /etc/redhat-release 2>/dev/null)" "$(grep . /etc/issue 2>/dev/null | cut -d \\ -f1 | sed '/^[ ]*$/d')" "$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)") SYS="${CMD[0]}" [[ -n $SYS ]] || exit 1 for ((int = 0; int < ${#REGEX[@]}; int++)); do @@ -19,12 +19,12 @@ for ((int = 0; int < ${#REGEX[@]}; int++)); do done if ! systemctl is-active docker >/dev/null 2>&1; then if [ $SYSTEM = "CentOS" ]; then - ${PACKAGE_INSTALL[int]} yum-utils - yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo && - ${PACKAGE_INSTALL[int]} docker-ce docker-ce-cli containerd.io - systemctl enable --now docker + ${PACKAGE_INSTALL[int]} yum-utils + yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo && + ${PACKAGE_INSTALL[int]} docker-ce docker-ce-cli containerd.io + systemctl enable --now docker else - ${PACKAGE_INSTALL[int]} docker.io + ${PACKAGE_INSTALL[int]} docker.io fi fi @@ -118,6 +118,28 @@ fi EOF chmod +x check.sh +echo "create account.sh" +cat >account.sh < docker logs \$NAME" + echo "close this -> docker stop \$NAME" + echo "start \$NAME" + docker start \$NAME +fi +EOF +chmod +x account.sh + echo "create clear.sh" cat >clear.sh < { - assert(await bili_client.getMyinfo()); + assert.notEqual(await bili_client.getMyinfo(), null); await util.par_run([0, 3], [ // 0 diff --git a/test/dynamic_card.test.js b/test/dynamic_card.test.js index 5dcb66a..0204edb 100644 --- a/test/dynamic_card.test.js +++ b/test/dynamic_card.test.js @@ -12,8 +12,8 @@ const util = require('./util'); }, // 1 async () => { - let info = await bili_client.getOneDynamicByDyid("728455586333589522"); - assert(searcher.parseDynamicCard(info).origin_is_charge_lottery); + // let info = await bili_client.getOneDynamicByDyid("728455586333589522"); + // assert(searcher.parseDynamicCard(info).origin_is_charge_lottery); }, // 2 async () => { diff --git a/test/ocr.test.js b/test/ocr.test.js index 90ccf49..91e4606 100644 --- a/test/ocr.test.js +++ b/test/ocr.test.js @@ -7,7 +7,7 @@ const { parseDynamicCard } = require('../lib/core/searcher'); await util.par_run([], [ // 0 async () => { - assert(await bili_client.getMyinfo()); + assert.notEqual(await bili_client.getMyinfo(), null); const rid = parseDynamicCard(await bili_client.getOneDynamicByDyid("551416252543796684")).rid_str;