增加tg bot测试,修改增删任务通知

This commit is contained in:
whyour 2021-05-07 23:10:09 +08:00
parent 99d8a8dd23
commit 14bd680202
8 changed files with 181 additions and 174 deletions

View File

@ -1,5 +1,5 @@
## Version: v2.0.0
## Date: 2021-04-07
## Date: 2021-05-07
## Update Content: 新一版青龙。
## 上面版本号中如果第2位数字有变化那么代表增加了新的参数如果只有第3位数字有变化仅代表更新了注释没有增加新的参数可更新可不更新
@ -19,8 +19,8 @@ CommandTimeoutTime="1h"
## 在crontab.list中除掉每小时上述时间启动的任务外其他任务在你定义了 RandomDelay 的情况下,一律启用随机延迟,但如果你给某些任务添加了 "now" 或者 "conc",那么这些任务也将无视随机延迟直接启动
RandomDelay="300"
## 如果你自己会写shell脚本并且希望在每次运行 ql update 命令时,额外运行你的 shell 脚本,请赋值为 "true"
EnableExtraShell=""
## 如果你自己会写shell脚本并且希望在每次运行 ql update 命令时,额外运行你的 shell 脚本,请赋值为 "true"默认为true
EnableExtraShell="true"
## 自动按顺序进行账号间互助(选填) 设置为 true 时将直接导入code最新日志来进行互助
AutoHelpOther=""
@ -33,7 +33,7 @@ AutoHelpOther=""
HelpType=""
## 需组合的环境变量列表env_name需要和var_name一一对应
## 需组合的环境变量列表env_name需要和var_name一一对应,如何有新活动按照格式添加(不懂勿动)
env_name=(
JD_COOKIE
FRUITSHARECODES

View File

@ -4,21 +4,6 @@ get_token() {
token=$(cat $file_auth_user | jq -r .token)
}
get_json_value() {
local json=$1
local key=$2
if [[ -z "$3" ]]; then
local num=1
else
local num=$3
fi
local value=$(echo "${json}" | awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'${key}'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p)
echo ${value}
}
add_cron_api() {
local currentTimeStamp=$(date +%s)
if [ $# -eq 1 ]; then
@ -44,10 +29,11 @@ add_cron_api() {
--compressed
)
code=$(echo $api | jq -r .code)
message=$(echo $api | jq -r .message)
if [[ $code == 200 ]]; then
echo -e "$name 添加成功"
return "$name 添加成功"
else
echo -e "$name 添加失败"
return "$name 添加失败(${message})"
fi
}
@ -79,10 +65,11 @@ update_cron_api() {
--compressed
)
code=$(echo $api | jq -r .code)
message=$(echo $api | jq -r .message)
if [[ $code == 200 ]]; then
echo -e "$name 添加成功"
return "$name 更新成功"
else
echo -e "$name 添加失败"
return "$name 更新失败(${message})"
fi
}
@ -101,10 +88,11 @@ del_cron_api() {
-H "Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7"
)
code=$(echo $api | jq -r .code)
message=$(echo $api | jq -r .message)
if [[ $code == 200 ]]; then
echo -e "$name 删除成功"
return "$name 删除成功"
else
echo -e "$name 删除失败"
return "$name 删除失败(${message})"
fi
}

19
shell/bot.sh Normal file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
## 导入通用变量与函数
dir_shell=/ql/shell
. $dir_shell/share.sh
echo -e "安装bot依赖...\n"
apk --no-cache add -f zlib-dev gcc jpeg-dev python3-dev musl-dev freetype-dev
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install telethon python-socks[asyncio] pillow qrcode requests prettytable
echo -e "下载bot所需文件...\n"
repo_path="${dir_repo}/SuMaiKaDe_jddockerbot"
git clone -b master https://ghproxy.com/https://github.com/SuMaiKaDe/jddockerbot.git $repo_path
cp -rf "$repo_path/jbot" $dir_root
cp -f "$repo_path/config/bot.json" "$dir_root/config"
cd $dir_root
nohup python3 -m jbot &

View File

@ -136,6 +136,15 @@ run_concurrent () {
done
}
## 运行其他命令
run_else() {
local log_time=$(date "+%Y-%m-%d-%H-%M-%S")
local log_dir="$dir_log/$1"
local log_path="$log_dir/$log_time.log"
make_dir "$log_dir"
timeout $CommandTimeoutTime "$@" 2>&1 | tee $log_path
}
## 命令检测
main() {
case $# in
@ -155,14 +164,12 @@ main () {
run_concurrent $1 $2
;;
*)
echo -e "\n命令输入错误...\n"
usage
run_else "$@"
;;
esac
;;
*)
echo -e "\n命令参数过多...\n"
usage
run_else "$@"
;;
esac
}

View File

@ -108,21 +108,15 @@ output_list_add_drop() {
del_cron() {
local list_drop=$1
local author=$2
local detail detail2
detail=$(cat $list_drop)
local detail=""
echo -e "开始尝试自动删除失效的定时任务...\n"
for cron in $detail; do
for cron in $(cat $list_drop); do
local id=$(cat $list_crontab_user | grep -E "$cmd_task $cron$" | perl -pe "s|.*ID=(.*) $cmd_task $cron$|\1|")
del_cron_api "$id"
result=$(del_cron_api "$id")
rm -f "$dir_scripts/${cron}"
detail="${detail}\n${result}"
done
exit_status=$?
detail2=$(echo $detail | perl -pe "s| |\\\n|g")
if [[ $exit_status -eq 0 ]]; then
notify "删除失效任务通知" "成功删除以下失效的定时任务:\n$detail2"
else
notify "删除任务失败通知" "尝试自动删除以下定时任务出错,请手动删除:\n$detail2"
fi
notify "删除失效任务通知" "$detail2"
}
## 自动增加定时任务需要1.AutoAddCron 设置为 true2.正常更新js脚本没有报错3.存在新任务4.crontab.list存在并且不为空
@ -131,9 +125,9 @@ add_cron() {
local list_add=$1
local author=$2
echo -e "开始尝试自动添加定时任务...\n"
local detail=$(cat $list_add)
local detail=""
cd $dir_scripts
for file in $detail; do
for file in $(cat $list_add); do
local file_name=${file/${author}\_/}
if [ -f $file ]; then
cron_line=$(
@ -148,16 +142,11 @@ add_cron() {
cron_name=$(grep "new Env" $file | awk -F "'|\"" '{print $2}' | head -1)
[[ -z $cron_name ]] && cron_name="$file_name"
[[ -z $cron_line ]] && cron_line="0 6 * * *"
add_cron_api "$cron_line:$cmd_task $file:$cron_name"
result=$(add_cron_api "$cron_line:$cmd_task $file:$cron_name")
detail="${detail}\n${result}"
fi
done
exit_status=$?
local detail2=$(echo $detail | perl -pe "s| |\\\n|g")
if [[ $exit_status -eq 0 ]]; then
notify "新增任务通知" "成功添加新的定时任务:\n$detail2"
else
notify "新任务添加失败通知" "尝试自动添加以下新的定时任务出错,请手动添加:\n$detail2"
fi
notify "新增任务通知" "$detail"
}
## 更新仓库
@ -207,10 +196,10 @@ update_raw() {
cp -f $raw_file_name $dir_scripts/${filename}
cron_line=$(
perl -ne "{
print if /.*([\d\*]*[\*-\/,\d]*[\d\*] ){4}[\d\*]*[\*-\/,\d]*[\d\*]( |,|\").*$raw_file_name/
print if /.*([\d\*]*[\*-\/,\d]*[\d\*] ){4,5}[\d\*]*[\*-\/,\d]*[\d\*]( |,|\").*$raw_file_name/
}" $raw_file_name |
perl -pe "{
s|[^\d\*]*(([\d\*]*[\*-\/,\d]*[\d\*] ){4}[\d\*]*[\*-\/,\d]*[\d\*])( \|,\|\").*/?$raw_file_name.*|\1|g;
s|[^\d\*]*(([\d\*]*[\*-\/,\d]*[\d\*] ){4,5}[\d\*]*[\*-\/,\d]*[\d\*])( \|,\|\").*/?$raw_file_name.*|\1|g;
s| | |g
}" | sort -u | head -1
)
@ -249,6 +238,7 @@ usage() {
echo -e "4. $cmd_update repo <repourl> <path> <blacklist> <dependence> # 更新仓库的脚本"
echo -e "5. $cmd_update rmlog <days> # 删除旧日志"
echo -e "6. $cmd_update code # 获取互助码"
echo -e "6. $cmd_update bot # 启动tg-bot"
}
## 更新qinglong
@ -380,6 +370,9 @@ main() {
code)
. $dir_shell/code.sh
;;
bot)
. $dir_shell/bot.sh
;;
*)
echo -e "命令输入错误...\n"
usage