feat: 查看帐号信息

This commit is contained in:
shanmite 2023-08-18 10:13:18 +08:00
parent 248c78d669
commit 3825be45df
13 changed files with 92 additions and 32 deletions

View File

@ -112,22 +112,20 @@ buvid3亦可不填 使用随机生成值
4. 在`my_config.js`中自定义设置 4. 在`my_config.js`中自定义设置
5. 在当前目录下**打开终端**运行可执行文件`lottery`(勿直接点击`lottery`) 5. 在当前目录下**打开终端**运行可执行文件`lottery`(勿直接点击`lottery`)
- windows 可直接点击对应的`*.bat`文件 - windows 可直接点击对应的`*.bat`文件
- unix-like
```sh ```
## 进入脚本所在目录 用法: lottery [OPTIONS]
## 授予执行权限
$ chmod u+x lottery OPTIONS:
## 启动脚本 start 启动抽奖
$ ./lottery start check 中奖检查
## 检测中奖 acount 查看帐号信息
$ ./lottery check clear 清理动态和关注
## 清理关注动态 update 检查更新
$ ./lottery clear help 帮助信息
## 下载最新版本
$ ./lottery update
``` ```
7. 运行截图 1. 运行截图
![lottery_start](https://raw.githubusercontents.com/shanmiteko/LotteryAutoScript/main/doc/pic/lottery_start.png) ![lottery_start](https://raw.githubusercontents.com/shanmiteko/LotteryAutoScript/main/doc/pic/lottery_start.png)
#### 以源码方式运行 #### 以源码方式运行

15
lib/account.js Normal file
View File

@ -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 }

View File

@ -1,6 +1,7 @@
const { isMe } = require('./check'); const { isMe } = require('./check');
const { clear } = require('./clear'); const { clear } = require('./clear');
const { start } = require('./lottery'); const { start } = require('./lottery');
const { account } = require("./account");
const global_var = require('./data/global_var') const global_var = require('./data/global_var')
const bili = require('./net/bili') const bili = require('./net/bili')
const { log } = require('./utils') const { log } = require('./utils')
@ -23,4 +24,4 @@ async function checkCookie(num) {
} }
module.exports = { start, isMe, clear, checkCookie } module.exports = { start, isMe, clear, checkCookie, account }

View File

@ -41,5 +41,6 @@ module.exports = Object.freeze({
TOPIC_SVR_TOPIC_NEW: 'https://api.vc.bilibili.com/topic_svr/v1/topic_svr/topic_new', 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", V2_REPLAY: "https://api.bilibili.com/x/v2/reply",
WEB_INTERFACE_CARD: 'https://api.bilibili.com/x/web-interface/card', 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', WEB_INTERFACE_SEARCH_TYPE: 'https://api.bilibili.com/x/web-interface/search/type',
}) })

View File

@ -134,7 +134,7 @@ function post({ url, config, contents, query }) {
const bili_client = { const bili_client = {
/** /**
* 判断是否成功登录 * 判断是否成功登录
* @returns {Promise<boolean>} * @returns {Promise<Object?>}
*/ */
async getMyinfo() { async getMyinfo() {
const const
@ -144,9 +144,25 @@ const bili_client = {
res = strToJson(responseText); res = strToJson(responseText);
if (res.code === 0) { if (res.code === 0) {
GlobalVar.set("myUNAME", res.data.name) GlobalVar.set("myUNAME", res.data.name)
return true; return res.data;
} else { } else {
return false; return null;
}
},
/**
* 帐号统计
* @returns {Promise<Object?>}
*/
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;
} }
}, },
/** /**

View File

@ -49,14 +49,14 @@ async function main() {
await global_var.init(COOKIE, NUMBER); 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.info('main', '当前为第' + NUMBER + '个账号');
log._cache.length = 0 log._cache.length = 0
if (await checkCookie(NUMBER)) { if (await checkCookie(NUMBER)) {
const mode = process.env.lottery_mode; 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"); const { lottery_loop_wait, check_loop_wait, clear_loop_wait, save_lottery_info_to_file } = require("./lib/data/config");
switch (mode) { switch (mode) {
case 'start': case 'start':
@ -81,6 +81,10 @@ async function main() {
break; break;
case 'help': case 'help':
return help_msg return help_msg
case 'account':
log.info('检查帐号信息', '开始运行');
await account();
break;
case undefined: case undefined:
return "未提供以下参数\n\t[OPTIONS]\n\n" + help_msg return "未提供以下参数\n\t[OPTIONS]\n\n" + help_msg
default: default:

View File

@ -9,6 +9,8 @@
"clear": "node main.js clear", "clear": "node main.js clear",
"check": "node main.js check", "check": "node main.js check",
"update": "node main.js update", "update": "node main.js update",
"account": "node main.js account",
"help": "node main.js help",
"pkg": "bash script/build/pkg.sh", "pkg": "bash script/build/pkg.sh",
"changelog": "bash script/build/changelog.sh" "changelog": "bash script/build/changelog.sh"
}, },
@ -46,4 +48,4 @@
"https-proxy-agent": "^7.0.0", "https-proxy-agent": "^7.0.0",
"nodemailer": "^6.7.0" "nodemailer": "^6.7.0"
} }
} }

View File

@ -49,7 +49,7 @@ for file in "$TARGET_DIR/"*; do
cp $TEMPLATE_CONFIG_FILE "$TMPDIR.d/$CONFIG_FILE" cp $TEMPLATE_CONFIG_FILE "$TMPDIR.d/$CONFIG_FILE"
cp $TEMPLATE_ENV_FILE "$TMPDIR.d/$ENV_FILE" cp $TEMPLATE_ENV_FILE "$TMPDIR.d/$ENV_FILE"
if [ "$(echo $file | grep '.exe')" ]; then if [ "$(echo $file | grep '.exe')" ]; then
BATS=("start" "check" "clear" "update") BATS=("start" "check" "clear" "account" "update")
for item in "${BATS[@]}"; do for item in "${BATS[@]}"; do
create_win_bat "${item}" >"$TMPDIR.d/$item.bat" create_win_bat "${item}" >"$TMPDIR.d/$item.bat"
done done

View File

@ -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_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_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" "") 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]}" SYS="${CMD[0]}"
[[ -n $SYS ]] || exit 1 [[ -n $SYS ]] || exit 1
for ((int = 0; int < ${#REGEX[@]}; int++)); do for ((int = 0; int < ${#REGEX[@]}; int++)); do
@ -19,12 +19,12 @@ for ((int = 0; int < ${#REGEX[@]}; int++)); do
done done
if ! systemctl is-active docker >/dev/null 2>&1; then if ! systemctl is-active docker >/dev/null 2>&1; then
if [ $SYSTEM = "CentOS" ]; then if [ $SYSTEM = "CentOS" ]; then
${PACKAGE_INSTALL[int]} yum-utils ${PACKAGE_INSTALL[int]} yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo && yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo &&
${PACKAGE_INSTALL[int]} docker-ce docker-ce-cli containerd.io ${PACKAGE_INSTALL[int]} docker-ce docker-ce-cli containerd.io
systemctl enable --now docker systemctl enable --now docker
else else
${PACKAGE_INSTALL[int]} docker.io ${PACKAGE_INSTALL[int]} docker.io
fi fi
fi fi
@ -118,6 +118,28 @@ fi
EOF EOF
chmod +x check.sh chmod +x check.sh
echo "create account.sh"
cat >account.sh <<EOF
#!$(which env) bash
NAME=shanmite-lottery-account
if [[ -z "\$(docker ps -a | grep \$NAME)" ]]; then
docker run \\
-v $PWD/$ENV_FILE:/lottery/$ENV_FILE \\
-v $PWD/$CONFIG_FILE:/lottery/$CONFIG_FILE \\
--network host \\
--name \$NAME \\
$DOCKER_REPO \\
account
else
echo "container \$NAME already existed"
echo "history logs -> 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" echo "create clear.sh"
cat >clear.sh <<EOF cat >clear.sh <<EOF
#!$(which env) bash #!$(which env) bash

View File

@ -39,6 +39,7 @@ EOF
create start create start
create check create check
create clear create clear
create account
cd $NAME cd $NAME
npm i npm i

View File

@ -4,7 +4,7 @@ const util = require('./util');
const { parseDynamicCard } = require('../lib/core/searcher'); const { parseDynamicCard } = require('../lib/core/searcher');
(async () => { (async () => {
assert(await bili_client.getMyinfo()); assert.notEqual(await bili_client.getMyinfo(), null);
await util.par_run([0, 3], [ await util.par_run([0, 3], [
// 0 // 0

View File

@ -12,8 +12,8 @@ const util = require('./util');
}, },
// 1 // 1
async () => { async () => {
let info = await bili_client.getOneDynamicByDyid("728455586333589522"); // let info = await bili_client.getOneDynamicByDyid("728455586333589522");
assert(searcher.parseDynamicCard(info).origin_is_charge_lottery); // assert(searcher.parseDynamicCard(info).origin_is_charge_lottery);
}, },
// 2 // 2
async () => { async () => {

View File

@ -7,7 +7,7 @@ const { parseDynamicCard } = require('../lib/core/searcher');
await util.par_run([], [ await util.par_run([], [
// 0 // 0
async () => { async () => {
assert(await bili_client.getMyinfo()); assert.notEqual(await bili_client.getMyinfo(), null);
const rid = parseDynamicCard(await bili_client.getOneDynamicByDyid("551416252543796684")).rid_str; const rid = parseDynamicCard(await bili_client.getOneDynamicByDyid("551416252543796684")).rid_str;