From 2fbfc3b519fb33577bc0dffe0c6058c8214722a9 Mon Sep 17 00:00:00 2001 From: yuudi Date: Fri, 2 Oct 2020 19:24:54 +0800 Subject: [PATCH] feat: deviation analyzer --- .env.example | 8 -- .github/workflows/docker-build.yml | 20 ++++ Dockerfile | 48 +++----- README.md | 2 - docker-compose.yml | 48 -------- scripts/yobot-mirai-auto.ps1 | 111 ++++++++++++------ src/client/nonebot_plugin.py | 6 + src/client/packedfiles/default_boss.json | 3 +- src/client/packedfiles/default_config.json | 2 +- src/client/packedfiles/default_pool.json | 40 +------ .../static/clan/statistics/deviation.png | Bin 0 -> 3265 bytes .../public/template/clan/statistics.html | 3 + src/client/ybplugins/updater.py | 12 +- src/client/yobot.py | 4 +- 14 files changed, 131 insertions(+), 176 deletions(-) delete mode 100644 .env.example create mode 100644 .github/workflows/docker-build.yml delete mode 100644 docker-compose.yml create mode 100644 src/client/public/static/clan/statistics/deviation.png diff --git a/.env.example b/.env.example deleted file mode 100644 index 3a79d358..00000000 --- a/.env.example +++ /dev/null @@ -1,8 +0,0 @@ -VNC_PWD=Yobot123 -QQ_ACCOUNT= -# 使用pro小i版 -#COOLQ_VERSION_URL=http://dlsec.cqp.me/cqp-xiaoi -# 使用pro图灵版 -#COOLQ_VERSION_URL=http://dlsec.cqp.me/cqp-tuling -# 使用air图灵版 -COOLQ_VERSION_URL=http://dlsec.cqp.me/cqa-tuling \ No newline at end of file diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 00000000..65e6bc36 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,20 @@ +name: docker-build + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + name: auto build + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Build image + uses: docker/build-push-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_ACCESSTOKEN }} + repository: yobot/yobot + tags: latest,slim diff --git a/Dockerfile b/Dockerfile index d5076497..eef22ce5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,43 +1,23 @@ FROM python:3.7-slim-buster -LABEL maintainer="AzurCrystal" +LABEL maintainer="yobot" -ARG PUID=1000 ENV PYTHONIOENCODING=utf-8 -RUN set -x \ - && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ - && echo 'Asia/Shanghai' >/etc/timezone \ - && { \ - echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free"; \ - echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free"; \ - echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free"; \ - echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security buster/updates main contrib non-free"; \ - } > /etc/apt/sources.list \ - && rm -rf /var/lib/apt/lists/* \ - && apt-get clean \ - && apt-get update \ - && apt-get install git -y --no-install-recommends --no-install-suggests \ - && useradd -u $PUID -m yobot \ - && su yobot -c \ - "mkdir -p /home/yobot \ - && cd /home/yobot \ - && git clone https://gitee.com/yobot/yobot.git \ - && { \ - echo '#!/bin/sh'; \ - echo 'cd /home/yobot/yobot/src/client && python3 /home/yobot/yobot/src/client/main.py && sh /home/yobot/yobot/src/client/yobotg.sh'; \ - } > /home/yobot/entry.sh \ - && chmod 755 /home/yobot/entry.sh \ - && chmod +x /home/yobot/entry.sh" \ - && pip3 install --no-cache-dir -r /home/yobot/yobot/src/client/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple \ - && apt-get clean autoclean \ - && apt-get autoremove -y \ - && rm -rf /var/lib/apt/lists/* -USER yobot +ADD src/client/ /yobot -WORKDIR /home/yobot +RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && echo 'Asia/Shanghai' >/etc/timezone \ + && cd /yobot \ + && useradd yobot \ + && pip3 install aiocqhttp==0.6.8 Quart==0.6.15 --no-cache-dir \ + && pip3 install -r requirements.txt --no-cache-dir \ + && python3 main.py \ + && chmod +x yobotg.sh + +WORKDIR /yobot EXPOSE 9222 -VOLUME /home/yobot/yobot +VOLUME /yobot/yobot_data -ENTRYPOINT /home/yobot/entry.sh +ENTRYPOINT /yobot/yobotg.sh diff --git a/README.md b/README.md index b1d7b4b3..712ad71f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # yobot -当前大版本已归档(archive),不再更新。项目整体重构中。基于 QQ 的部分已不再支持,重构后将基于其他平台。 - [yobot](./about.md) 是为[公主连接](https://game.bilibili.com/pcr/)公会战设计的辅助机器人,能够帮助公会战管理者提供自动化管理服务。 yobot 提供了群聊、web 页面两套用户交互方式,具有操作便捷、通知及时、数据详细的特点。 diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index c13246ca..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,48 +0,0 @@ -version: "3" -services: - bot: - build: . - ports: - - "9222:9222" - env_file: .env - restart: on-failure - volumes: - - .:/home/yobot/yobot - networks: - - bot_net - - cqhttp: - image: richardchien/cqhttp:latest - env_file: .env - restart: on-failure - environment: - - VNC_PASSWD=${VNC_PWD} - - COOLQ_ACCOUNT=${QQ_ACCOUNT} # 要登录的 QQ 账号,可选但建议填 - - COOLQ_URL=${COOLQ_VERSION_URL} - - CQHTTP_USE_HTTP=false - - CQHTTP_USE_WS=false - - CQHTTP_USE_WS_REVERSE=true - - CQHTTP_WS_REVERSE_API_URL=ws://bot:9222/ws/api/ - - CQHTTP_WS_REVERSE_EVENT_URL=ws://bot:9222/ws/event/ - - CQHTTP_WS_REVERSE_URL=ws://bot:9222 - - CQHTTP_WS_REVERSE_RECONNECT_INTERVAL=4000 - - CQHTTP_REVERSE_RECONNECT_ON_CODE_1000=true - - CQHTTP_POST_MESSAGE_FORMAT=string - - CQHTTP_SERVE_DATA_FILES=false - - CQHTTP_UPDATE_SOURCE=github - - CQHTTP_UPDATE_CHANNEL=stable - - CQHTTP_CHECK_UPDATE=false - - CQHTTP_PERFORM_UPDATE=false - - CQHTTP_SHOW_LOG_CONSOLE=true - - CQHTTP_LOG_LEVEL=info - volumes: - - ./cqhttp:/home/user/coolq - ports: - - "9000:9000" # VNC端口 - # - "5700:5700" # HTTP API 插件开放的端口 - networks: - - bot_net - -networks: - bot_net: - driver: bridge diff --git a/scripts/yobot-mirai-auto.ps1 b/scripts/yobot-mirai-auto.ps1 index 9275215f..cb4ecb22 100644 --- a/scripts/yobot-mirai-auto.ps1 +++ b/scripts/yobot-mirai-auto.ps1 @@ -1,5 +1,5 @@ # this file should be saved as "UTF-8 with BOM" -$ErrorActionPreference = "Inquire" +$ErrorActionPreference = "Stop" # 检查运行环境 if ($Host.Version.Major -lt 5) { @@ -10,32 +10,37 @@ if ((Get-ChildItem -Path Env:OS).Value -ine 'Windows_NT') { Write-Output '当前操作系统不支持一键安装' exit } -if ([Environment]::Is64BitProcess) { -} -else { +if (![Environment]::Is64BitProcess) { Write-Output '暂时不支持32位系统' exit } if (Test-Path .\qqbot) { Write-Output '发现重复,是否删除旧文件并重新安装?' $reinstall = Read-Host '请输入 y 或 n (y/n)' - Switch ($reinstall) { - Y { Remove-Item .\qqbot -Recurse -Force } - N { exit } - Default { exit } - } + Switch ($reinstall) { + Y { Remove-Item .\qqbot -Recurse -Force } + N { exit } + Default { exit } + } } # 用户输入 $qqid = Read-Host '请输入作为机器人的QQ号:' -$qqpassword = Read-Host '请输入作为机器人的QQ密码:' +$qqpassword = Read-Host -AsSecureString '请输入作为机器人的QQ密码:' +Write-Output '是否使用YoCool皮肤(测试版):' +$yocool = Read-Host '请输入 y 或 n (y/n)' +Switch ($yocool) { + Y { $yocool = $true } + N { $yocool = $false } + Default { $yocool = $false } +} Write-Output '是否监听80端口(如果此服务器没有其他网站,建议选 y):' $listen_80 = Read-Host '请输入 y 或 n (y/n)' -Switch ($listen_80) { - Y { $port = 80 } - N { $port = 9222 } - Default { $port = 9222 } -} +Switch ($listen_80) { + Y { $port = 80 } + N { $port = 9222 } + Default { $port = 9222 } +} # 创建运行目录 New-Item -Path .\qqbot -ItemType Directory @@ -43,34 +48,64 @@ Set-Location qqbot New-Item -ItemType Directory -Path .\yobot, .\yobot\yobot_data, .\mirai, .\mirai\plugins, .\mirai\plugins\CQHTTPMirai # 下载程序 -Invoke-WebRequest https://get.yobot.win/scyb/miraiOK_win_amd64.exe -OutFile .\mirai\miraiOK.exe -if ((Get-FileHash -Path .\mirai\miraiOK.exe -Algorithm SHA256).Hash -ne "60B4B16AC401ADD7D75FADA83344B50EBA9F0976F73113FF6D95E5C09E79941F") { Write-Output '下载失败'; exit } -Invoke-WebRequest https://get.yobot.win/scyb/cqhttp-mirai-0.1.9-all.jar -OutFile .\mirai\plugins\cqhttp-mirai-0.1.9-all.jar -if ((Get-FileHash -Path .\mirai\plugins\cqhttp-mirai-0.1.9-all.jar -Algorithm SHA256).Hash -ne "6A93DB2B422D93B1632A92C8E0AC25FE51050A5474B36B252BB2E1A8D22B5B0D") { Write-Output '下载失败'; exit } -Invoke-WebRequest https://get.yobot.win/scyb/yobot208.zip -OutFile .\yobot.zip -if ((Get-FileHash -Path .\yobot.zip -Algorithm SHA256).Hash -ne "5D5FE0CBEEA746D4C50303794C4E01C0A7EAA54D805873CA3269BBEF35BEA643") { Write-Output '下载失败'; exit } +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +Invoke-WebRequest https://pan.yobot.win/yobot/wget.exe -OutFile .\wget.exe +.\wget.exe https://download.fastgit.org/Mrs4s/go-cqhttp/releases/download/v0.9.25-fix3/go-cqhttp-v0.9.25-fix3-windows-amd64.zip -O .\go-cqhttp.zip +Expand-Archive go-cqhttp.zip -DestinationPath .\mirai\ +Remove-Item go-cqhttp.zip +if ($yocool) { + .\wget.exe https://pan.yobot.win/yobot/yocool.zip -O .\yobot.zip +} +else { + .\wget.exe https://pan.yobot.win/yobot/yobot.zip -O .\yobot.zip +} Expand-Archive yobot.zip -DestinationPath .\yobot\ +if ($yocool) { Move-Item .\yobot\yobot--with-yocool.exe .\yobot\yobot.exe } Remove-Item yobot.zip # 生成随机 access_token $token = -join ((65..90) + (97..122) | Get-Random -Count 16 | ForEach-Object { [char]$_ }) -# 写入 cqmiraihttp 配置文件 -New-Item -Path .\mirai\plugins\CQHTTPMirai\setting.yml -ItemType File -Value @" -"${qqid}": - ws_reverse: - - enable: true - postMessageFormat: string - reverseHost: 127.0.0.1 - reversePort: ${port} - reversePath: /ws/ - accessToken: ${token} - reconnectInterval: 3000 +# 写入 go-cqhttp 配置文件 +$realpassword = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($qqpassword)) +New-Item -Path .\mirai\config.json -ItemType File -Value @" +{ + "uin": ${qqid}, + "password": "${realpassword}", + "encrypt_password": false, + "password_encrypted": `"`", + "enable_db": false, + "access_token": "${token}", + "relogin": { + "enabled": true, + "relogin_delay": 3, + "max_relogin_times": 0 + }, + "_rate_limit": { + "enabled": false, + "frequency": 1, + "bucket_size": 1 + }, + "post_message_format": "string", + "ignore_invalid_cqcode": false, + "force_fragmented": true, + "heartbeat_interval": 5, + "http_config": { + "enabled": false + }, + "ws_config": { + "enabled": false + }, + "ws_reverse_servers": [ + { + "enabled": true, + "reverse_url": "ws://localhost:${port}/ws/", + "reverse_reconnect_interval": 3000 + } + ] +} "@ -# 写入 miraiOK 配置文件 -New-Item -Path .\mirai\config.txt -ItemType File -Value "----------`nlogin ${qqid} ${qqpassword}`n" - # 写入 yobot 配置文件 New-Item -Path .\yobot\yobot_data\yobot_config.json -ItemType File -Value @" { @@ -82,14 +117,14 @@ New-Item -Path .\yobot\yobot_data\yobot_config.json -ItemType File -Value @" # 启动程序 Start-Process -FilePath .\yobot\yobot.exe -WorkingDirectory .\yobot -Start-Process -FilePath .\mirai\miraiOK.exe -WorkingDirectory .\mirai +Start-Process -FilePath cmd.exe -WorkingDirectory .\mirai -ArgumentList "/C `"go-cqhttp & pause`"" # 创建快捷方式 $desktop = [Environment]::GetFolderPath("Desktop") $WshShell = New-Object -comObject WScript.Shell -$Shortcut = $WshShell.CreateShortcut("${desktop}\mirai.lnk") -$Shortcut.TargetPath = "${pwd}\mirai\miraiOK.exe" +$Shortcut = $WshShell.CreateShortcut("${desktop}\mirai-go.lnk") +$Shortcut.TargetPath = "${pwd}\mirai\go-cqhttp.exe" $Shortcut.WorkingDirectory = "${pwd}\mirai\" $Shortcut.Save() diff --git a/src/client/nonebot_plugin.py b/src/client/nonebot_plugin.py index ffea5a72..18ad321f 100644 --- a/src/client/nonebot_plugin.py +++ b/src/client/nonebot_plugin.py @@ -30,6 +30,12 @@ def makefile(path, content="# doing nothing"): from .yobot import Yobot import asyncio +# print( +# "|===========================================|" +# "| yobot 插件版即将停止支持,请尽快更换为独立版 |" +# "|===========================================|" +# ) + if "nonebot" in sys.modules: from nonebot import get_bot, scheduler else: diff --git a/src/client/packedfiles/default_boss.json b/src/client/packedfiles/default_boss.json index a805ce97..3e45fa17 100644 --- a/src/client/packedfiles/default_boss.json +++ b/src/client/packedfiles/default_boss.json @@ -13,7 +13,8 @@ "tw": [ [6000000, 8000000, 10000000, 12000000, 15000000], [6000000, 8000000, 10000000, 12000000, 15000000], - [6000000, 8000000, 10000000, 12000000, 15000000] + [7000000, 9000000, 13000000, 15000000, 20000000], + [15000000, 16000000, 18000000, 19000000, 20000000] ], "eff": [ [1.2, 1.2, 1.3, 1.4, 1.5], diff --git a/src/client/packedfiles/default_config.json b/src/client/packedfiles/default_config.json index e276f4a1..ad213717 100644 --- a/src/client/packedfiles/default_config.json +++ b/src/client/packedfiles/default_config.json @@ -4,7 +4,7 @@ "access_token": "", "client_salt": null, "public_address": null, - "public_basepath": "/yobot/", + "public_basepath": "/", "web_mode_hint": true, "super-admin": [], "black-list": [], diff --git a/src/client/packedfiles/default_pool.json b/src/client/packedfiles/default_pool.json index 5e33da63..9e3443c3 100644 --- a/src/client/packedfiles/default_pool.json +++ b/src/client/packedfiles/default_pool.json @@ -9,39 +9,17 @@ "shuffle": false }, "pool": { - "fes": { - "prop": 1, - "prop_last": 1, - "prefix":"★★★", - "pool": [ - "克里斯蒂娜" ,"矛依未","似似花","佩可莉姆(公主)" - ] - }, - "hidden": { - "prop": 0, - "prop_last": 1, - "prefix":"★★★", - "pool": [ - "千里真那","拉比林斯塔","拉基尼卡德" - ] - }, "star3": { - "prop": 18, - "prop_last": 18, + "prop": 25, + "prop_last": 25, "prefix":"★★★", "pool": [ "初音","真琴","姬塔","咲恋","望","璃乃","妮侬","伊绪","秋乃","莫妮卡","静流", "杏奈","纯","真步","亚里沙","镜华","伊利亚","智","流夏","香澄","安","古蕾雅", "空花(大江户)","妮侬(大江户)","碧(插班生)","克萝伊", "美美(万圣节)", "露娜","卡娅","伊利亚(圣诞节)","霞(魔法少女)","优妮","琪爱儿","铃(游侠)", - "真阳(游侠)" - ] - }, - "limited_3": { - "prop": 2, - "prop_last": 5, - "prefix":"★★★", - "pool": [ + "真阳(游侠)", + "佩可莉姆(夏日)","铃莓(夏日)","凯留(夏日)","珠希(夏日)","忍(万圣节)", "美咲(万圣节)","千歌(圣诞节)","绫音(圣诞节)","日和莉(新年)","优衣(新年)", "静流(情人节)","蕾姆","艾米莉亚","玲奈(夏日)","咲恋(夏日)","真琴(夏日)", @@ -49,16 +27,6 @@ "凯露(新年)","岛村卯月(偶像大师)","涉谷凛(偶像大师)" ] }, - "limited_1": { - "prop": 4, - "prop_last": 0, - "prefix":"★", - "pool": [ - "可可萝(夏日)","美冬(夏日)","宫子(万圣节)","胡桃(圣诞节)","怜(新年)", - "惠理子(情人节)","露","拉姆","伊绪(夏日)","香织(夏日)","未奏希(万圣节)", - "望(圣诞节)","铃莓(新年)","本田未央(偶像大师)" - ] - }, "star2": { "prop": 180, "prop_last": 975, diff --git a/src/client/public/static/clan/statistics/deviation.png b/src/client/public/static/clan/statistics/deviation.png new file mode 100644 index 0000000000000000000000000000000000000000..2b96a5383ca903f8b3d39cc76f94aa4f8029a74b GIT binary patch literal 3265 zcmcgveM}Q)7=H_$fDGg#*~kPrkLk8(dv^sYJ#7VA1rn$KBChYoV>hDtw_hCvtVkOgiMDzLI5 zg}AL2n?Sm?Xh1Is*OC}RkpM(otwnPrgGi}yIilwsERv~ID`+Ak6Pc$`66*8}jb<*Q z!ig*l&%%gw1)(N0a8jj0f)5Ih6x4?b5nMV zP~sA$0Fa?WIJ?tf2^eQ+jJ2><)+P!NON6j?GcWRjnSX@p(D4`pFtkQv$i}$7Sgj!w zg1D#}(g+4*T(nSJV`s5KR^Xiunq5>4-At3%*h#&Er9|FQ%=4DfL@gh68PV&d#AuLL zOE??DyM)&sxWgJKk=3FqT!ky}ECo&!;~FwOgUnRV!LvvlAAuTqhO4X@7dnq5GR8n* z)i9Ju{V$lI$x7Z~r66a{N|{*9ZZn}sD3YX}x9|>V7p(o$ww1`Ue2r;fmgT9=uHO8+C> zBQSxl6kU{q%`w4fJx)bo(0@$o#t|ym!z=@54|MJ*9F7BN8Ja_I6PjeK4UR7doKr(N zyG{TQQBq*YDR!3)^{=#@BSE%z*X;|tue9%1yx+yucT7u7Z-~ECvZuySaI5iYe`h8v4fql34GZ7y)-tR6$KW3tPruk=Q?@Eq;^Fq%pa=7p_;B7RRSNZ(g zfVbUX*82QAfcLP$oZ|Cu1zw-Q{I<^zsZBAM%Y1(5gbMUAX6=5Fcrdv)L95%sS;Rwu)V-&?cMBT#u^^3A`mtT1VAe4=jvv#SCr znA`#Ja9MEx44&cWKQ zo}MJSKdrQ9UFsWZQ?Po1Gx(>OP1~j)0G;eu@sk*syrKSluXEL(Kksb2AAbG*^tPjY uSE3J{?3PDN(r?N$$;Q8eB|m@uVE9m5Y>KS&^S#plh=N5+4IR1VjsF08t7yFd literal 0 HcmV?d00001 diff --git a/src/client/public/template/clan/statistics.html b/src/client/public/template/clan/statistics.html index c16df4e4..c5e25a10 100644 --- a/src/client/public/template/clan/statistics.html +++ b/src/client/public/template/clan/statistics.html @@ -13,6 +13,8 @@

图表




数据图表
by @Diving-Fish & @Winrey +

+
均值偏差
by @Alive24




更多分析

>出刀顺序表 by @Ai-Himmel

@@ -53,6 +55,7 @@

更多分析

var apiurl = window.location.href + "api/?apikey=" + apikey document.getElementById("apiurl").value = apiurl; document.getElementById("pcrd-yobot-fe").href = "http://tools.yobot.win/pcrd-yobot-fe/#" + encodeURIComponent(apiurl); + document.getElementById("clan-battle-analyzer").href = "http://clan-battle-analyzer.pcrbot.com/?apiURL=" + encodeURIComponent(apiurl); document.getElementById("copy").addEventListener("click", e => { document.getElementById("apiurl").select(); document.execCommand("Copy"); diff --git a/src/client/ybplugins/updater.py b/src/client/ybplugins/updater.py index 6cce4884..9f7fd5bf 100644 --- a/src/client/ybplugins/updater.py +++ b/src/client/ybplugins/updater.py @@ -336,6 +336,12 @@ def get_version(base_version: str, base_commit: int) -> dict: "https://toolscdn.yobot.win/verinfo/yobot3.json", ] } + if os.path.exists('/.dockerenv'): + return { + "run-as": "python", + "commited": False, + "ver_name": f"yobot{base_version} on Docker" + } try: with os.popen("git diff HEAD --stat") as r: text = r.read() @@ -346,12 +352,6 @@ def get_version(base_version: str, base_commit: int) -> dict: "ver_name": "yobot{}源码版\n存在未提交的修改".format(base_version) } except Exception as e: - if os.path.exists('/.dockerenv'): - return { - "run-as": "python", - "commited": False, - "ver_name": f"yobot{base_version} on Docker" - } return { "run-as": "python", "commited": False, diff --git a/src/client/yobot.py b/src/client/yobot.py index 8682ef47..d98f74fd 100644 --- a/src/client/yobot.py +++ b/src/client/yobot.py @@ -33,8 +33,8 @@ class Yobot: - Version = "[v3.6.4]" - Version_id = 211 + Version = "[v3.6.5]" + Version_id = 213 # "git rev-list --count HEAD" def __init__(self, *,