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`中自定义设置
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)
#### 以源码方式运行

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 { 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 }
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',
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',
})

View File

@ -134,7 +134,7 @@ function post({ url, config, contents, query }) {
const bili_client = {
/**
* 判断是否成功登录
* @returns {Promise<boolean>}
* @returns {Promise<Object?>}
*/
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<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);
/**引入基础功能 */
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:

View File

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

View File

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

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_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 <<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"
cat >clear.sh <<EOF
#!$(which env) bash

View File

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

View File

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

View File

@ -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 () => {

View File

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