mirror of
https://github.com/KimigaiiWuyi/GenshinUID.git
synced 2025-07-04 05:53:29 +00:00
Compare commits
305 Commits
main
...
QQGuildBot
Author | SHA1 | Date | |
---|---|---|---|
474939801d | |||
fdef61bc2f | |||
27f17f9d1b | |||
da02c9e3fe | |||
38bcf9ab98 | |||
6308f39ef1 | |||
b0e35e906f | |||
97c55ba2b4 | |||
5c452b364f | |||
0a2427f931 | |||
b4b21e14c1 | |||
1df91e9512 | |||
3802371d69 | |||
8d8533044e | |||
77d70775de | |||
22096c3d02 | |||
c3cf59f518 | |||
e39c9ccee6 | |||
8bf3f51820 | |||
57ae879057 | |||
ec459237da | |||
1518a69102 | |||
21777d971c | |||
719b3992dc | |||
1b8328de1d | |||
865df9fbcd | |||
fc7e384367 | |||
cfbc21401b | |||
003fe8a3a3 | |||
0b738d4ff5 | |||
a7a8f67a23 | |||
6d26f12e7f | |||
3e13a0974c | |||
3193b8462f | |||
dbf7221609 | |||
0d7d6ec518 | |||
c7c555d644 | |||
fce2348971 | |||
4ad951e319 | |||
f1c92e2a9e | |||
ce67787c62 | |||
1f5edb77f4 | |||
61e356fe06 | |||
06bb055aab | |||
fafdbe4cc6 | |||
4f9b1a547c | |||
25228518af | |||
8272a1d45b | |||
607585c65d | |||
5449566357 | |||
a06c8a29ee | |||
14ce0dcbb4 | |||
31f08c16bb | |||
ebcdaa07a9 | |||
12d3d27f65 | |||
ab6cad2dc3 | |||
03dc27609e | |||
99fbf9d0dc | |||
1b4e3df777 | |||
2b9484e0d3 | |||
45455388e2 | |||
a9d4914de3 | |||
a05a922e8e | |||
e2c8edacc2 | |||
e4a12b2d5f | |||
8180f8dd5f | |||
dbcf214d3a | |||
0bb40319a1 | |||
f3771c1950 | |||
0a8a5cf9da | |||
fe183d3a89 | |||
cb24cdbf23 | |||
118cfc68b1 | |||
986125af32 | |||
0c3b8fc58e | |||
e4b191c932 | |||
f0d5a3e371 | |||
f07450bfd8 | |||
3c7bd4ce35 | |||
06cca70bd5 | |||
7c0cfaeb64 | |||
043e626a07 | |||
c6e51ecfeb | |||
06ab2d9ed3 | |||
257f4c7d94 | |||
b602b99e82 | |||
4755e86c97 | |||
8777c730e1 | |||
f2157be829 | |||
cd48c8deae | |||
ec89590c9c | |||
74ad0be66b | |||
32e9ddef2d | |||
594344a0c1 | |||
7d85d89107 | |||
711d9a372f | |||
952f2abe65 | |||
717f776b02 | |||
6911eaa1d3 | |||
be3084074c | |||
f651e2060c | |||
d50dcf6134 | |||
8eeede0b49 | |||
9af6a68ffe | |||
1b25add056 | |||
98f3744543 | |||
58614e6e94 | |||
d149b8a0be | |||
7629559f17 | |||
82481d5f09 | |||
559906b742 | |||
0d91bcbfd3 | |||
b216323c75 | |||
e27960af15 | |||
91e34b7684 | |||
17453d5cb3 | |||
35623949ae | |||
c3cc0e6c2d | |||
41ab9e1133 | |||
da7f8ac510 | |||
f0c183501b | |||
9cd467cbf5 | |||
e0c1fc2f59 | |||
0a1892eee8 | |||
81cbd547a6 | |||
b3adee4e8d | |||
e3cbebbdec | |||
57440fad9e | |||
9329f1f723 | |||
4ec7b16fec | |||
94607ece00 | |||
52b989eef6 | |||
23b63da70b | |||
219cba148d | |||
c45f546c2c | |||
a585f95128 | |||
5e2406c88c | |||
3eddb06f7b | |||
001ac794af | |||
c0a60845ab | |||
7fe880a7a0 | |||
6f22de7623 | |||
5f51e378b5 | |||
397ecbf569 | |||
6241be4224 | |||
0413311345 | |||
63aec98647 | |||
7273c07a9c | |||
a2e053c279 | |||
c88037d9ae | |||
a8ccab1a3e | |||
4a6ec9f718 | |||
1eea39e759 | |||
3b543f9bed | |||
24dc256989 | |||
04540b4dbd | |||
5d3c481437 | |||
89c60337b7 | |||
cbae225225 | |||
a6a842bf0e | |||
2e5668b77b | |||
0b6e7146ab | |||
f03ec2a4ef | |||
0936856218 | |||
37cdbb9a26 | |||
9fd1c725d0 | |||
843e821bc6 | |||
9ced17a1a5 | |||
8ee92d0d2d | |||
7fa86be495 | |||
8f817050a7 | |||
edc76d974e | |||
ee4200e093 | |||
e9490d9a3b | |||
f17bc36b12 | |||
34d2af332f | |||
16bec27e27 | |||
256d264d7f | |||
403c6ddadd | |||
ddce7c0857 | |||
4c68c1bb45 | |||
58aab2821f | |||
95e47679d4 | |||
09a34d90f8 | |||
cc4c17bebe | |||
2470732df2 | |||
d96458d143 | |||
768d706144 | |||
5f120c2bb5 | |||
cb9f19c79d | |||
95d74dc76d | |||
de414301d9 | |||
5b0b1bc74f | |||
9e37ccbc4e | |||
461215a2d5 | |||
58debfb018 | |||
86ef61a916 | |||
ad6e3f6355 | |||
6456f6970c | |||
f4290334f3 | |||
7d0c79bd52 | |||
5f038227b0 | |||
7ea12afee9 | |||
e9228b447c | |||
806e2f4b29 | |||
f9a33c680d | |||
3be0a04a35 | |||
73c0744b0d | |||
f6f169428e | |||
580631d11d | |||
94a5449e10 | |||
b23f4cf42f | |||
9f9dca5b96 | |||
4d06e056f0 | |||
8a7b35fcfa | |||
3ce77fbd74 | |||
3790c79a59 | |||
2da7d63257 | |||
3cb7a5c34b | |||
5174db4b95 | |||
f7b217f0f7 | |||
306c9603b1 | |||
3e14aaad20 | |||
fc8bdd7f25 | |||
55506601a4 | |||
47b047d87c | |||
86bcd7dcf4 | |||
56d8d965d5 | |||
3bbbc899cc | |||
8e27c9804a | |||
9ec921835e | |||
5c252f79ca | |||
cc9ff70dba | |||
ff887b7b07 | |||
952324f86c | |||
6509db7e6e | |||
f27ce031b3 | |||
d4c0f9486d | |||
8c9ff9a303 | |||
cefccc4595 | |||
f5e1c13b37 | |||
0aa10fbbfb | |||
cad0fd83e5 | |||
8c6146dc5f | |||
76094023cd | |||
7ee8e9d92e | |||
c3b218e742 | |||
444be35fae | |||
8bb217b559 | |||
6357c14884 | |||
ff919b723f | |||
7f7ef72279 | |||
cec1ed59bc | |||
de0fe54ea1 | |||
aef1e35e2d | |||
a891201bdd | |||
06bb43c060 | |||
3bd88688f2 | |||
c1efb28ac6 | |||
188feaa476 | |||
a0e6aa8398 | |||
c935cdfd77 | |||
344ff332e7 | |||
bfeb2562f0 | |||
66dcfed64f | |||
d83554128b | |||
af6cb81ebb | |||
50110742f8 | |||
cc5a77bac3 | |||
7eeb22bff8 | |||
5d620fff37 | |||
6ee27b6136 | |||
1f5e9a8e30 | |||
a79130e5af | |||
b83d786bde | |||
a6727600e8 | |||
7e290406d0 | |||
9667d1aa07 | |||
9be3895215 | |||
e4fce7c075 | |||
e18b444d2a | |||
580db9060d | |||
15ccb8e214 | |||
f229b881bc | |||
13cf46cf43 | |||
ae61435334 | |||
42c255640c | |||
1b3b1d3779 | |||
2b81ccc4d4 | |||
c33bb130ab | |||
a05f856a8e | |||
6e1b20fcfb | |||
dce3fede2a | |||
9167581122 | |||
029a2b4e7d | |||
b014dd8218 | |||
dd42b5b6b6 | |||
65cd3e0852 | |||
1ee60b2c17 | |||
9a4123db14 | |||
f7eba39657 | |||
67d3a0be02 | |||
b8f295a78d | |||
4f76dcb9ff | |||
f5b9a0b985 |
16
.dockerignore
Normal file
16
.dockerignore
Normal file
@ -0,0 +1,16 @@
|
||||
# .git
|
||||
.vscode
|
||||
.env
|
||||
.venv
|
||||
env
|
||||
venv
|
||||
.pytest_cache
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
.Python
|
||||
tests
|
||||
GenshinUID.egg-info
|
||||
build
|
||||
__pycache__
|
||||
.pytest_cache
|
54
.github/workflows/pre-commit.yml
vendored
Normal file
54
.github/workflows/pre-commit.yml
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
name: Pre Commit
|
||||
on:
|
||||
- pull_request
|
||||
jobs:
|
||||
Pre-Commit:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.ref }}
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: "3.10"
|
||||
architecture: "x64"
|
||||
|
||||
- name: Setup pre-commit and actions-toolkit
|
||||
run: "python3 -m pip install pre-commit actions-toolkit"
|
||||
|
||||
- name: Run pre-commit
|
||||
run: python3 -c "import os;os.system('python3 -m pre_commit run --color never -a > result.txt')"
|
||||
|
||||
- name: Commit and push
|
||||
run: |
|
||||
git config user.name github-actions[bot]
|
||||
git config user.email github-actions[bot]@users.noreply.github.com
|
||||
git add .
|
||||
git diff-index --quiet HEAD || git commit -m ":rotating_light: auto fix by pre-commit"
|
||||
git push
|
||||
|
||||
- name: Read result
|
||||
id: rr
|
||||
run: python3 -c "from pathlib import Path;from actions_toolkit.core import set_output;comment=Path('./result.txt').read_text();set_output('comment', comment)"
|
||||
|
||||
- name: Find Comment
|
||||
uses: peter-evans/find-comment@v2
|
||||
id: fc
|
||||
with:
|
||||
issue-number: ${{ github.event.pull_request.number }}
|
||||
comment-author: "github-actions[bot]"
|
||||
body-includes: "pre-commit"
|
||||
|
||||
- name: Create or update comment
|
||||
uses: peter-evans/create-or-update-comment@v2
|
||||
with:
|
||||
comment-id: ${{ steps.fc.outputs.comment-id }}
|
||||
issue-number: ${{ github.event.pull_request.number }}
|
||||
body: |
|
||||
pre-commit output:
|
||||
```
|
||||
${{ steps.rr.outputs.COMMENT }}
|
||||
```
|
||||
edit-mode: replace
|
7
.gitignore
vendored
7
.gitignore
vendored
@ -210,7 +210,7 @@ celerybeat.pid
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.env/
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
@ -668,5 +668,6 @@ result.txt
|
||||
### GenshinUID ###
|
||||
GenshinUID/genshinuid_help/help.png
|
||||
GenshinUID/genshinuid_map/map_data
|
||||
.vscode/settings.json
|
||||
.vscode/settings.json
|
||||
|
||||
### Debug ###
|
||||
testnb2/
|
||||
|
@ -5,11 +5,6 @@ ci:
|
||||
autoupdate_schedule: monthly
|
||||
autoupdate_commit_msg: ":arrow_up: auto update by pre-commit-ci"
|
||||
repos:
|
||||
- repo: https://github.com/hadialqattan/pycln
|
||||
rev: v2.1.2
|
||||
hooks:
|
||||
- id: pycln
|
||||
|
||||
- repo: https://github.com/pycqa/isort
|
||||
rev: 5.11.5
|
||||
hooks:
|
||||
@ -25,17 +20,16 @@ repos:
|
||||
hooks:
|
||||
- id: flake8
|
||||
|
||||
- repo: https://github.com/hadialqattan/pycln
|
||||
rev: v2.1.2
|
||||
hooks:
|
||||
- id: pycln
|
||||
|
||||
- repo: https://github.com/python-poetry/poetry
|
||||
rev: 1.3.1
|
||||
hooks:
|
||||
- id: poetry-check
|
||||
- id: poetry-lock
|
||||
- id: poetry-export
|
||||
args:
|
||||
[
|
||||
"-f",
|
||||
"requirements.txt",
|
||||
"--without-hashes",
|
||||
"-o",
|
||||
"requirements.txt",
|
||||
]
|
||||
args: ["-f", "requirements.txt", "--without-hashes", "-o", "requirements.txt"]
|
||||
verbose: true
|
||||
|
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -1,14 +1,12 @@
|
||||
{
|
||||
"python.languageServer": "Pylance",
|
||||
"python.analysis.typeCheckingMode": "off",
|
||||
"python.analysis.typeCheckingMode": "basic",
|
||||
"cSpell.words": [
|
||||
"audioid",
|
||||
"enka",
|
||||
"genshin",
|
||||
"genshinuid",
|
||||
"minigg",
|
||||
"nonebot",
|
||||
"nonebug",
|
||||
"weapontype"
|
||||
],
|
||||
"[python]": {
|
||||
|
43
Dockerfile
Normal file
43
Dockerfile
Normal file
@ -0,0 +1,43 @@
|
||||
FROM python:3.9
|
||||
|
||||
# 1. 环境设置
|
||||
|
||||
# 使用镜像源
|
||||
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
|
||||
|
||||
RUN apt-get update && apt-get install -y tzdata
|
||||
|
||||
ENV TZ Asia/Shanghai
|
||||
|
||||
# 2. 安装 GenshinUID
|
||||
WORKDIR /plugin
|
||||
|
||||
COPY ./pyproject.toml ./LICENSE ./README.md /plugin/
|
||||
|
||||
COPY ./GenshinUID /plugin/GenshinUID/
|
||||
|
||||
RUN pip install --editable "."
|
||||
|
||||
COPY ./.git /plugin/.git
|
||||
|
||||
# 3. 生成 nb2 项目
|
||||
WORKDIR /nb2
|
||||
|
||||
RUN pip install tomlkit "cookiecutter>=2.1.1"
|
||||
|
||||
COPY ./deploy/cookiecutter.yml ./deploy/update_pyproject.py /nb2/
|
||||
|
||||
# RUN cookiecutter --config-file ./cookiecutter.yml https://github.com/nonebot/nb-cli.git --directory="nb_cli/project" --no-input
|
||||
# 使用镜像源
|
||||
RUN cookiecutter --config-file ./cookiecutter.yml https://ghproxy.com/https://github.com/nonebot/nb-cli.git --directory="nb_cli/project" --no-input
|
||||
|
||||
RUN python update_pyproject.py
|
||||
|
||||
COPY ./deploy/.env.dev /nb2/nb2/
|
||||
|
||||
WORKDIR /nb2/nb2
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
|
||||
CMD python bot.py
|
@ -0,0 +1,42 @@
|
||||
from nonebot.log import logger
|
||||
from nonebot import require, load_all_plugins, get_plugin_by_module_name
|
||||
|
||||
require('nonebot_plugin_apscheduler')
|
||||
|
||||
# from .utils.nonebot2.send import patch_send
|
||||
|
||||
# patch_send()
|
||||
if get_plugin_by_module_name("GenshinUID"):
|
||||
logger.info("推荐直接加载 GenshinUID 仓库文件夹")
|
||||
load_all_plugins(
|
||||
[
|
||||
'GenshinUID.genshinuid_abyss',
|
||||
'GenshinUID.genshinuid_adv',
|
||||
'GenshinUID.genshinuid_ann',
|
||||
'GenshinUID.genshinuid_gcg',
|
||||
'GenshinUID.genshinuid_xkdata',
|
||||
'GenshinUID.genshinuid_check',
|
||||
'GenshinUID.genshinuid_collection',
|
||||
'GenshinUID.genshinuid_config',
|
||||
'GenshinUID.genshinuid_enka',
|
||||
'GenshinUID.genshinuid_etcimg',
|
||||
'GenshinUID.genshinuid_eventlist',
|
||||
'GenshinUID.genshinuid_gachalog',
|
||||
'GenshinUID.genshinuid_guide',
|
||||
'GenshinUID.genshinuid_help',
|
||||
'GenshinUID.genshinuid_map',
|
||||
'GenshinUID.genshinuid_meta',
|
||||
'GenshinUID.genshinuid_mhybbscoin',
|
||||
'GenshinUID.genshinuid_mys',
|
||||
'GenshinUID.genshinuid_note',
|
||||
'GenshinUID.genshinuid_resin',
|
||||
'GenshinUID.genshinuid_resource',
|
||||
'GenshinUID.genshinuid_roleinfo',
|
||||
'GenshinUID.genshinuid_signin',
|
||||
'GenshinUID.genshinuid_user',
|
||||
'GenshinUID.genshinuid_wikitext',
|
||||
'GenshinUID.genshinuid_webconsole',
|
||||
'GenshinUID.genshinuid_update',
|
||||
],
|
||||
[],
|
||||
)
|
||||
|
@ -1,6 +0,0 @@
|
||||
import hoshino
|
||||
from hoshino import Service
|
||||
|
||||
sv = Service('genshinuid', bundle='genshin', help_='发送"原神帮助"查看详情')
|
||||
hoshino_bot = hoshino.get_bot()
|
||||
logger = sv.logger
|
5
GenshinUID/config.py
Normal file
5
GenshinUID/config.py
Normal file
@ -0,0 +1,5 @@
|
||||
from nonebot import get_driver
|
||||
|
||||
config = get_driver().config
|
||||
SUPERUSERS = {int(x) for x in config.superusers}
|
||||
priority = 2
|
@ -1,59 +1,78 @@
|
||||
import re
|
||||
from typing import Any, Tuple
|
||||
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot import on_regex
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import Depends, RegexGroup
|
||||
from nonebot.adapters.qqguild import MessageEvent, MessageSegment
|
||||
|
||||
from ..base import sv, logger
|
||||
from ..genshinuid_meta import register_menu
|
||||
from .draw_abyss_card import draw_abyss_img
|
||||
from ..utils.message.error_reply import UID_HINT
|
||||
from ..utils.message.cast_type import cast_to_int
|
||||
from ..utils.db_operation.db_operation import select_db
|
||||
from ..utils.message.get_image_and_at import ImageAndAt
|
||||
from ..utils.mhy_api.convert_mysid_to_uid import convert_mysid
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
|
||||
@sv.on_rex(
|
||||
get_abyss_info = on_regex(
|
||||
r'^(\[CQ:at,qq=[0-9]+\])?( )?'
|
||||
r'(uid|查询|mys)?([0-9]+)?(上期)?(深渊|sy)'
|
||||
r'(9|10|11|12|九|十|十一|十二)?(层)?'
|
||||
r'(\[CQ:at,qq=[0-9]+\])?( )?$',
|
||||
block=True,
|
||||
)
|
||||
async def send_abyss_info(bot: HoshinoBot, ev: CQEvent):
|
||||
args = ev['match'].groups()
|
||||
|
||||
|
||||
@get_abyss_info.handle()
|
||||
@handle_exception('查询深渊信息')
|
||||
@register_menu(
|
||||
'查询深渊信息',
|
||||
'查询(@某人)(上期)深渊(xx层)',
|
||||
'查询你的或者指定人的深渊战绩',
|
||||
detail_des=(
|
||||
'指令:'
|
||||
'<ft color=(238,120,0)>[查询</ft>'
|
||||
'<ft color=(125,125,125)>(@某人)</ft>'
|
||||
'<ft color=(238,120,0)>/uidxxx/mysxxx]</ft>'
|
||||
'<ft color=(125,125,125)>(上期)</ft>'
|
||||
'<ft color=(238,120,0)>深渊</ft>'
|
||||
'<ft color=(125,125,125)>(xx层)</ft>\n'
|
||||
' \n' # 如果想要空行,请在换行符前面打个空格,不然会忽略换行符
|
||||
'可以用来查看你的或者指定人的深渊战绩,可以指定层数,默认为最高层数\n'
|
||||
'可以在命令文本后带一张图以自定义背景图\n'
|
||||
' \n'
|
||||
'示例:\n'
|
||||
'<ft color=(238,120,0)>查询深渊</ft>;\n'
|
||||
'<ft color=(238,120,0)>uid123456789上期深渊</ft>;\n'
|
||||
'<ft color=(238,120,0)>查询</ft><ft color=(0,148,200)>@无疑Wuyi</ft> '
|
||||
'<ft color=(238,120,0)>上期深渊12层</ft>'
|
||||
),
|
||||
)
|
||||
async def send_abyss_info(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
args: Tuple[Any, ...] = RegexGroup(),
|
||||
custom: ImageAndAt = Depends(),
|
||||
):
|
||||
logger.info('开始执行[查询深渊信息]')
|
||||
logger.info('[查询深渊信息]参数: {}'.format(args))
|
||||
at = re.search(r'\[CQ:at,qq=(\d*)]', str(ev.message))
|
||||
|
||||
if at:
|
||||
qid = int(at.group(1))
|
||||
else:
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
|
||||
# 判断uid
|
||||
if args[2] != 'mys':
|
||||
if args[3] is None:
|
||||
uid = await select_db(qid, mode='uid')
|
||||
logger.info(f'[查询深渊信息]参数: {args}')
|
||||
at = custom.get_first_at()
|
||||
qid = at or cast_to_int(event.author)
|
||||
if args[2] == 'mys':
|
||||
uid = await convert_mysid(args[3])
|
||||
elif args[3] is None:
|
||||
uid = await select_db(str(qid), mode='uid')
|
||||
uid = str(uid)
|
||||
elif len(args[3]) != 9:
|
||||
return
|
||||
else:
|
||||
uid = args[3]
|
||||
else:
|
||||
uid = await convert_mysid(args[3])
|
||||
|
||||
logger.info('[查询深渊信息]uid: {}'.format(uid))
|
||||
|
||||
logger.info(f'[查询深渊信息]uid: {uid}')
|
||||
if '未找到绑定的UID' in uid:
|
||||
await bot.send(ev, UID_HINT)
|
||||
|
||||
# 判断深渊期数
|
||||
if args[4] is None:
|
||||
schedule_type = '1'
|
||||
else:
|
||||
schedule_type = '2'
|
||||
logger.info('[查询深渊信息]深渊期数: {}'.format(schedule_type))
|
||||
|
||||
await matcher.finish(UID_HINT)
|
||||
schedule_type = '1' if args[4] is None else '2'
|
||||
logger.info(f'[查询深渊信息]深渊期数: {schedule_type}')
|
||||
if args[6] in ['九', '十', '十一', '十二']:
|
||||
floor = (
|
||||
args[6]
|
||||
@ -62,17 +81,16 @@ async def send_abyss_info(bot: HoshinoBot, ev: CQEvent):
|
||||
.replace('十二', '12')
|
||||
.replace('十', '10')
|
||||
)
|
||||
|
||||
else:
|
||||
floor = args[6]
|
||||
if floor is not None:
|
||||
floor = int(floor)
|
||||
logger.info('[查询深渊信息]深渊层数: {}'.format(floor))
|
||||
|
||||
logger.info(f'[查询深渊信息]深渊层数: {floor}')
|
||||
im = await draw_abyss_img(uid, floor, schedule_type)
|
||||
if isinstance(im, str):
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
elif isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
await bot.send(ev, '发生了未知错误,请联系管理员检查后台输出!')
|
||||
await matcher.finish('发生了未知错误,请联系管理员检查后台输出!')
|
||||
|
@ -1,36 +1,34 @@
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot import on_command
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import CommandArg
|
||||
from nonebot.adapters.qqguild import Message
|
||||
|
||||
from ..base import sv, logger
|
||||
from ..config import priority
|
||||
from .get_achi_desc import get_achi, get_daily_achi
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
get_task_info = on_command('查委托', aliases={'委托'}, priority=priority)
|
||||
get_achi_info = on_command('查成就', aliases={'成就'}, priority=priority)
|
||||
|
||||
|
||||
@sv.on_prefix('查委托')
|
||||
async def send_task_info(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
message = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
@get_task_info.handle()
|
||||
@handle_exception('查委托')
|
||||
async def send_task_info(matcher: Matcher, args: Message = CommandArg()):
|
||||
if not args:
|
||||
return
|
||||
|
||||
if message == '':
|
||||
return
|
||||
|
||||
name = str(message)
|
||||
name = str(args[0])
|
||||
logger.info(f'[查委托] 参数:{name}')
|
||||
im = await get_daily_achi(name)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
||||
|
||||
@sv.on_prefix('查成就')
|
||||
async def send_achi_info(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
message = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
@get_achi_info.handle()
|
||||
@handle_exception('查成就')
|
||||
async def send_achi_info(matcher: Matcher, args: Message = CommandArg()):
|
||||
if not args:
|
||||
return
|
||||
|
||||
if message == '':
|
||||
return
|
||||
|
||||
name = str(message)
|
||||
name = str(args[0])
|
||||
logger.info(f'[查成就] 参数:{name}')
|
||||
im = await get_achi(name)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
@ -1,19 +1,68 @@
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from typing import Any, Tuple
|
||||
|
||||
from ..base import sv
|
||||
from nonebot import on_regex
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import RegexGroup
|
||||
|
||||
from ..config import priority
|
||||
from .get_adv import char_adv, weapon_adv
|
||||
from ..genshinuid_meta import register_menu
|
||||
from ..utils.alias.alias_to_char_name import alias_to_char_name
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
get_char_adv = on_regex('([\u4e00-\u9fa5]+)(用什么|能用啥|怎么养)', priority=priority)
|
||||
get_weapon_adv = on_regex(
|
||||
'([\u4e00-\u9fa5]+)(能给谁|给谁用|要给谁|谁能用)', priority=priority
|
||||
)
|
||||
|
||||
|
||||
@sv.on_rex(r'([\u4e00-\u9fa5]+)(用什么|能用啥|怎么养)')
|
||||
async def send_char_adv(bot: HoshinoBot, ev: CQEvent):
|
||||
name = await alias_to_char_name(str(ev['match'].group(1)))
|
||||
@get_char_adv.handle()
|
||||
@handle_exception('建议')
|
||||
@register_menu(
|
||||
'角色配置推荐',
|
||||
'xx用什么',
|
||||
'查询角色武器/圣遗物推荐配置',
|
||||
detail_des=(
|
||||
'指令:'
|
||||
'<ft color=(238,120,0)>[角色名][用什么/能用啥/怎么养]</ft>\n'
|
||||
' \n'
|
||||
'可以查询某角色的武器/圣遗物推荐配置\n'
|
||||
'支持部分角色别名\n'
|
||||
' \n'
|
||||
'示例:\n'
|
||||
'<ft color=(238,120,0)>钟离用什么</ft>;\n'
|
||||
'<ft color=(238,120,0)>公子怎么养</ft>'
|
||||
),
|
||||
)
|
||||
async def send_char_adv(
|
||||
matcher: Matcher, args: Tuple[Any, ...] = RegexGroup()
|
||||
):
|
||||
name = await alias_to_char_name(str(args[0]))
|
||||
im = await char_adv(name)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
||||
|
||||
@sv.on_rex(r'([\u4e00-\u9fa5]+)(能给谁|给谁用|要给谁|谁能用)')
|
||||
async def send_weapon_adv(bot: HoshinoBot, ev: CQEvent):
|
||||
name = await alias_to_char_name(str(ev['match'].group(1)))
|
||||
@get_weapon_adv.handle()
|
||||
@handle_exception('建议')
|
||||
@register_menu(
|
||||
'装备适用角色',
|
||||
'xx能给谁',
|
||||
'查询某武器/圣遗物能给谁用',
|
||||
detail_des=(
|
||||
'指令:'
|
||||
'<ft color=(238,120,0)>[角色名][能给谁/给谁用/要给谁/谁能用]</ft>\n'
|
||||
' \n'
|
||||
'可以通过武器/圣遗物名反查适用的角色\n'
|
||||
'支持部分别名\n'
|
||||
' \n'
|
||||
'示例:\n'
|
||||
'<ft color=(238,120,0)>四风原典能给谁</ft>;\n'
|
||||
'<ft color=(238,120,0)>千岩给谁用</ft>'
|
||||
),
|
||||
)
|
||||
async def send_weapon_adv(
|
||||
matcher: Matcher, args: Tuple[Any, ...] = RegexGroup()
|
||||
):
|
||||
name = await alias_to_char_name(str(args[0]))
|
||||
im = await weapon_adv(name)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
@ -1,90 +1,92 @@
|
||||
import random
|
||||
import asyncio
|
||||
|
||||
from nonebot import get_bot
|
||||
from hoshino import Service, priv
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import CommandArg
|
||||
from nonebot import get_bot, on_command
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot.adapters.qqguild import Message, MessageEvent, MessageSegment
|
||||
|
||||
from ..base import logger
|
||||
from .util import black_ids
|
||||
from ..config import priority
|
||||
from .main import ann, consume_remind
|
||||
from ..utils.nonebot2.rule import FullCommand
|
||||
from ..utils.message.error_reply import UID_HINT
|
||||
from ..utils.message.cast_type import cast_to_int
|
||||
from ..utils.db_operation.db_operation import select_db
|
||||
from ..genshinuid_config.default_config import string_config
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
from .ann_card import sub_ann, unsub_ann, ann_list_card, ann_detail_card
|
||||
|
||||
sv_help = '''
|
||||
原神公告
|
||||
原神公告#ID
|
||||
'''.strip()
|
||||
|
||||
sv = Service(
|
||||
name='原神公告', # 功能名
|
||||
use_priv=priv.NORMAL, # 使用权限
|
||||
manage_priv=priv.ADMIN, # 管理权限
|
||||
visible=True, # 可见性
|
||||
enable_on_default=True, # 默认启用
|
||||
# bundle = '娱乐', #分组归类
|
||||
help_=sv_help, # 帮助说明
|
||||
update_ann_scheduler = scheduler
|
||||
get_ann_info = on_command('原神公告', priority=priority)
|
||||
reg_ann = on_command(
|
||||
'订阅原神公告', priority=priority, rule=FullCommand(), permission=SUPERUSER
|
||||
)
|
||||
|
||||
prefix = '原神'
|
||||
unreg_ann = on_command(
|
||||
'取消订阅原神公告',
|
||||
aliases={'取消原神公告', '退订原神公告'},
|
||||
priority=priority,
|
||||
rule=FullCommand(),
|
||||
permission=SUPERUSER,
|
||||
)
|
||||
consume_ann = on_command('清除原神公告红点', priority=priority, rule=FullCommand())
|
||||
|
||||
|
||||
@sv.on_prefix((f'{prefix}公告#', f'{prefix}公告'))
|
||||
async def ann_(bot, ev):
|
||||
ann_id = ev.message.extract_plain_text().strip()
|
||||
@get_ann_info.handle()
|
||||
@handle_exception('原神公告', '获取/发送原神公告失败')
|
||||
async def send_ann_pic(
|
||||
matcher: Matcher,
|
||||
args: Message = CommandArg(),
|
||||
):
|
||||
ann_id = str(args).replace(' ', '').replace('#', '')
|
||||
|
||||
if not ann_id:
|
||||
img = await ann_list_card()
|
||||
img = await convert_img(img)
|
||||
await bot.send(ev, img, at_sender=True)
|
||||
return
|
||||
await matcher.finish(MessageSegment.file_image(img))
|
||||
|
||||
if not ann_id.isdigit():
|
||||
raise Exception("公告ID不正确")
|
||||
try:
|
||||
|
||||
img = await ann_detail_card(int(ann_id))
|
||||
img = await convert_img(img)
|
||||
await bot.send(ev, img, at_sender=True)
|
||||
except Exception as e:
|
||||
await bot.finish(ev, str(e))
|
||||
await matcher.finish(MessageSegment.file_image(img))
|
||||
|
||||
|
||||
@sv.on_fullmatch(f'订阅{prefix}公告')
|
||||
async def sub_ann_(bot, ev):
|
||||
if not priv.check_priv(ev, priv.ADMIN):
|
||||
raise Exception("你没有权限开启原神公告推送")
|
||||
try:
|
||||
await bot.send(ev, sub_ann(ev.group_id))
|
||||
except Exception as e:
|
||||
await bot.finish(ev, str(e))
|
||||
@reg_ann.handle()
|
||||
@handle_exception('设置原神公告', '设置原神公告失败')
|
||||
async def send_reg_ann(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
await matcher.finish(sub_ann(event.channel_id))
|
||||
|
||||
|
||||
@sv.on_fullmatch((f'取消订阅{prefix}公告', f'取消{prefix}公告', f'退订{prefix}公告'))
|
||||
async def unsub_ann_(bot, ev):
|
||||
if not priv.check_priv(ev, priv.ADMIN):
|
||||
raise Exception("你没有权限取消原神公告推送")
|
||||
try:
|
||||
await bot.send(ev, unsub_ann(ev.group_id))
|
||||
except Exception as e:
|
||||
await bot.finish(ev, str(e))
|
||||
@unreg_ann.handle()
|
||||
@handle_exception('取消原神公告', '取消设置原神公告失败')
|
||||
async def send_unreg_ann(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
await matcher.finish(unsub_ann(event.channel_id))
|
||||
|
||||
|
||||
@sv.on_fullmatch(f'取消{prefix}公告红点')
|
||||
async def consume_remind_(bot, ev):
|
||||
try:
|
||||
qid = int(ev.sender['user_id'])
|
||||
@consume_ann.handle()
|
||||
@handle_exception('取消原神公告红点', '取消红点失败')
|
||||
async def send_consume_ann(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
qid = str(cast_to_int(event.author))
|
||||
uid = await select_db(qid, mode='uid')
|
||||
uid = str(uid)
|
||||
if '未找到绑定的UID' in uid:
|
||||
await bot.send(ev, UID_HINT)
|
||||
return
|
||||
await bot.send(ev, await consume_remind(uid), at_sender=True)
|
||||
except Exception as e:
|
||||
await bot.finish(ev, str(e))
|
||||
await matcher.finish(UID_HINT)
|
||||
await matcher.finish(await consume_remind(uid))
|
||||
|
||||
|
||||
@sv.scheduled_job('cron', minute=10)
|
||||
@update_ann_scheduler.scheduled_job('cron', minute=10)
|
||||
async def check_ann():
|
||||
await check_ann_state()
|
||||
|
||||
@ -117,12 +119,15 @@ async def check_ann_state():
|
||||
if ann_id in black_ids:
|
||||
continue
|
||||
try:
|
||||
img = await ann_detail_card(ann_id)
|
||||
img = await convert_img(img)
|
||||
img = await ann_detail_card(ann_id) # 防止抛出异常报错
|
||||
bot = get_bot()
|
||||
for group in sub_list:
|
||||
try:
|
||||
await bot.send_group_msg(group_id=group, message=img)
|
||||
await bot.call_api(
|
||||
api='_post_messages',
|
||||
channel_id=group,
|
||||
content=img,
|
||||
)
|
||||
await asyncio.sleep(random.uniform(1, 3))
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
|
@ -1,101 +1,116 @@
|
||||
import random
|
||||
import asyncio
|
||||
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot import on_command
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot.adapters.qqguild import Bot, MessageEvent
|
||||
|
||||
from ..base import sv, logger
|
||||
from ..config import priority
|
||||
from .backup_data import data_backup
|
||||
from ..genshinuid_meta import register_menu
|
||||
from ..utils.nonebot2.rule import FullCommand
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
from ..utils.db_operation.db_cache_and_check import check_db, check_stoken_db
|
||||
from ..utils.db_operation.db_operation import delete_cookies, get_all_push_list
|
||||
from ..utils.message.get_cqhttp_data import (
|
||||
get_all_friend_list,
|
||||
get_group_member_list,
|
||||
|
||||
backup = on_command('gs清除缓存', rule=FullCommand(), priority=priority)
|
||||
check = on_command('校验全部Cookies', rule=FullCommand(), priority=priority)
|
||||
check_stoken = on_command('校验全部Stoken', rule=FullCommand(), priority=priority)
|
||||
remove_invalid_user = on_command(
|
||||
'清除无效用户', rule=FullCommand(), priority=priority
|
||||
)
|
||||
|
||||
backup_scheduler = scheduler
|
||||
|
||||
@sv.scheduled_job('cron', hour=0)
|
||||
|
||||
@backup_scheduler.scheduled_job('cron', hour=0)
|
||||
async def daily_refresh_charData():
|
||||
await data_backup()
|
||||
|
||||
|
||||
@sv.on_fullmatch('gs清除缓存')
|
||||
@backup.handle()
|
||||
@handle_exception('清除缓存', '清除缓存错误')
|
||||
async def send_backup_msg(
|
||||
bot: HoshinoBot,
|
||||
ev: CQEvent,
|
||||
bot: Bot,
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
if not await SUPERUSER(bot, event):
|
||||
return
|
||||
if qid not in bot.config.SUPERUSERS:
|
||||
return
|
||||
|
||||
await data_backup()
|
||||
await bot.send(ev, '操作成功完成!')
|
||||
|
||||
|
||||
@sv.on_fullmatch('清除无效用户')
|
||||
async def send_remove_invalid_user_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
if qid not in bot.config.SUPERUSERS:
|
||||
return
|
||||
im_list = []
|
||||
invalid_user = {}
|
||||
invalid_uid_list = []
|
||||
user_list = await get_all_push_list()
|
||||
friend_list = await get_all_friend_list(bot)
|
||||
for user in user_list:
|
||||
if user['StatusA'] == 'on':
|
||||
if user['QID'] not in friend_list:
|
||||
invalid_user['qid'] = user['UID']
|
||||
invalid_uid_list.append(user['UID'])
|
||||
else:
|
||||
group_member_list = await get_group_member_list(
|
||||
bot, int(user['StatusA'])
|
||||
)
|
||||
if user['QID'] not in group_member_list:
|
||||
invalid_user['qid'] = user['UID']
|
||||
invalid_uid_list.append(user['UID'])
|
||||
for uid in invalid_uid_list:
|
||||
im_list.append(await delete_cookies(str(uid)))
|
||||
logger.warning(f'无效UID已被删除: {uid}')
|
||||
await bot.send(ev, f'已清理失效用户{len(im_list)}个!')
|
||||
await matcher.finish('操作成功完成!')
|
||||
|
||||
|
||||
# 群聊内 校验Cookies 是否正常的功能,不正常自动删掉
|
||||
@sv.on_fullmatch('校验全部Cookies')
|
||||
async def send_check_cookies(bot: HoshinoBot, ev: CQEvent):
|
||||
@check.handle()
|
||||
@handle_exception('Cookie校验', 'Cookie校验错误')
|
||||
@register_menu(
|
||||
'校验全部Cookies',
|
||||
'校验全部Cookies',
|
||||
'校验数据库内所有Cookies是否正常',
|
||||
trigger_method='管理员指令',
|
||||
detail_des=(
|
||||
'指令:'
|
||||
'<ft color=(238,120,0)>校验全部Cookies</ft>\n'
|
||||
'注意<ft color=(238,120,0)>Cookies</ft>的'
|
||||
'<ft color=(238,120,0)>C</ft>为大写\n'
|
||||
' \n'
|
||||
'校验数据库内所有Cookies是否正常,不正常的会自动删除'
|
||||
),
|
||||
)
|
||||
async def send_check_cookie(bot: Bot, matcher: Matcher):
|
||||
raw_mes = await check_db()
|
||||
im = raw_mes[0]
|
||||
await bot.send(ev, im)
|
||||
await matcher.send(im)
|
||||
for i in raw_mes[1]:
|
||||
await bot.send_private_msg(
|
||||
user_id=i[0],
|
||||
message=(
|
||||
await bot.call_api(
|
||||
api='send_private_msg',
|
||||
**{
|
||||
'user_id': i[0],
|
||||
'message': (
|
||||
'您绑定的Cookies(uid{})已失效,以下功能将会受到影响:\n'
|
||||
'查看完整信息列表\n查看深渊配队\n自动签到/当前状态/每月统计\n'
|
||||
'请及时重新绑定Cookies并重新开关相应功能。'
|
||||
).format(i[1]),
|
||||
},
|
||||
)
|
||||
await asyncio.sleep(3 + random.randint(1, 3))
|
||||
await matcher.finish()
|
||||
|
||||
|
||||
# 群聊内 校验Stoken 是否正常的功能,不正常自动删掉
|
||||
@sv.on_fullmatch('校验全部Stoken')
|
||||
async def send_check_stoken(bot: HoshinoBot, ev: CQEvent):
|
||||
@check_stoken.handle()
|
||||
@handle_exception('Stoken校验', 'Stoken校验错误')
|
||||
@register_menu(
|
||||
'校验全部Stoken',
|
||||
'校验全部Stoken',
|
||||
'校验数据库内所有Stoken是否正常',
|
||||
trigger_method='管理员指令',
|
||||
detail_des=(
|
||||
'指令:'
|
||||
'<ft color=(238,120,0)>校验全部Stoken</ft>\n'
|
||||
'注意<ft color=(238,120,0)>Stoken</ft>的<ft color=(238,120,0)>S</ft>为大写\n'
|
||||
' \n'
|
||||
'校验数据库内所有Stoken是否正常,不正常的会自动删除'
|
||||
),
|
||||
)
|
||||
async def send_check_stoken(bot: Bot, matcher: Matcher):
|
||||
raw_mes = await check_stoken_db()
|
||||
im = raw_mes[0]
|
||||
await bot.send(ev, im)
|
||||
await matcher.send(im)
|
||||
for i in raw_mes[1]:
|
||||
await bot.send_private_msg(
|
||||
user_id=i[0],
|
||||
message=(
|
||||
await bot.call_api(
|
||||
api='send_private_msg',
|
||||
**{
|
||||
'user_id': i[0],
|
||||
'message': (
|
||||
'您绑定的Stoken(uid{})已失效,以下功能将会受到影响:\n'
|
||||
'gs开启自动米游币,开始获取米游币。\n'
|
||||
'重新添加后需要重新开启自动米游币。'
|
||||
).format(i[1]),
|
||||
},
|
||||
)
|
||||
await asyncio.sleep(3 + random.randint(1, 3))
|
||||
|
||||
await matcher.finish()
|
||||
|
@ -1,70 +1,97 @@
|
||||
import re
|
||||
from nonebot import on_command
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import Depends, CommandArg
|
||||
from nonebot.adapters.qqguild import Message, MessageEvent, MessageSegment
|
||||
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
|
||||
from ..base import sv, logger
|
||||
from ..genshinuid_meta import register_menu
|
||||
from ..utils.data_convert.get_uid import get_uid
|
||||
from ..utils.message.error_reply import UID_HINT
|
||||
from ..utils.message.error_reply import * # noqa: F403,F401
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.message.cast_type import cast_to_int
|
||||
from ..utils.message.get_image_and_at import ImageAndAt
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
from .draw_collection_card import draw_explora_img, draw_collection_img
|
||||
|
||||
get_collection_info = on_command('查询收集', aliases={'收集', 'sj'}, block=True)
|
||||
get_explora_info = on_command('查询探索', aliases={'探索', 'ts'}, block=True)
|
||||
|
||||
@sv.on_prefix(('查询收集', '收集', 'sj'))
|
||||
async def send_collection_info(bot: HoshinoBot, ev: CQEvent):
|
||||
raw_mes = ev.message.extract_plain_text().replace(' ', '')
|
||||
|
||||
@get_collection_info.handle()
|
||||
@handle_exception('查询收集信息')
|
||||
@register_menu(
|
||||
'查询收集信息',
|
||||
'查询(@某人)收集',
|
||||
'查询你的或者指定人的宝箱收集度',
|
||||
detail_des=(
|
||||
'指令:'
|
||||
'<ft color=(238,120,0)>[查询</ft>'
|
||||
'<ft color=(125,125,125)>(@某人)</ft>'
|
||||
'<ft color=(238,120,0)>/uidxxx/mysxxx]</ft>'
|
||||
'<ft color=(238,120,0)>[收集/宝箱/sj/bx]</ft>\n'
|
||||
' \n'
|
||||
'可以用来查看你的或者指定人的宝箱收集度\n'
|
||||
'可以在命令文本后带一张图以自定义背景图\n'
|
||||
' \n'
|
||||
'示例:\n'
|
||||
'<ft color=(238,120,0)>查询收集</ft>;\n'
|
||||
'<ft color=(238,120,0)>uid123456789宝箱</ft>;\n'
|
||||
'<ft color=(238,120,0)>查询</ft><ft color=(0,148,200)>@无疑Wuyi'
|
||||
'</ft> <ft color=(238,120,0)>bx</ft>'
|
||||
),
|
||||
)
|
||||
async def send_collection_info(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
args: Message = CommandArg(),
|
||||
custom: ImageAndAt = Depends(),
|
||||
):
|
||||
logger.info('开始执行[查询收集信息]')
|
||||
at = re.search(r'\[CQ:at,qq=(\d*)]', raw_mes)
|
||||
|
||||
if at:
|
||||
qid = int(at.group(1))
|
||||
else:
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
logger.info('[查询收集信息]参数: {}'.format(args))
|
||||
raw_mes = args.extract_plain_text().strip()
|
||||
at = custom.get_first_at()
|
||||
qid = at or cast_to_int(event.author)
|
||||
qid = str(qid)
|
||||
|
||||
uid = await get_uid(qid, raw_mes)
|
||||
logger.info('[查询收集信息]uid: {}'.format(uid))
|
||||
|
||||
if '未找到绑定的UID' in uid:
|
||||
await bot.send(ev, UID_HINT)
|
||||
await matcher.finish(UID_HINT)
|
||||
|
||||
im = await draw_collection_img(qid, uid)
|
||||
if isinstance(im, str):
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
elif isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
await bot.send(ev, '发生了未知错误,请联系管理员检查后台输出!')
|
||||
await matcher.finish('发生了未知错误,请联系管理员检查后台输出!')
|
||||
|
||||
|
||||
@sv.on_prefix(('查询探索', '探索', 'ts'))
|
||||
async def send_explora_info(bot: HoshinoBot, ev: CQEvent):
|
||||
raw_mes = ev.message.extract_plain_text().replace(' ', '')
|
||||
@get_explora_info.handle()
|
||||
@handle_exception('查询探索信息')
|
||||
async def send_explora_info(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
args: Message = CommandArg(),
|
||||
custom: ImageAndAt = Depends(),
|
||||
):
|
||||
logger.info('开始执行[查询探索信息]')
|
||||
at = re.search(r'\[CQ:at,qq=(\d*)]', raw_mes)
|
||||
|
||||
if at:
|
||||
qid = int(at.group(1))
|
||||
else:
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
logger.info('[查询探索信息]参数: {}'.format(args))
|
||||
raw_mes = args.extract_plain_text().strip()
|
||||
at = custom.get_first_at()
|
||||
qid = at or cast_to_int(event.author)
|
||||
qid = str(qid)
|
||||
|
||||
uid = await get_uid(qid, raw_mes)
|
||||
logger.info('[查询探索信息]uid: {}'.format(uid))
|
||||
|
||||
if '未找到绑定的UID' in uid:
|
||||
await bot.send(ev, UID_HINT)
|
||||
await matcher.finish(UID_HINT)
|
||||
|
||||
im = await draw_explora_img(qid, uid)
|
||||
if isinstance(im, str):
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
elif isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
await bot.send(ev, '发生了未知错误,请联系管理员检查后台输出!')
|
||||
await matcher.finish('发生了未知错误,请联系管理员检查后台输出!')
|
||||
|
@ -1,126 +1,124 @@
|
||||
import re
|
||||
from typing import Any, Tuple
|
||||
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot import on_regex, on_command
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot.params import Depends, CommandArg, RegexGroup
|
||||
from nonebot.adapters.qqguild import Bot, Message, MessageEvent, MessageSegment
|
||||
|
||||
from ..base import sv, logger
|
||||
from .draw_config_card import draw_config_img
|
||||
from ..utils.message.error_reply import UID_HINT
|
||||
from ..utils.message.cast_type import cast_to_int
|
||||
from ..utils.db_operation.db_operation import select_db
|
||||
from ..utils.message.get_image_and_at import ImageAndAt
|
||||
from .set_config import set_push_value, set_config_func
|
||||
from ..utils.message.error_reply import * # noqa: F403,F401
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
open_and_close_switch = on_regex(
|
||||
r'^(\[CQ:at,qq=[0-9]+\])?( )?'
|
||||
r'(gs)(开启|关闭)(.*)'
|
||||
r'(\[CQ:at,qq=[0-9]+\])?( )?$'
|
||||
)
|
||||
|
||||
@sv.on_fullmatch('gs配置')
|
||||
async def send_config_card(bot: HoshinoBot, ev: CQEvent):
|
||||
logger.info('开始执行[gs配置]')
|
||||
im = await draw_config_img()
|
||||
if isinstance(im, str):
|
||||
await bot.send(ev, im)
|
||||
elif isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
else:
|
||||
await bot.send(ev, '发生了未知错误,请联系管理员检查后台输出!')
|
||||
|
||||
|
||||
@sv.on_rex(
|
||||
push_config = on_regex(
|
||||
r'^(\[CQ:at,qq=[0-9]+\])?( )?'
|
||||
r'(gs)(设置)([\u4e00-\u9fffa-zA-Z]*)([0-9]*)'
|
||||
r'(\[CQ:at,qq=[0-9]+\])?( )?$'
|
||||
)
|
||||
async def send_config_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
args = ev['match'].groups()
|
||||
|
||||
config_card = on_command('gs配置')
|
||||
|
||||
|
||||
@config_card.handle()
|
||||
@handle_exception('发送配置表')
|
||||
async def send_config_card(matcher: Matcher, args: Message = CommandArg()):
|
||||
if args:
|
||||
await matcher.finish()
|
||||
logger.info('开始执行[gs配置]')
|
||||
im = await draw_config_img()
|
||||
if isinstance(im, str):
|
||||
await matcher.finish(im)
|
||||
elif isinstance(im, bytes):
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
await matcher.finish('发生了未知错误,请联系管理员检查后台输出!')
|
||||
|
||||
|
||||
@push_config.handle()
|
||||
@handle_exception('设置推送服务')
|
||||
async def send_config_msg(
|
||||
bot: Bot,
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
args: Tuple[Any, ...] = RegexGroup(),
|
||||
custom: ImageAndAt = Depends(),
|
||||
):
|
||||
logger.info('开始执行[设置阈值信息]')
|
||||
logger.info('[设置阈值信息]参数: {}'.format(args))
|
||||
qid = cast_to_int(event.author)
|
||||
at = custom.get_first_at()
|
||||
|
||||
at = re.search(r'\[CQ:at,qq=(\d*)]', str(ev.message))
|
||||
|
||||
if at:
|
||||
qid = int(at.group(1))
|
||||
else:
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
|
||||
if qid in bot.config.SUPERUSERS:
|
||||
is_admin = True
|
||||
else:
|
||||
is_admin = False
|
||||
|
||||
if at and is_admin:
|
||||
if at and await SUPERUSER(bot, event):
|
||||
qid = at
|
||||
elif at and at != qid:
|
||||
await bot.send(ev, '你没有权限操作别人的状态噢~', at_sender=True)
|
||||
await matcher.finish('你没有权限操作别人的状态噢~', at_sender=True)
|
||||
logger.info('[设置阈值信息]qid: {}'.format(qid))
|
||||
|
||||
try:
|
||||
uid = await select_db(qid, mode='uid')
|
||||
uid = await select_db(str(qid), mode='uid')
|
||||
except TypeError:
|
||||
await bot.send(ev, UID_HINT)
|
||||
return
|
||||
await matcher.finish(UID_HINT)
|
||||
|
||||
func = args[4].replace('阈值', '')
|
||||
if args[5]:
|
||||
try:
|
||||
value = int(args[5])
|
||||
except ValueError:
|
||||
await bot.send(ev, '请输入数字哦~', at_sender=True)
|
||||
return
|
||||
await matcher.finish('请输入数字哦~', at_sender=True)
|
||||
else:
|
||||
await bot.send(ev, '请输入正确的阈值数字!', at_sender=True)
|
||||
return
|
||||
await matcher.finish('请输入正确的阈值数字!', at_sender=True)
|
||||
logger.info('[设置阈值信息]func: {}, value: {}'.format(func, value))
|
||||
im = await set_push_value(func, str(uid), value)
|
||||
await bot.send(ev, im, at_sender=True)
|
||||
await matcher.finish(im, at_sender=True)
|
||||
|
||||
|
||||
# 开启 自动签到 和 推送树脂提醒 功能
|
||||
@sv.on_rex(
|
||||
r'^(\[CQ:at,qq=[0-9]+\])?( )?'
|
||||
r'(gs)(开启|关闭)(.*)'
|
||||
r'(\[CQ:at,qq=[0-9]+\])?( )?$'
|
||||
)
|
||||
async def open_switch_func(bot: HoshinoBot, ev: CQEvent):
|
||||
args = ev['match'].groups()
|
||||
at = re.search(r'\[CQ:at,qq=(\d*)]', str(ev.message))
|
||||
|
||||
@open_and_close_switch.handle()
|
||||
async def open_switch_func(
|
||||
bot: Bot,
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
args: Tuple[Any, ...] = RegexGroup(),
|
||||
at: ImageAndAt = Depends(),
|
||||
):
|
||||
qid = cast_to_int(event.author)
|
||||
if at:
|
||||
qid = int(at.group(1))
|
||||
else:
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
|
||||
at = at.get_first_at() # type: ignore
|
||||
config_name = args[4]
|
||||
|
||||
logger.info(f'[{qid}]尝试[{args[3]}]了[{config_name}]功能')
|
||||
|
||||
if args[3] == '开启':
|
||||
query = 'OPEN'
|
||||
gid = str(ev.group_id) if ev.group_id else 'on'
|
||||
gid = (
|
||||
event.get_session_id().split('_')[1]
|
||||
if len(event.get_session_id().split('_')) == 3
|
||||
else 'on'
|
||||
)
|
||||
else:
|
||||
query = 'CLOSED'
|
||||
gid = 'off'
|
||||
|
||||
if qid in bot.config.SUPERUSERS:
|
||||
is_admin = True
|
||||
else:
|
||||
is_admin = False
|
||||
|
||||
is_admin = await SUPERUSER(bot, event)
|
||||
if at and is_admin:
|
||||
qid = at
|
||||
elif at and at != qid:
|
||||
bot.send(ev, '你没有权限操作别人的状态噢~', at_sender=True)
|
||||
return
|
||||
await matcher.finish('你没有权限操作别人的状态噢~', at_sender=True)
|
||||
|
||||
try:
|
||||
uid = await select_db(qid, mode='uid')
|
||||
uid = await select_db(str(qid), mode='uid')
|
||||
except TypeError:
|
||||
await bot.send(ev, UID_HINT)
|
||||
return
|
||||
await matcher.finish(UID_HINT)
|
||||
|
||||
im = await set_config_func(
|
||||
config_name=config_name,
|
||||
@ -130,4 +128,4 @@ async def open_switch_func(bot: HoshinoBot, ev: CQEvent):
|
||||
query=query,
|
||||
is_admin=is_admin,
|
||||
)
|
||||
await bot.send(ev, im, at_sender=True)
|
||||
await matcher.finish(im, at_sender=True)
|
||||
|
@ -1,17 +1,15 @@
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot import on_command
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.permission import SUPERUSER
|
||||
|
||||
from ..base import sv
|
||||
from .export_data import export_v3
|
||||
from ..utils.nonebot2.rule import FullCommand
|
||||
|
||||
export_v3_data = on_command('导出v3数据', permission=SUPERUSER, rule=FullCommand())
|
||||
|
||||
|
||||
@sv.on_prefix(('导出v3数据'))
|
||||
async def send_export_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
if qid not in bot.config.SUPERUSERS:
|
||||
return
|
||||
await bot.send(ev, '开始导出数据..可能需要一定时间!')
|
||||
@export_v3_data.handle()
|
||||
async def send_export_msg(matcher: Matcher):
|
||||
await matcher.send('开始导出数据..可能需要一定时间!')
|
||||
await export_v3()
|
||||
await bot.send(ev, '导出数据成功!')
|
||||
await matcher.send('导出数据成功!')
|
||||
|
@ -5,7 +5,7 @@ from ..utils.download_resource.RESOURCE_PATH import MAIN_PATH
|
||||
from ..utils.db_operation.db_operation import get_all_bind, get_user_bind_data
|
||||
|
||||
DATA_PATH = MAIN_PATH / 'v3_data.json'
|
||||
BOT_ID = 'onebot'
|
||||
BOT_ID = 'qqguild'
|
||||
RECOGNIZE_SERVER = {
|
||||
'1': 'cn_gf01',
|
||||
'2': 'cn_gf01',
|
||||
|
@ -3,104 +3,141 @@ import random
|
||||
import asyncio
|
||||
from typing import Tuple
|
||||
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot import on_command
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot.params import Depends, CommandArg
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot.adapters.qqguild import Bot, Message, MessageEvent, MessageSegment
|
||||
|
||||
from ..base import sv, logger
|
||||
from ..config import priority
|
||||
from .get_enka_img import draw_enka_img
|
||||
from ..genshinuid_meta import register_menu
|
||||
from .draw_char_rank import draw_cahrcard_list
|
||||
from ..utils.message.error_reply import UID_HINT
|
||||
from ..utils.message.cast_type import cast_to_int
|
||||
from ..utils.enka_api.get_enka_data import switch_api
|
||||
from ..utils.enka_api.enka_to_card import enka_to_card
|
||||
from ..utils.enka_api.enka_to_data import enka_to_data
|
||||
from ..utils.message.get_image_and_at import ImageAndAt
|
||||
from ..utils.download_resource.RESOURCE_PATH import TEMP_PATH
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
from ..utils.db_operation.db_operation import select_db, get_all_uid
|
||||
|
||||
refresh = on_command('强制刷新')
|
||||
original_pic = on_command('原图')
|
||||
change_api = on_command('切换api')
|
||||
get_charcard_list = on_command('毕业度统计')
|
||||
get_char_info = on_command(
|
||||
'查询',
|
||||
priority=priority,
|
||||
)
|
||||
|
||||
AUTO_REFRESH = False
|
||||
refresh_scheduler = scheduler
|
||||
|
||||
|
||||
@sv.on_fullmatch('切换api')
|
||||
async def send_change_api_info(bot: HoshinoBot, ev: CQEvent):
|
||||
print(ev)
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
|
||||
if qid not in bot.config.SUPERUSERS:
|
||||
@change_api.handle()
|
||||
@handle_exception('切换api')
|
||||
async def send_change_api_info(
|
||||
bot: Bot,
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
args: Message = CommandArg(),
|
||||
):
|
||||
if args or not await SUPERUSER(bot, event):
|
||||
return
|
||||
|
||||
im = await switch_api()
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
||||
|
||||
@sv.on_rex(r'^(\[CQ:reply,id=[0-9]+\])?( )?(\[CQ:at,qq=[0-9]+\])?( )?原图')
|
||||
async def send_original_pic(bot: HoshinoBot, ev: CQEvent):
|
||||
for msg in ev.message:
|
||||
if msg['type'] == 'reply':
|
||||
msg_id = msg['data']['id']
|
||||
@original_pic.handle()
|
||||
@handle_exception('原图')
|
||||
async def send_original_pic(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
ev = event.__dict__
|
||||
if 'message_reference' in ev:
|
||||
msg_id = ev['message_reference'].__dict__['message_id']
|
||||
path = TEMP_PATH / f'{msg_id}.jpg'
|
||||
if path.exists():
|
||||
logger.info('[原图]访问图片: {}'.format(path))
|
||||
with open(path, 'rb') as f:
|
||||
im = await convert_img(f.read())
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(MessageSegment.file_image(f.read()))
|
||||
|
||||
|
||||
@sv.on_rex(
|
||||
r'^(\[CQ:at,qq=[0-9]+\])?( )?'
|
||||
r'(uid|查询|mys)([0-9]+)?'
|
||||
r'([\u4e00-\u9fa5]+)'
|
||||
r'(\[CQ:at,qq=[0-9]+\])?( )?',
|
||||
@get_char_info.handle()
|
||||
@handle_exception('查询角色面板')
|
||||
@register_menu(
|
||||
'查询角色面板',
|
||||
'查询(@某人)角色名',
|
||||
'查询你的或者指定人的已缓存展柜角色的面板',
|
||||
detail_des=(
|
||||
'指令:'
|
||||
'<ft color=(238,120,0)>[查询</ft>'
|
||||
'<ft color=(125,125,125)>(@某人)</ft>'
|
||||
'<ft color=(238,120,0)>/uidxxx/mysxxx]</ft>'
|
||||
'<ft color=(238,120,0)>角色名</ft>\n'
|
||||
' \n'
|
||||
'可以用来查看你的或者指定人的已缓存展柜角色的面板\n'
|
||||
'支持部分角色别名\n'
|
||||
' \n'
|
||||
'示例:\n'
|
||||
'<ft color=(238,120,0)>查询宵宫</ft>;\n'
|
||||
'<ft color=(238,120,0)>查询</ft><ft color=(0,148,200)>@无疑Wuyi</ft>'
|
||||
' <ft color=(238,120,0)>公子</ft>'
|
||||
),
|
||||
)
|
||||
async def send_char_info(bot: HoshinoBot, ev: CQEvent):
|
||||
args = ev['match'].groups()
|
||||
if args[4] is None:
|
||||
async def send_char_info(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
args: Message = CommandArg(),
|
||||
custom: ImageAndAt = Depends(),
|
||||
):
|
||||
raw_mes = args.extract_plain_text().strip()
|
||||
name = ''.join(re.findall('[\u4e00-\u9fa5]', raw_mes))
|
||||
if not name:
|
||||
return
|
||||
# 获取角色名
|
||||
msg = ''.join(re.findall('[\u4e00-\u9fa5]', args[4]))
|
||||
logger.info('开始执行[查询角色面板]')
|
||||
logger.info('[查询角色面板]参数: {}'.format(args))
|
||||
# 获取角色名
|
||||
at = re.search(r'\[CQ:at,qq=(\d*)]', str(ev.message))
|
||||
image = re.search(r'\[CQ:image,file=(.*),url=(.*)]', str(ev.message))
|
||||
at = custom.get_first_at()
|
||||
img = custom.get_first_image()
|
||||
|
||||
qid = at or cast_to_int(event.author)
|
||||
qid = str(qid)
|
||||
|
||||
img = None
|
||||
if image:
|
||||
img = image.group(2)
|
||||
if at:
|
||||
qid = int(at.group(1))
|
||||
else:
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
logger.info('[查询角色面板]QQ: {}'.format(qid))
|
||||
|
||||
# 获取uid
|
||||
if args[3] is None:
|
||||
uid = re.findall(r'\d+', raw_mes)
|
||||
if uid:
|
||||
uid = uid[0]
|
||||
else:
|
||||
uid = await select_db(qid, mode='uid')
|
||||
uid = str(uid)
|
||||
else:
|
||||
uid = args[3]
|
||||
logger.info('[查询角色面板]uid: {}'.format(uid))
|
||||
|
||||
if '未找到绑定的UID' in uid:
|
||||
await bot.send(ev, UID_HINT)
|
||||
await matcher.finish(UID_HINT)
|
||||
|
||||
# 获取角色名
|
||||
msg = ''.join(re.findall('[\u4e00-\u9fa5]', raw_mes))
|
||||
im = await draw_enka_img(msg, uid, img)
|
||||
|
||||
if isinstance(im, str):
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
elif isinstance(im, Tuple):
|
||||
img = await convert_img(im[0])
|
||||
req = await bot.send(ev, img)
|
||||
msg_id = req['message_id']
|
||||
if isinstance(im[0], str):
|
||||
await matcher.finish(im[0])
|
||||
req = await matcher.send(MessageSegment.file_image(im[0]))
|
||||
msg_id = req.id
|
||||
if im[1]:
|
||||
with open(TEMP_PATH / f'{msg_id}.jpg', 'wb') as f:
|
||||
f.write(im[1])
|
||||
else:
|
||||
await bot.send(ev, '发生了未知错误,请联系管理员检查后台输出!')
|
||||
await matcher.finish('发生了未知错误,请联系管理员检查后台输出!')
|
||||
|
||||
|
||||
async def refresh_char_data():
|
||||
@ -125,92 +162,116 @@ async def refresh_char_data():
|
||||
return f'执行成功!共刷新{str(t)}个角色!'
|
||||
|
||||
|
||||
@sv.scheduled_job('cron', hour='4')
|
||||
@refresh_scheduler.scheduled_job('cron', hour='4')
|
||||
async def daily_refresh_charData():
|
||||
global AUTO_REFRESH
|
||||
if AUTO_REFRESH:
|
||||
await refresh_char_data()
|
||||
|
||||
|
||||
@sv.on_prefix('强制刷新')
|
||||
async def send_card_info(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
message = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
return
|
||||
|
||||
at = re.search(r'\[CQ:at,qq=(\d*)]', str(ev.message))
|
||||
|
||||
if at:
|
||||
qid = int(at.group(1))
|
||||
message = message.replace(str(at), '')
|
||||
else:
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
|
||||
@refresh.handle()
|
||||
@handle_exception('强制刷新')
|
||||
@register_menu(
|
||||
'刷新展柜缓存',
|
||||
'强制刷新',
|
||||
'强制刷新你的或者指定人缓存的角色展柜数据',
|
||||
detail_des=(
|
||||
'指令:'
|
||||
'<ft color=(238,120,0)>强制刷新</ft>'
|
||||
'<ft color=(125,125,125)>(uid/全部数据)</ft>\n'
|
||||
' \n'
|
||||
'用于强制刷新你的或者指定人缓存的角色展柜数据\n'
|
||||
'当刷新全部数据时需要机器人管理员权限\n'
|
||||
' \n'
|
||||
'示例:\n'
|
||||
'<ft color=(238,120,0)>强制刷新</ft>;\n'
|
||||
'<ft color=(238,120,0)>强制刷新123456789</ft>;\n'
|
||||
'<ft color=(238,120,0)>强制刷新全部数据</ft>'
|
||||
),
|
||||
)
|
||||
async def send_card_info(
|
||||
bot: Bot,
|
||||
matcher: Matcher,
|
||||
event: MessageEvent,
|
||||
custom: ImageAndAt = Depends(),
|
||||
args: Message = CommandArg(),
|
||||
):
|
||||
message = args.extract_plain_text().strip().replace(' ', '')
|
||||
uid = re.findall(r'\d+', message) # str
|
||||
m = ''.join(re.findall('[\u4e00-\u9fa5]', message))
|
||||
qid = str(cast_to_int(event.author))
|
||||
at = custom.get_first_at()
|
||||
if at:
|
||||
qid = at
|
||||
|
||||
if len(uid) >= 1:
|
||||
uid = uid[0]
|
||||
else:
|
||||
if m == '全部数据':
|
||||
if qid in bot.config.SUPERUSERS:
|
||||
await bot.send(ev, '开始刷新全部数据,这可能需要相当长的一段时间!!')
|
||||
if await SUPERUSER(bot, event):
|
||||
await matcher.send('开始刷新全部数据,这可能需要相当长的一段时间!!')
|
||||
im = await refresh_char_data()
|
||||
await bot.send(ev, str(im))
|
||||
return
|
||||
await matcher.finish(str(im))
|
||||
else:
|
||||
return
|
||||
else:
|
||||
uid = await select_db(qid, mode='uid')
|
||||
uid = str(uid)
|
||||
if '未找到绑定的UID' in uid:
|
||||
await bot.send(ev, UID_HINT)
|
||||
return
|
||||
if not uid:
|
||||
await matcher.finish(UID_HINT)
|
||||
im = await enka_to_card(uid)
|
||||
|
||||
logger.info(f'UID{uid}获取角色数据成功!')
|
||||
if isinstance(im, str):
|
||||
await bot.send(ev, im)
|
||||
elif isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
else:
|
||||
await bot.send(ev, '发生了未知错误,请联系管理员检查后台输出!')
|
||||
await matcher.finish(im)
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
|
||||
|
||||
@sv.on_prefix('毕业度统计')
|
||||
async def send_charcard_list(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
message = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
return
|
||||
|
||||
at = re.search(r'\[CQ:at,qq=(\d*)]', str(ev.message))
|
||||
|
||||
@get_charcard_list.handle()
|
||||
@handle_exception('毕业度统计')
|
||||
@register_menu(
|
||||
'毕业度统计',
|
||||
'毕业度统计',
|
||||
'查看你或指定人已缓存的展柜角色毕业度',
|
||||
detail_des=(
|
||||
'指令:'
|
||||
'<ft color=(238,120,0)>毕业度统计</ft>'
|
||||
'<ft color=(125,125,125)>(@某人)</ft>\n'
|
||||
' \n'
|
||||
'可以查看你或指定人已缓存的所有展柜角色毕业度\n'
|
||||
' \n'
|
||||
'示例:\n'
|
||||
'<ft color=(238,120,0)>毕业度统计</ft>;\n'
|
||||
'<ft color=(238,120,0)>毕业度统计</ft><ft color=(0,148,200)>@无疑Wuyi</ft>'
|
||||
),
|
||||
)
|
||||
async def send_charcard_list(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
args: Message = CommandArg(),
|
||||
custom: ImageAndAt = Depends(),
|
||||
):
|
||||
raw_mes = args.extract_plain_text().strip()
|
||||
qid = str(cast_to_int(event.author))
|
||||
at = custom.get_first_at()
|
||||
if at:
|
||||
qid = int(at.group(1))
|
||||
message = message.replace(str(at), '')
|
||||
else:
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
qid = at
|
||||
|
||||
# 获取uid
|
||||
uid = re.findall(r'\d+', message)
|
||||
uid = re.findall(r'\d+', raw_mes)
|
||||
if uid:
|
||||
uid = uid[0]
|
||||
else:
|
||||
uid = await select_db(qid, mode='uid')
|
||||
uid = str(uid)
|
||||
|
||||
im = await draw_cahrcard_list(str(uid), qid)
|
||||
|
||||
logger.info(f'UID{uid}获取角色数据成功!')
|
||||
if isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
if event.author and event.author.avatar:
|
||||
avatar = event.author.avatar
|
||||
else:
|
||||
await bot.send(ev, str(im))
|
||||
avatar = '3399214199'
|
||||
|
||||
im = await draw_cahrcard_list(str(uid), avatar)
|
||||
|
||||
if isinstance(im, bytes):
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
await matcher.finish(str(im))
|
||||
|
@ -501,7 +501,7 @@ class Character:
|
||||
|
||||
# 重新计算加成值
|
||||
# base_effect_list = [
|
||||
# [limit_list, effect_attr, effect_value,effect_base]
|
||||
# [limit_list, effect_attr, effect_value, effect_base]
|
||||
# ]
|
||||
for effect in base_effect_list:
|
||||
prop = await self.get_buff_value(prop, *effect)
|
||||
@ -614,8 +614,12 @@ class Character:
|
||||
'type': '攻击力',
|
||||
'plus': 1,
|
||||
'value': [
|
||||
f'''{int(i[:-1]) +
|
||||
int(self.power_list["A霜华矢·霜华绽发伤害"]["value"][index][:-1])
|
||||
f'''{
|
||||
int(i[:-1]) + int(
|
||||
self.power_list[
|
||||
"A霜华矢·霜华绽发伤害"
|
||||
]["value"][index][:-1]
|
||||
)
|
||||
}%'''
|
||||
for index, i in enumerate(
|
||||
self.power_list['A霜华矢命中伤害']['value']
|
||||
|
@ -216,8 +216,8 @@ class Fight:
|
||||
if '前台' in char.power_list[char.power_name]['name']:
|
||||
if char.char_name == '纳西妲':
|
||||
em = char.fight_prop[f'{char.attack_type}_elementalMastery']
|
||||
effect = f'''elementalMastery+
|
||||
{0.25 * em if 0.25 * em <= 250 else 250}
|
||||
effect = f'''
|
||||
elementalMastery+{0.25 * em if 0.25 * em <= 250 else 250}
|
||||
'''.strip()
|
||||
effect_list.append(effect)
|
||||
|
||||
|
@ -1,42 +1,92 @@
|
||||
from pathlib import Path
|
||||
from typing import Any, Tuple
|
||||
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot import on_regex, on_command
|
||||
from nonebot.params import CommandArg, RegexGroup
|
||||
from nonebot.adapters.qqguild import Message, MessageSegment
|
||||
|
||||
from ..base import sv, logger
|
||||
from ..version import Genshin_version
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..genshinuid_meta import register_menu
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
get_primogems_data = on_command('版本规划', aliases={'原石预估'})
|
||||
get_img_data = on_regex(r'^(查询)?(伤害乘区|血量表|抗性表|血量排行)$')
|
||||
|
||||
PRIMOGEMS_DATA_PATH = Path(__file__).parent / 'primogems_data'
|
||||
IMG_PATH = Path(__file__).parent / 'img_data'
|
||||
|
||||
|
||||
@sv.on_rex(r'^(版本规划|原石预估)(\S+)?$')
|
||||
async def send_primogems_data(bot: HoshinoBot, ev: CQEvent):
|
||||
args = ev['match'].groups()
|
||||
@get_primogems_data.handle()
|
||||
@handle_exception('版本规划')
|
||||
@register_menu(
|
||||
'版本原石规划',
|
||||
'版本规划(版本号)',
|
||||
'发送一张指定版本的原石规划图',
|
||||
detail_des=(
|
||||
'指令:'
|
||||
'<ft color=(238,120,0)>版本规划</ft>'
|
||||
'<ft color=(125,125,125)>(版本号)</ft>\n'
|
||||
' \n'
|
||||
'发送一张指定版本的原石规划图\n'
|
||||
' \n'
|
||||
'示例:\n'
|
||||
'<ft color=(238,120,0)>版本规划</ft>;\n'
|
||||
'<ft color=(238,120,0)>版本规划3.0</ft>'
|
||||
),
|
||||
)
|
||||
async def send_primogems_data(matcher: Matcher, args: Message = CommandArg()):
|
||||
logger.info('开始执行[图片][版本规划]')
|
||||
logger.info('[图片][版本规划]参数: {}'.format(args))
|
||||
if args[1]:
|
||||
path = PRIMOGEMS_DATA_PATH / f'{str(args[1])}.png'
|
||||
if args:
|
||||
path = PRIMOGEMS_DATA_PATH / f'{str(args)}.png'
|
||||
if path.exists():
|
||||
img = f'{str(args[1])}.png'
|
||||
img = f'{str(args)}.png'
|
||||
else:
|
||||
return
|
||||
await matcher.finish()
|
||||
else:
|
||||
img = f'{Genshin_version[:3]}.png'
|
||||
primogems_img = PRIMOGEMS_DATA_PATH / img
|
||||
logger.info('[图片][版本规划]访问图片: {}'.format(img))
|
||||
primogems_img = await convert_img(primogems_img)
|
||||
await bot.send(ev, primogems_img)
|
||||
await matcher.finish(MessageSegment.file_image(primogems_img))
|
||||
|
||||
|
||||
@sv.on_rex(r'^(查询)?(伤害乘区|血量表|抗性表|血量排行)$')
|
||||
async def send_img_data(bot: HoshinoBot, ev: CQEvent):
|
||||
args = ev['match'].groups()
|
||||
@get_img_data.handle()
|
||||
@handle_exception('杂图')
|
||||
@register_menu(
|
||||
'伤害乘区图',
|
||||
'伤害乘区',
|
||||
'发送一张理论伤害计算公式图',
|
||||
detail_des=(
|
||||
'指令:' '<ft color=(238,120,0)>伤害乘区</ft>\n' ' \n' '发送一张理论伤害计算公式图'
|
||||
),
|
||||
)
|
||||
@register_menu(
|
||||
'怪物血量表',
|
||||
'血量表',
|
||||
'发送一张原神怪物血量表图',
|
||||
detail_des=('指令:' '<ft color=(238,120,0)>血量表</ft>\n' ' \n' '发送一张原神怪物血量表图'),
|
||||
)
|
||||
@register_menu(
|
||||
'怪物抗性表',
|
||||
'抗性表',
|
||||
'发送一张原神怪物抗性表图',
|
||||
detail_des=('指令:' '<ft color=(238,120,0)>抗性表</ft>\n' ' \n' '发送一张原神怪物抗性表图'),
|
||||
)
|
||||
@register_menu(
|
||||
'怪物血量排行',
|
||||
'血量排行',
|
||||
'发送一张原神怪物血量排行图',
|
||||
detail_des=(
|
||||
'指令:' '<ft color=(238,120,0)>血量排行</ft>\n' ' \n' '发送一张原神怪物血量排行图'
|
||||
),
|
||||
)
|
||||
async def send_img_data(
|
||||
matcher: Matcher, args: Tuple[Any, ...] = RegexGroup()
|
||||
):
|
||||
logger.info('开始执行[图片][杂图]')
|
||||
logger.info('[图片][杂图]参数: {}'.format(args))
|
||||
img = IMG_PATH / f'{args[1]}.jpg'
|
||||
if img.exists():
|
||||
img = await convert_img(img)
|
||||
await bot.send(ev, img)
|
||||
else:
|
||||
return
|
||||
await matcher.finish(MessageSegment.file_image(img))
|
||||
|
@ -1,24 +1,42 @@
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot import on_regex
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot.adapters.qqguild import MessageSegment
|
||||
|
||||
from ..base import sv
|
||||
from ..genshinuid_meta import register_menu
|
||||
from .draw_event_img import get_event_img, get_all_event_img
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
get_event = on_regex(r'^活动列表$')
|
||||
get_gacha = on_regex(r'^卡池列表$')
|
||||
|
||||
|
||||
@sv.scheduled_job('cron', hour='2')
|
||||
@scheduler.scheduled_job('cron', hour='2')
|
||||
async def draw_event():
|
||||
await get_all_event_img()
|
||||
|
||||
|
||||
@sv.on_fullmatch('活动列表')
|
||||
async def send_events(bot: HoshinoBot, ev: CQEvent):
|
||||
@get_event.handle()
|
||||
@handle_exception('活动')
|
||||
@register_menu(
|
||||
'活动列表',
|
||||
'活动列表',
|
||||
'查询当前版本活动日程表',
|
||||
detail_des=('指令:' '<ft color=(238,120,0)>活动列表</ft>\n' ' \n' '查询当前版本活动日程表'),
|
||||
)
|
||||
async def send_events(matcher: Matcher):
|
||||
img = await get_event_img('EVENT')
|
||||
im = await convert_img(img)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(MessageSegment.file_image(img))
|
||||
|
||||
|
||||
@sv.on_fullmatch('卡池列表')
|
||||
async def send_gachas(bot: HoshinoBot, ev: CQEvent):
|
||||
@get_gacha.handle()
|
||||
@handle_exception('卡池')
|
||||
@register_menu(
|
||||
'卡池列表',
|
||||
'卡池列表',
|
||||
'查询当前版本卡池列表',
|
||||
detail_des=('指令:' '<ft color=(238,120,0)>卡池列表</ft>\n' ' \n' '查询当前版本卡池列表'),
|
||||
)
|
||||
async def send_gachas(matcher: Matcher):
|
||||
img = await get_event_img('GACHA')
|
||||
im = await convert_img(img)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(MessageSegment.file_image(img))
|
||||
|
@ -1,93 +1,132 @@
|
||||
from nonebot import get_bot
|
||||
from hoshino.typing import CQEvent, HoshinoBot, NoticeSession
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot import get_bot, on_notice, on_command
|
||||
from nonebot.adapters.qqguild import MessageEvent, MessageSegment
|
||||
|
||||
from ..base import sv, logger
|
||||
from .get_gachalogs import save_gachalogs
|
||||
from ..genshinuid_meta import register_menu
|
||||
from ..utils.nonebot2.rule import FullCommand
|
||||
from .draw_gachalogs import draw_gachalogs_img
|
||||
from ..utils.message.error_reply import UID_HINT
|
||||
from ..utils.message.cast_type import cast_to_int
|
||||
from ..utils.db_operation.db_operation import select_db
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
from .export_and_import import export_gachalogs, import_gachalogs
|
||||
|
||||
|
||||
@sv.on_notice()
|
||||
async def import_gacha_log_info(session: NoticeSession):
|
||||
ev = session.event
|
||||
if ev['notice_type'] != 'offline_file':
|
||||
return
|
||||
url = ev['file']['url']
|
||||
name: str = ev['file']['name']
|
||||
if not name.endswith('.json'):
|
||||
return
|
||||
qid = ev['user_id']
|
||||
uid = await select_db(qid, mode='uid')
|
||||
if not isinstance(uid, str) or '未找到绑定的UID' in uid:
|
||||
await session.send(UID_HINT)
|
||||
return
|
||||
logger.info('开始执行[导入抽卡记录]')
|
||||
im = await import_gachalogs(url, uid)
|
||||
await session.send(im, at_sender=True)
|
||||
get_gacha_log = on_command('刷新抽卡记录', aliases={'强制刷新抽卡记录'}, rule=FullCommand())
|
||||
get_gacha_log_card = on_command('抽卡记录', rule=FullCommand())
|
||||
import_gacha_log = on_notice()
|
||||
export_gacha_log = on_command('导出抽卡记录', rule=FullCommand())
|
||||
|
||||
|
||||
@sv.on_fullmatch('导出抽卡记录')
|
||||
async def export_gacha_log_info(bot: HoshinoBot, ev: CQEvent):
|
||||
@export_gacha_log.handle()
|
||||
@handle_exception('导出抽卡记录')
|
||||
async def export_gacha_log_info(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
|
||||
logger.info('开始执行[导出抽卡记录]')
|
||||
qid = int(ev.sender['user_id'])
|
||||
gid = int(ev.group_id)
|
||||
qid = str(str(cast_to_int(event.author)))
|
||||
gid = event.channel_id
|
||||
uid = await select_db(qid, mode='uid')
|
||||
bot = get_bot()
|
||||
if not isinstance(uid, str) or '未找到绑定的UID' in uid:
|
||||
await bot.send(ev, UID_HINT)
|
||||
return
|
||||
await matcher.finish(UID_HINT)
|
||||
raw_data = await export_gachalogs(uid)
|
||||
if raw_data['retcode'] == 'ok':
|
||||
await bot.call_action(
|
||||
action='upload_group_file',
|
||||
await bot.call_api(
|
||||
'upload_group_file',
|
||||
group_id=gid,
|
||||
name=raw_data['name'],
|
||||
file=raw_data['url'],
|
||||
)
|
||||
logger.info(f'[导出抽卡记录] UID{uid}成功!')
|
||||
await bot.send(ev, '上传成功!')
|
||||
await matcher.finish('上传成功!')
|
||||
else:
|
||||
logger.warning(f'[导出抽卡记录] UID{uid}失败!')
|
||||
await bot.send(ev, '导出抽卡记录失败!')
|
||||
await matcher.finish('导出抽卡记录失败!')
|
||||
|
||||
|
||||
@sv.on_fullmatch('抽卡记录')
|
||||
async def send_gacha_log_card_info(bot: HoshinoBot, ev: CQEvent):
|
||||
@import_gacha_log.handle()
|
||||
@handle_exception('导入抽卡记录')
|
||||
async def import_gacha_log_info(event: MessageEvent, matcher: Matcher):
|
||||
args = event.dict()
|
||||
if args['notice_type'] != 'offline_file':
|
||||
await matcher.finish()
|
||||
url = args['file']['url']
|
||||
name: str = args['file']['name']
|
||||
if not name.endswith('.json'):
|
||||
return
|
||||
qid = args['user_id']
|
||||
uid = await select_db(qid, mode='uid')
|
||||
if not isinstance(uid, str) or '未找到绑定的UID' in uid:
|
||||
await matcher.finish(UID_HINT)
|
||||
logger.info('开始执行[导入抽卡记录]')
|
||||
im = await import_gachalogs(url, uid)
|
||||
await matcher.finish(im)
|
||||
|
||||
|
||||
@get_gacha_log_card.handle()
|
||||
@handle_exception('抽卡记录')
|
||||
@register_menu(
|
||||
'查询抽卡记录',
|
||||
'抽卡记录',
|
||||
'查询你的原神抽卡记录',
|
||||
detail_des=(
|
||||
'指令:'
|
||||
'<ft color=(238,120,0)>抽卡记录</ft>\n'
|
||||
' \n'
|
||||
'查询你的原神抽卡记录\n'
|
||||
'需要<ft color=(238,120,0)>绑定Stoken</ft>'
|
||||
),
|
||||
)
|
||||
async def send_gacha_log_card_info(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
logger.info('开始执行[抽卡记录]')
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
uid = await select_db(qid, mode='uid')
|
||||
|
||||
uid = await select_db(str(cast_to_int(event.author)), mode='uid')
|
||||
if event.author and event.author.avatar:
|
||||
avatar = event.author.avatar
|
||||
else:
|
||||
avatar = '3399214199'
|
||||
if isinstance(uid, str):
|
||||
im = await draw_gachalogs_img(uid, qid)
|
||||
im = await draw_gachalogs_img(uid, avatar) # type: ignore
|
||||
if isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
else:
|
||||
await bot.send(ev, UID_HINT)
|
||||
await matcher.finish(UID_HINT)
|
||||
|
||||
|
||||
@sv.on_fullmatch(('刷新抽卡记录', '强制刷新抽卡记录'))
|
||||
async def send_daily_info(bot: HoshinoBot, ev: CQEvent):
|
||||
@get_gacha_log.handle()
|
||||
@handle_exception('刷新抽卡记录')
|
||||
@register_menu(
|
||||
'刷新抽卡记录',
|
||||
'刷新抽卡记录',
|
||||
'刷新你的原神抽卡记录本地缓存',
|
||||
detail_des=(
|
||||
'指令:'
|
||||
'<ft color=(238,120,0)>刷新抽卡记录</ft>\n'
|
||||
' \n'
|
||||
'刷新你的原神抽卡记录本地缓存\n'
|
||||
'需要<ft color=(238,120,0)>绑定Stoken</ft>'
|
||||
),
|
||||
)
|
||||
async def send_daily_info(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
logger.info('开始执行[刷新抽卡记录]')
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
uid = await select_db(qid, mode='uid')
|
||||
uid = await select_db(str(cast_to_int(event.author)), mode='uid')
|
||||
if isinstance(uid, str):
|
||||
is_force = False
|
||||
if ev.raw_message and str(ev.raw_message).startswith('强制'):
|
||||
logger.info('[WARNING]本次为强制刷新')
|
||||
if event.content and event.content.startswith('强制'):
|
||||
is_force = True
|
||||
im = await save_gachalogs(uid, None, is_force)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
else:
|
||||
await bot.send(ev, UID_HINT)
|
||||
await matcher.finish(UID_HINT)
|
||||
|
@ -1,28 +1,41 @@
|
||||
import re
|
||||
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot import on_command
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import Depends, CommandArg
|
||||
from nonebot.adapters.qqguild import Message, MessageEvent, MessageSegment
|
||||
|
||||
from ..base import sv, logger
|
||||
from ..config import priority
|
||||
from .draw_gcginfo import draw_gcg_info
|
||||
from ..utils.message.error_reply import UID_HINT
|
||||
from ..utils.message.cast_type import cast_to_int
|
||||
from ..utils.db_operation.db_operation import select_db
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.message.get_image_and_at import ImageAndAt
|
||||
from ..utils.message.error_reply import CK_HINT, UID_HINT
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
get_gcg_info = on_command('七圣召唤', aliases={'七圣', '召唤'}, priority=priority)
|
||||
|
||||
|
||||
@sv.on_prefix(('七圣召唤', '七圣', '召唤'))
|
||||
async def send_gcg_pic(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
raw_mes = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
# 群聊内 每月统计 功能
|
||||
@get_gcg_info.handle()
|
||||
@handle_exception('七圣召唤', '获取/发送七圣召唤失败', '@未找到绑定信息\n' + CK_HINT)
|
||||
async def send_gcg_pic(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
args: Message = CommandArg(),
|
||||
custom: ImageAndAt = Depends(),
|
||||
):
|
||||
raw_mes = args.extract_plain_text().strip().replace(' ', '')
|
||||
name = ''.join(re.findall('[\u4e00-\u9fa5]', raw_mes))
|
||||
if name:
|
||||
return
|
||||
|
||||
at = re.search(r'\[CQ:at,qq=(\d*)]', str(ev.message))
|
||||
at = custom.get_first_at()
|
||||
logger.info('开始执行[七圣召唤]')
|
||||
|
||||
if at:
|
||||
qid = int(at.group(1))
|
||||
else:
|
||||
qid = int(ev.sender['user_id'])
|
||||
qid = at or cast_to_int(event.author)
|
||||
qid = str(qid)
|
||||
|
||||
logger.info('[七圣召唤]QQ: {}'.format(qid))
|
||||
|
||||
# 获取uid
|
||||
@ -32,18 +45,16 @@ async def send_gcg_pic(bot: HoshinoBot, ev: CQEvent):
|
||||
else:
|
||||
uid = await select_db(qid, mode='uid')
|
||||
uid = str(uid)
|
||||
|
||||
logger.info('[七圣召唤]uid: {}'.format(uid))
|
||||
|
||||
if '未找到绑定的UID' in uid:
|
||||
await bot.send(ev, UID_HINT)
|
||||
await matcher.finish(UID_HINT)
|
||||
|
||||
im = await draw_gcg_info(uid)
|
||||
|
||||
if isinstance(im, str):
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
elif isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
await bot.send(ev, '发生了未知错误,请联系管理员检查后台输出!')
|
||||
await matcher.finish('发生了未知错误,请联系管理员检查后台输出!')
|
||||
|
@ -1,117 +1,128 @@
|
||||
import asyncio
|
||||
import threading
|
||||
from typing import List
|
||||
from pathlib import Path
|
||||
from typing import Any, List, Tuple
|
||||
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot import on_regex, on_command
|
||||
from nonebot.params import CommandArg, RegexGroup
|
||||
from nonebot.adapters.qqguild import Message, MessageSegment
|
||||
|
||||
from ..base import sv, logger
|
||||
from .get_card import get_gs_card
|
||||
from .get_guide import get_gs_guide
|
||||
from ..version import Genshin_version
|
||||
from ..genshinuid_meta import register_menu
|
||||
from .get_abyss_data import get_review, generate_data
|
||||
from ..utils.alias.alias_to_char_name import alias_to_char_name
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
get_guide_pic = on_regex('([\u4e00-\u9fa5]+)(推荐|攻略)')
|
||||
get_bluekun_pic = on_command('参考面板')
|
||||
get_card = on_command('原牌')
|
||||
get_abyss = on_command('版本深渊')
|
||||
|
||||
IMG_PATH = Path(__file__).parent / 'img'
|
||||
|
||||
|
||||
@sv.on_rex('([\u4e00-\u9fa5]+)(推荐|攻略)')
|
||||
async def send_guide_pic(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
name = name = str(ev['match'].group(1))
|
||||
else:
|
||||
@get_guide_pic.handle()
|
||||
@handle_exception('建议')
|
||||
@register_menu(
|
||||
'角色攻略',
|
||||
'xx攻略',
|
||||
'发送一张对应角色的西风驿站攻略图',
|
||||
detail_des=(
|
||||
'指令:'
|
||||
'<ft color=(238,120,0)>角色名[推荐/攻略]</ft>\n'
|
||||
' \n'
|
||||
'发送一张对应角色的米游社西风驿站攻略图\n'
|
||||
'支持部分角色别名\n'
|
||||
' \n'
|
||||
'示例:\n'
|
||||
'<ft color=(238,120,0)>钟离推荐</ft>;\n'
|
||||
'<ft color=(238,120,0)>公子攻略</ft>'
|
||||
),
|
||||
)
|
||||
async def send_guide_pic(
|
||||
matcher: Matcher, args: Tuple[Any, ...] = RegexGroup()
|
||||
):
|
||||
if not args:
|
||||
return
|
||||
|
||||
if name == '':
|
||||
return
|
||||
|
||||
name = str(args[0])
|
||||
im = await get_gs_guide(name)
|
||||
|
||||
if im:
|
||||
logger.info('获得{}攻略成功!'.format(name))
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
print('gg')
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
logger.warning('未找到{}攻略图片'.format(name))
|
||||
|
||||
|
||||
@sv.on_prefix('参考面板')
|
||||
async def send_bluekun_pic(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
message = ev.message.extract_plain_text().replace(' ', '')
|
||||
@get_bluekun_pic.handle()
|
||||
@handle_exception('参考面板')
|
||||
@register_menu(
|
||||
'参考面板',
|
||||
'参考面板[角色名/元素名]',
|
||||
'发送一张对应角色/元素的参考面板图',
|
||||
detail_des=(
|
||||
'指令:'
|
||||
'<ft color=(238,120,0)>参考面板[角色名/元素名]</ft>\n'
|
||||
' \n'
|
||||
'发送一张对应角色/元素的参考面板图\n'
|
||||
'支持部分角色别名\n'
|
||||
' \n'
|
||||
'示例:\n'
|
||||
'<ft color=(238,120,0)>参考面板火</ft>;\n'
|
||||
'<ft color=(238,120,0)>参考面板公子</ft>'
|
||||
),
|
||||
)
|
||||
async def send_bluekun_pic(matcher: Matcher, args: Message = CommandArg()):
|
||||
if str(args[0]) in ['冰', '水', '火', '草', '雷', '风', '岩']:
|
||||
name = str(args[0])
|
||||
else:
|
||||
return
|
||||
|
||||
if message == '':
|
||||
return
|
||||
|
||||
if str(message) in ['冰', '水', '火', '草', '雷', '风', '岩']:
|
||||
name = str(message)
|
||||
else:
|
||||
name = await alias_to_char_name(str(message))
|
||||
name = await alias_to_char_name(str(args[0]))
|
||||
img = IMG_PATH / '{}.jpg'.format(name)
|
||||
if img.exists():
|
||||
img = await convert_img(img)
|
||||
logger.info('获得{}参考面板图片成功!'.format(name))
|
||||
await bot.send(ev, img)
|
||||
await matcher.finish(MessageSegment.file_image(img))
|
||||
else:
|
||||
logger.warning('未找到{}参考面板图片'.format(name))
|
||||
|
||||
|
||||
@sv.on_prefix('原牌')
|
||||
async def send_gscard_pic(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
name = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
@get_card.handle()
|
||||
@handle_exception('原牌')
|
||||
async def send_gscard_pic(matcher: Matcher, args: Message = CommandArg()):
|
||||
if not args:
|
||||
return
|
||||
|
||||
if name == '':
|
||||
return
|
||||
|
||||
name = str(args[0])
|
||||
im = await get_gs_card(name)
|
||||
|
||||
if im:
|
||||
logger.info('获得{}原牌成功!'.format(name))
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
logger.warning('未找到{}原牌图片'.format(name))
|
||||
|
||||
|
||||
@sv.on_prefix('版本深渊')
|
||||
async def send_abyss_review(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
version = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
return
|
||||
|
||||
if version == '':
|
||||
@get_abyss.handle()
|
||||
@handle_exception('版本深渊')
|
||||
async def send_abyss_review(
|
||||
matcher: Matcher,
|
||||
args: Message = CommandArg(),
|
||||
):
|
||||
if not args:
|
||||
version = Genshin_version[:-2]
|
||||
|
||||
im = await get_review(version)
|
||||
|
||||
if isinstance(im, List):
|
||||
mes = []
|
||||
for msg in im:
|
||||
mes.append(
|
||||
{
|
||||
'type': 'node',
|
||||
'data': {
|
||||
'name': '小仙',
|
||||
'uin': '3399214199',
|
||||
'content': msg,
|
||||
},
|
||||
}
|
||||
)
|
||||
await bot.send_group_forward_msg(group_id=ev.group_id, messages=mes)
|
||||
elif isinstance(im, str):
|
||||
await bot.send(ev, im)
|
||||
elif isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
else:
|
||||
await bot.send(ev, '发生了未知错误,请联系管理员检查后台输出!')
|
||||
version = str(args[0])
|
||||
im = await get_review(version)
|
||||
if isinstance(im, List):
|
||||
im = '\n'.join(im)
|
||||
await matcher.finish(im)
|
||||
elif isinstance(im, str):
|
||||
await matcher.finish(im)
|
||||
elif isinstance(im, bytes):
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
await matcher.finish('发生了未知错误,请联系管理员检查后台输出!')
|
||||
|
||||
|
||||
threading.Thread(
|
||||
|
139
GenshinUID/genshinuid_guild/__init__.py
Normal file
139
GenshinUID/genshinuid_guild/__init__.py
Normal file
@ -0,0 +1,139 @@
|
||||
import asyncio
|
||||
from typing import List
|
||||
|
||||
from nonebot import on_command
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot.message import event_preprocessor
|
||||
from nonebot.adapters.qqguild.message import Text
|
||||
from nonebot.adapters.qqguild import Bot, MessageEvent
|
||||
from nonebot.adapters.qqguild.api.model import DMS, Guild, MessageMarkdown
|
||||
|
||||
from ..utils.nonebot2.rule import FullCommand
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
_md = '''## 这是一个自定义MD文本
|
||||
'''
|
||||
|
||||
guild_detail = on_command('频道统计', block=True, rule=FullCommand())
|
||||
get_dirct_msg = on_command(
|
||||
'给我发消息',
|
||||
aliases={'给我发私信', '给我发短信', '给我发信息'},
|
||||
block=True,
|
||||
rule=FullCommand(),
|
||||
)
|
||||
get_markdown_msg = on_command(
|
||||
'给我发md',
|
||||
aliases={'给我发markdown'},
|
||||
block=True,
|
||||
rule=FullCommand(),
|
||||
)
|
||||
|
||||
|
||||
@get_markdown_msg.handle()
|
||||
@handle_exception('发md')
|
||||
async def send_markdown_msg(bot: Bot, event: MessageEvent, matcher: Matcher):
|
||||
if not event.author:
|
||||
return
|
||||
|
||||
await bot.call_api(
|
||||
'post_markdown_message',
|
||||
channel_id=str(event.channel_id),
|
||||
content=_md,
|
||||
)
|
||||
|
||||
await matcher.finish('已发送消息!')
|
||||
|
||||
|
||||
@get_dirct_msg.handle()
|
||||
@handle_exception('发私信')
|
||||
async def send_dirct_msg(
|
||||
bot: Bot,
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
if not event.author:
|
||||
return
|
||||
|
||||
dms: DMS = await bot.call_api(
|
||||
'post_dms',
|
||||
recipient_id=str(event.author.id),
|
||||
source_guild_id=str(event.guild_id),
|
||||
)
|
||||
|
||||
await bot.call_api(
|
||||
'post_dms_messages',
|
||||
guild_id=dms.guild_id,
|
||||
content='一条消息!',
|
||||
)
|
||||
|
||||
await matcher.finish('已发送消息!')
|
||||
|
||||
|
||||
@event_preprocessor
|
||||
async def _(event: MessageEvent):
|
||||
msg = event.get_message().extract_content()
|
||||
msg = msg.replace(' ', '').replace('/', '')
|
||||
r_msg = None
|
||||
new_msg = []
|
||||
for i in event._message: # type: ignore
|
||||
if isinstance(i, Text):
|
||||
i.data['text'] = msg
|
||||
if '毕业都统计' in i.data['text']:
|
||||
i.data['text'].replace('都', '度')
|
||||
|
||||
if r_msg:
|
||||
new_msg.insert(0, r_msg)
|
||||
event._message = new_msg
|
||||
|
||||
if event.content:
|
||||
event.content = event.content.replace(' ', '').replace('/', '')
|
||||
|
||||
|
||||
@guild_detail.handle()
|
||||
@handle_exception('频道统计')
|
||||
async def send_create_map_msg(
|
||||
bot: Bot,
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
if not await SUPERUSER(bot, event):
|
||||
return
|
||||
logger.info('[频道统计]正在执行...')
|
||||
await matcher.send('频道统计正在执行...可能需要较长时间!')
|
||||
|
||||
# 初始化最后的计数
|
||||
ALL_MEMBER = 0
|
||||
HIDE = 0
|
||||
|
||||
# 开始分页
|
||||
after = None
|
||||
# 初始化频道列表
|
||||
guild_list = []
|
||||
# 开始循环
|
||||
while True:
|
||||
# 本次获取的频道列表
|
||||
new_guild_list: List[Guild] = await bot.call_api(
|
||||
'guilds', before=None, after=after, limit=None
|
||||
)
|
||||
# 遍历频道列表
|
||||
for guild in new_guild_list:
|
||||
# 如果该频道人数展示
|
||||
if guild.member_count:
|
||||
# 总人数加上该频道的人数
|
||||
ALL_MEMBER += guild.member_count
|
||||
else:
|
||||
HIDE += 1
|
||||
logger.info(f'频道{guild.id}隐藏频道人数信息,已跳过计算...')
|
||||
# 重新设定拉取值
|
||||
after = guild.id
|
||||
# 把本次拉取的频道列表 合并到总频道列表
|
||||
guild_list.extend(new_guild_list)
|
||||
logger.info(f'当前页gid={after}')
|
||||
# 如果已经拉取不到频道了,就退出循环
|
||||
if new_guild_list == []:
|
||||
break
|
||||
await asyncio.sleep(0.5)
|
||||
im = f'当前Bot加入频道数{len(guild_list)}\n总人数为{ALL_MEMBER}\n隐藏人数频道数量{HIDE}!'
|
||||
await matcher.finish(im)
|
@ -2,18 +2,34 @@ import asyncio
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
from ..base import sv, logger
|
||||
from nonebot import on_command
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.adapters.qqguild import MessageSegment
|
||||
|
||||
from .draw_help_card import draw_help_img
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..genshinuid_meta import register_menu
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
get_help = on_command('gs帮助')
|
||||
|
||||
HELP_IMG = Path(__file__).parent / 'help.png'
|
||||
|
||||
|
||||
@sv.on_fullmatch(('gs帮助', 'genshin帮助', 'ys帮助', '原神帮助'))
|
||||
async def send_guide_pic(bot, ev):
|
||||
img = await convert_img(HELP_IMG)
|
||||
@get_help.handle()
|
||||
@handle_exception('建议')
|
||||
@register_menu(
|
||||
'插件帮助',
|
||||
'gs帮助',
|
||||
'查看插件功能帮助图',
|
||||
detail_des=('指令:' '<ft color=(238,120,0)>gs帮助</ft>\n' ' \n' '查看插件功能帮助图'),
|
||||
)
|
||||
async def send_guide_pic(matcher: Matcher):
|
||||
logger.info('获得gs帮助图片成功!')
|
||||
await bot.send(ev, img)
|
||||
if HELP_IMG.exists():
|
||||
await matcher.finish(MessageSegment.file_image(HELP_IMG))
|
||||
else:
|
||||
await matcher.finish('帮助图不存在!')
|
||||
|
||||
|
||||
threading.Thread(
|
||||
|
@ -1,8 +1,29 @@
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from typing import Any, Dict, Union
|
||||
|
||||
from ..base import sv, logger
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import RegexDict
|
||||
from nonebot import on_regex, on_command
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot.adapters.onebot.v11 import (
|
||||
Bot,
|
||||
MessageSegment,
|
||||
GroupMessageEvent,
|
||||
PrivateMessageEvent,
|
||||
)
|
||||
|
||||
from ..config import priority
|
||||
from ..genshinuid_meta import register_menu
|
||||
from ..utils.nonebot2.rule import FullCommand
|
||||
from .draw_genshinmap_card import MAP_DATA, draw_genshin_map
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
change_map = on_command('切换地图', block=True, rule=FullCommand())
|
||||
find_map = on_regex(
|
||||
r'^(?P<name>.*)(在哪里|在哪|哪里有|哪儿有|哪有|在哪儿)$', priority=priority
|
||||
)
|
||||
find_map2 = on_regex(r'^(哪里有|哪儿有|哪有)(?P<name>.*)$', priority=priority)
|
||||
|
||||
|
||||
MAP_ID_LIST = [
|
||||
'2', # 提瓦特
|
||||
@ -18,13 +39,31 @@ MAP_CHN_NAME = {
|
||||
}
|
||||
|
||||
|
||||
@sv.on_fullmatch('切换地图')
|
||||
async def send_change_map_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
if qid not in bot.config.SUPERUSERS:
|
||||
@change_map.handle()
|
||||
@handle_exception('切换地图')
|
||||
@register_menu(
|
||||
'切换地图',
|
||||
'切换地图',
|
||||
'切换查找资源点功能所使用的地图',
|
||||
detail_des=(
|
||||
'介绍:\n'
|
||||
'切换查找资源点功能所使用的地图\n'
|
||||
'指令按列表顺序轮流切换地图\n'
|
||||
'目前可用地图:'
|
||||
+ ";".join(
|
||||
[f"<ft color=(238,120,0)>{x}</ft>" for x in MAP_CHN_NAME.values()]
|
||||
)
|
||||
+ ' \n\n'
|
||||
'指令:\n'
|
||||
'- <ft color=(238,120,0)>切换地图</ft>'
|
||||
),
|
||||
)
|
||||
async def send_change_map_msg(
|
||||
bot: Bot,
|
||||
event: Union[GroupMessageEvent, PrivateMessageEvent],
|
||||
matcher: Matcher,
|
||||
):
|
||||
if not await SUPERUSER(bot, event):
|
||||
return
|
||||
logger.info('[切换地图]正在执行...')
|
||||
MAP_ID_LIST.append(MAP_ID_LIST[0])
|
||||
@ -32,44 +71,66 @@ async def send_change_map_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
current = MAP_ID_LIST[0]
|
||||
chn = MAP_CHN_NAME.get(current)
|
||||
logger.info(f'[切换地图]当前地图为{chn}')
|
||||
await bot.send(ev, f'切换到{chn}地图')
|
||||
await matcher.finish(f'切换到{chn}地图')
|
||||
|
||||
|
||||
@sv.on_rex(r'^(?P<name>.*)(在哪里|在哪|哪里有|哪儿有|哪有|在哪儿)$')
|
||||
@sv.on_rex(r'^(哪里有|哪儿有|哪有)(?P<name>.*)$')
|
||||
async def send_find_map_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
@find_map.handle()
|
||||
@find_map2.handle()
|
||||
@handle_exception('查找资源点')
|
||||
@register_menu(
|
||||
'查找资源点',
|
||||
'xx在哪',
|
||||
'查找指定资源在地图上的位置',
|
||||
detail_des=(
|
||||
'介绍:\n'
|
||||
'在米游社大地图上查询某资源的位置\n'
|
||||
'使用 <ft color=(238,120,0)>切换地图</ft> 指令来切换目标地图'
|
||||
' \n'
|
||||
'指令:\n'
|
||||
'- <ft color=(0,148,200)>[资源名称]</ft>'
|
||||
'<ft color=(238,120,0)>{在哪里|在哪|哪里有|哪儿有|哪有|在哪儿}</ft>\n'
|
||||
'- <ft color=(238,120,0)>{哪里有|哪儿有|哪有}</ft>'
|
||||
'<ft color=(0,148,200)>[资源名称]</ft>\n'
|
||||
' \n'
|
||||
'示例:\n'
|
||||
'- <ft color=(238,120,0)>甜甜花在哪</ft>\n'
|
||||
'- <ft color=(238,120,0)>哪有清心</ft>'
|
||||
),
|
||||
)
|
||||
async def send_find_map_msg(
|
||||
matcher: Matcher, args: Dict[str, Any] = RegexDict()
|
||||
):
|
||||
map_id = MAP_ID_LIST[0]
|
||||
map_name = MAP_CHN_NAME[map_id]
|
||||
args = ev['match'].groupdict().get('name')
|
||||
logger.info(f'[查找资源点]正在执行...当前地图为{map_name}')
|
||||
logger.info('[查找资源点]参数: {}'.format(args))
|
||||
|
||||
if not args:
|
||||
if not (args and (name := args.get('name'))):
|
||||
return
|
||||
|
||||
im = ''
|
||||
|
||||
if not MAP_DATA.exists():
|
||||
MAP_DATA.mkdir()
|
||||
|
||||
resource_temp_path = MAP_DATA / f'{map_name}_{args}.jpg'
|
||||
resource_temp_path = MAP_DATA / f'{map_name}_{name}.jpg'
|
||||
if resource_temp_path.exists():
|
||||
logger.info(f'本地已有{map_name}_{args}的资源点,直接发送...')
|
||||
resource_temp = await convert_img(resource_temp_path)
|
||||
await bot.send(ev, resource_temp)
|
||||
logger.info(f'本地已有{map_name}_{name}的资源点,直接发送...')
|
||||
with open(resource_temp_path, 'rb') as f:
|
||||
await matcher.finish(MessageSegment.image(f.read()))
|
||||
else:
|
||||
# 放弃安慰剂回复
|
||||
'''
|
||||
await bot.send(
|
||||
ev,
|
||||
f'正在查找{args},可能需要比较久的时间...\n当前地图:{map_name}',
|
||||
await matcher.send(
|
||||
(
|
||||
f'正在查找{name},可能需要比较久的时间...\n'
|
||||
f'当前地图:{MAP_CHN_NAME.get(MAP_ID_LIST[0])}'
|
||||
)
|
||||
)
|
||||
'''
|
||||
logger.info('本地未缓存,正在渲染...')
|
||||
im = await draw_genshin_map(args, map_id, map_name)
|
||||
im = await draw_genshin_map(name, map_id, map_name)
|
||||
if isinstance(im, str):
|
||||
return
|
||||
# await bot.send(ev, im)
|
||||
await matcher.finish()
|
||||
elif isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(MessageSegment.image(im))
|
||||
else:
|
||||
await matcher.finish('查找失败!')
|
||||
|
45
GenshinUID/genshinuid_meta/__init__.py
Normal file
45
GenshinUID/genshinuid_meta/__init__.py
Normal file
@ -0,0 +1,45 @@
|
||||
from typing import Optional
|
||||
|
||||
from nonebot.plugin import PluginMetadata
|
||||
|
||||
sub_menus = []
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name='GenshinUID',
|
||||
description='基于NoneBot2的原神Uid查询/原神Wiki/米游社签到/树脂提醒插件',
|
||||
usage=(
|
||||
'发送 <ft color=(238,120,0)>gs帮助</ft> 可以获取帮助列表,也可以参考下面的表格\n'
|
||||
'可以使用 <ft color=(238,120,0)>菜单 gsuid </ft>'
|
||||
'<ft color=(0,148,200)>[序号]</ft> '
|
||||
'指令获取某功能详细介绍\n'
|
||||
' \n'
|
||||
'示例指令小括号中的内容为可选参数,可以省略;\n'
|
||||
'中括号中的内容或者用“xx”代表的内容为必选参数,请将它们替换为对应的参数'
|
||||
),
|
||||
extra={'menu_data': sub_menus, 'menu_template': 'default'},
|
||||
)
|
||||
|
||||
|
||||
def register_menu_func(
|
||||
func: str,
|
||||
trigger_condition: str,
|
||||
brief_des: str,
|
||||
trigger_method: str = '指令',
|
||||
detail_des: Optional[str] = None,
|
||||
):
|
||||
sub_menus.append(
|
||||
{
|
||||
'func': func,
|
||||
'trigger_method': trigger_method,
|
||||
'trigger_condition': trigger_condition,
|
||||
'brief_des': brief_des,
|
||||
'detail_des': detail_des or brief_des,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def register_menu(*args, **kwargs):
|
||||
def decorator(f):
|
||||
register_menu_func(*args, **kwargs)
|
||||
return f
|
||||
|
||||
return decorator
|
@ -1,35 +1,49 @@
|
||||
import random
|
||||
import asyncio
|
||||
|
||||
from nonebot import get_bot
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot import get_bot, on_command
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot.adapters.qqguild import MessageEvent
|
||||
|
||||
from ..base import sv, logger
|
||||
from ..config import SUPERUSERS, priority
|
||||
from ..utils.nonebot2.rule import FullCommand
|
||||
from ..utils.db_operation.db_operation import config_check
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
from .daily_mihoyo_bbs_coin import mihoyo_coin, all_daily_mihoyo_bbs_coin
|
||||
|
||||
bbscoin_scheduler = scheduler
|
||||
|
||||
get_mihoyo_coin = on_command('开始获取米游币', priority=priority, rule=FullCommand())
|
||||
all_bbscoin_recheck = on_command(
|
||||
'全部重获取', permission=SUPERUSER, priority=priority, rule=FullCommand()
|
||||
)
|
||||
|
||||
|
||||
# 获取米游币
|
||||
@sv.on_fullmatch('开始获取米游币')
|
||||
async def send_mihoyo_coin(bot: HoshinoBot, ev: CQEvent):
|
||||
await bot.send(ev, '开始操作……', at_sender=True)
|
||||
qid = int(ev.sender['user_id']) # type: ignore
|
||||
@get_mihoyo_coin.handle()
|
||||
@handle_exception('获取米游币')
|
||||
async def send_mihoyo_coin(event: MessageEvent, matcher: Matcher):
|
||||
await matcher.send('开始操作……', at_sender=True)
|
||||
qid = int(event.sender.user_id) # type: ignore
|
||||
im = await mihoyo_coin(qid)
|
||||
await bot.send(ev, im, at_sender=True)
|
||||
await matcher.finish(im, at_sender=True)
|
||||
|
||||
|
||||
@sv.on_fullmatch('全部重获取')
|
||||
async def bbs_recheck(bot: HoshinoBot, ev: CQEvent):
|
||||
qid = int(ev.sender['user_id']) # type: ignore
|
||||
if qid not in bot.config.SUPERUSERS:
|
||||
return
|
||||
await bot.send(ev, '已开始执行!可能需要较久时间!')
|
||||
@all_bbscoin_recheck.handle()
|
||||
@handle_exception('米游币全部重获取')
|
||||
async def bbs_recheck(
|
||||
matcher: Matcher,
|
||||
):
|
||||
await matcher.send('已开始执行!可能需要较久时间!')
|
||||
await send_daily_mihoyo_bbs_sign()
|
||||
await bot.send(ev, '执行完成!')
|
||||
await matcher.finish('执行完成!')
|
||||
|
||||
|
||||
# 每日一点十六分进行米游币获取
|
||||
@sv.scheduled_job('cron', hour='1', minute='16')
|
||||
@bbscoin_scheduler.scheduled_job('cron', hour='1', minute='16')
|
||||
async def sign_at_night():
|
||||
if await config_check('SchedMhyBBSCoin'):
|
||||
await send_daily_mihoyo_bbs_sign()
|
||||
@ -45,7 +59,7 @@ async def send_daily_mihoyo_bbs_sign():
|
||||
)
|
||||
await asyncio.sleep(5 + random.randint(1, 3))
|
||||
if await config_check('PrivateReport'):
|
||||
for qid in bot.config.SUPERUSERS:
|
||||
await bot.send_private_msg(user_id=qid, message=im)
|
||||
for qid in SUPERUSERS:
|
||||
await bot.call_api(api='send_private_msg', user_id=qid, message=im)
|
||||
await asyncio.sleep(5 + random.randint(1, 3))
|
||||
logger.info('米游币获取已结束。')
|
||||
|
@ -1,39 +1,63 @@
|
||||
import asyncio
|
||||
from typing import Any, Tuple
|
||||
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import RegexGroup
|
||||
from nonebot import on_regex, on_command
|
||||
from nonebot.adapters.qqguild import Bot, MessageEvent, MessageSegment
|
||||
|
||||
from ..base import sv, logger
|
||||
from ..config import priority
|
||||
from .get_lots_data import get_lots_msg
|
||||
from .get_meme_card import get_meme_img
|
||||
from .get_mys_data import get_region_task, get_task_detail
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from .get_mys_data import get_task_detail
|
||||
from ..utils.nonebot2.rule import FullCommand
|
||||
from ..utils.message.cast_type import cast_to_int
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
get_task_adv = on_regex(
|
||||
r'^(原神任务|任务|任务详情|任务攻略)( )?([\u4e00-\u9fa5]+)( )?$', priority=priority
|
||||
)
|
||||
get_meme = on_command('抽表情', priority=priority, rule=FullCommand())
|
||||
get_lots = on_command('御神签', priority=priority, rule=FullCommand())
|
||||
|
||||
|
||||
@sv.on_rex(r'^(原神任务|任务|任务详情|任务攻略)( )?([\u4e00-\u9fa5]+)( )?$')
|
||||
async def send_task_adv(bot: HoshinoBot, ev: CQEvent):
|
||||
args = ev['match'].groups()
|
||||
@get_task_adv.handle()
|
||||
@handle_exception('任务攻略')
|
||||
async def send_task_adv(
|
||||
bot: Bot,
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
args: Tuple[Any, ...] = RegexGroup(),
|
||||
):
|
||||
if str(args[2]) in ['须弥', '层岩', '海岛']:
|
||||
pass
|
||||
'''
|
||||
im = await get_region_task(str(args[2]))
|
||||
for i in im:
|
||||
await bot.send_group_forward_msg(group_id=ev.group_id, messages=i)
|
||||
await bot.call_api(
|
||||
'send_group_forward_msg', group_id=event.group_id, messages=i
|
||||
)
|
||||
await asyncio.sleep(1)
|
||||
return
|
||||
await matcher.finish()
|
||||
'''
|
||||
else:
|
||||
im = await get_task_detail(str(args[2]))
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
||||
|
||||
@sv.on_fullmatch('抽表情')
|
||||
async def send_meme_card(bot: HoshinoBot, ev: CQEvent):
|
||||
@get_meme.handle()
|
||||
@handle_exception('抽表情')
|
||||
async def send_meme_card(matcher: Matcher):
|
||||
logger.info('开始执行[抽表情]')
|
||||
img = await get_meme_img()
|
||||
img = await convert_img(img)
|
||||
await bot.send(ev, img)
|
||||
await matcher.finish(MessageSegment.file_image(img))
|
||||
|
||||
|
||||
@sv.on_fullmatch('御神签')
|
||||
async def send_lots_data(bot: HoshinoBot, ev: CQEvent):
|
||||
qid = int(ev.sender['user_id'])
|
||||
@get_lots.handle()
|
||||
@handle_exception('御神签')
|
||||
async def send_lots_data(matcher: Matcher, event: MessageEvent):
|
||||
qid = cast_to_int(event.author)
|
||||
logger.info('开始执行[御神签]')
|
||||
im = await get_lots_msg(qid)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
@ -1,48 +1,62 @@
|
||||
import re
|
||||
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot import on_command
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.adapters.qqguild import MessageEvent, MessageSegment
|
||||
|
||||
from .note_text import award
|
||||
from ..base import sv, logger
|
||||
from ..config import priority
|
||||
from .draw_note_card import draw_note_img
|
||||
from ..utils.message.error_reply import UID_HINT
|
||||
from ..utils.nonebot2.rule import FullCommand
|
||||
from ..utils.message.cast_type import cast_to_int
|
||||
from ..utils.db_operation.db_operation import select_db
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.message.error_reply import CK_HINT, UID_HINT
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
monthly_data = on_command('每月统计', priority=priority, rule=FullCommand())
|
||||
get_genshin_info = on_command(
|
||||
'当前信息', aliases={'zj', '札记', '原石札记'}, priority=priority, rule=FullCommand()
|
||||
)
|
||||
|
||||
|
||||
# 群聊内 每月统计 功能
|
||||
@sv.on_fullmatch('每月统计')
|
||||
async def send_monthly_data(bot: HoshinoBot, ev: CQEvent):
|
||||
qid = int(ev.sender['user_id']) # type: ignore
|
||||
uid = await select_db(qid, mode='uid')
|
||||
@monthly_data.handle()
|
||||
@handle_exception('每月统计', '获取/发送每月统计失败', '@未找到绑定信息\n' + CK_HINT)
|
||||
async def send_monthly_data(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
qid = cast_to_int(event.author)
|
||||
logger.info('[每月统计]QQ号: {}'.format(qid))
|
||||
uid = await select_db(str(qid), mode='uid')
|
||||
if isinstance(uid, str):
|
||||
if '未找到绑定的UID' in uid:
|
||||
await bot.send(ev, UID_HINT)
|
||||
await matcher.finish(UID_HINT)
|
||||
else:
|
||||
await bot.send(ev, '发生未知错误...')
|
||||
await matcher.finish('发生未知错误...')
|
||||
im = await award(uid)
|
||||
await bot.send(ev, im, at_sender=True)
|
||||
await matcher.finish(im, at_sender=True)
|
||||
|
||||
|
||||
@sv.on_fullmatch(('当前信息', 'zj', '原石札记', '札记'))
|
||||
async def send_monthly_pic(bot: HoshinoBot, ev: CQEvent):
|
||||
logger.info('开始执行[每日信息]')
|
||||
at = re.search(r'\[CQ:at,qq=(\d*)]', str(ev.message))
|
||||
if at:
|
||||
qid = int(at.group(1))
|
||||
# 群聊内 每月统计 功能
|
||||
@get_genshin_info.handle()
|
||||
@handle_exception('每月统计', '获取/发送每月统计失败', '@未找到绑定信息\n' + CK_HINT)
|
||||
async def send_monthly_pic(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
qid = cast_to_int(event.author)
|
||||
logger.info('[原石札记]QQ号: {}'.format(qid))
|
||||
uid = await select_db(str(qid), mode='uid')
|
||||
if isinstance(uid, str):
|
||||
if '未找到绑定的UID' in uid:
|
||||
await matcher.finish(UID_HINT)
|
||||
else:
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
logger.info('[每日信息]QQ号: {}'.format(qid))
|
||||
uid = await select_db(qid, mode='uid')
|
||||
logger.info('[每日信息]UID: {}'.format(uid))
|
||||
im = await draw_note_img(str(uid))
|
||||
await matcher.finish('发生未知错误...')
|
||||
logger.info(f'[原石札记] 开始绘制,UID: {uid}')
|
||||
im = await draw_note_img(uid)
|
||||
if isinstance(im, str):
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
elif isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
await bot.send(ev, '发生了未知错误,请联系管理员检查后台输出!')
|
||||
await matcher.finish('发生了未知错误,请联系管理员检查后台输出!')
|
||||
|
@ -1,118 +1,107 @@
|
||||
import re
|
||||
import asyncio
|
||||
|
||||
from nonebot import get_bot
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot.log import logger
|
||||
from nonebot.params import Depends
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot import get_bot, on_command
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot.adapters.qqguild import MessageEvent, MessageSegment
|
||||
|
||||
from ..base import sv, logger
|
||||
from .notice import get_notice_list
|
||||
from .resin_text import get_resin_text
|
||||
from .draw_resin_card import get_resin_img
|
||||
from ..utils.nonebot2.rule import FullCommand
|
||||
from ..utils.message.error_reply import UID_HINT
|
||||
from ..utils.message.cast_type import cast_to_int
|
||||
from ..utils.db_operation.db_operation import select_db
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.message.get_image_and_at import ImageAndAt
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
notice_scheduler = scheduler
|
||||
get_resin_info = on_command(
|
||||
'每日',
|
||||
aliases={'mr', '状态', '实时便笺', '便笺', '便签'},
|
||||
block=True,
|
||||
rule=FullCommand(),
|
||||
)
|
||||
get_daily_info = on_command('当前状态', rule=FullCommand())
|
||||
|
||||
|
||||
@sv.on_fullmatch('当前状态')
|
||||
async def send_daily_info(bot: HoshinoBot, ev: CQEvent):
|
||||
@get_daily_info.handle()
|
||||
@handle_exception('每日信息文字版')
|
||||
async def send_daily_info(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
custom: ImageAndAt = Depends(),
|
||||
):
|
||||
logger.info('开始执行[每日信息文字版]')
|
||||
at = re.search(r'\[CQ:at,qq=(\d*)]', str(ev.message))
|
||||
if ev.sender:
|
||||
qid = ev.sender['user_id']
|
||||
else:
|
||||
return
|
||||
|
||||
at = custom.get_first_at()
|
||||
qid = at or cast_to_int(event.author)
|
||||
if at:
|
||||
qid = at.group(1)
|
||||
|
||||
qid = at
|
||||
logger.info('[每日信息文字版]QQ号: {}'.format(qid))
|
||||
|
||||
uid: str = await select_db(qid, mode='uid') # type: ignore
|
||||
logger.info('[每日信息文字版]UID: {}'.format(uid))
|
||||
|
||||
if '未找到绑定的UID' in uid:
|
||||
await bot.send(ev, UID_HINT)
|
||||
if not uid:
|
||||
await matcher.finish(UID_HINT)
|
||||
|
||||
im = await get_resin_text(uid)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
||||
|
||||
@sv.scheduled_job('cron', minute='*/30')
|
||||
@notice_scheduler.scheduled_job('cron', minute='*/30')
|
||||
async def notice_job():
|
||||
bot = get_bot()
|
||||
result = await get_notice_list()
|
||||
logger.info('[推送检查]完成!等待消息推送中...')
|
||||
# 执行私聊推送
|
||||
bot_ids = bot._wsr_api_clients.keys()
|
||||
for qid in result[0]:
|
||||
send_success = False
|
||||
for sid in bot_ids:
|
||||
try:
|
||||
await bot.send_private_msg(
|
||||
self_id=sid,
|
||||
await bot.call_api(
|
||||
api='send_private_msg',
|
||||
user_id=qid,
|
||||
message=result[0][qid],
|
||||
)
|
||||
send_success = True
|
||||
break
|
||||
except Exception:
|
||||
logger.info(f'[推送检查(轮推)] BOT {sid} 没有 {qid} 好友,已跳过')
|
||||
if not send_success:
|
||||
logger.warning(f'[推送检查] QQ {qid} 私聊推送失败!')
|
||||
await asyncio.sleep(0.5)
|
||||
logger.info('[推送检查] 私聊推送完成')
|
||||
logger.info('[推送检查]私聊推送完成')
|
||||
# 执行群聊推送
|
||||
for group_id in result[1]:
|
||||
send_success = False
|
||||
for sid in bot_ids:
|
||||
try:
|
||||
await bot.send_group_msg(
|
||||
self_id=sid,
|
||||
await bot.call_api(
|
||||
api='send_group_msg',
|
||||
group_id=group_id,
|
||||
message=result[1][group_id],
|
||||
)
|
||||
send_success = True
|
||||
break
|
||||
except Exception:
|
||||
logger.info(f'[推送检查(轮推)] BOT {sid} 没有 {group_id} 群,已跳过')
|
||||
if not send_success:
|
||||
logger.warning(f'[推送检查] 群 {group_id} 推送失败!')
|
||||
logger.warning(f'[推送检查] 群 {group_id} 群聊推送失败!')
|
||||
await asyncio.sleep(0.5)
|
||||
logger.info('[推送检查] 群聊推送完成')
|
||||
logger.info('[推送检查]群聊推送完成')
|
||||
|
||||
|
||||
@sv.on_fullmatch(('执行推送检查任务'))
|
||||
async def manual_notice_job(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
if qid not in bot.config.SUPERUSERS:
|
||||
return
|
||||
await notice_job()
|
||||
await bot.send(ev, '推送检查任务已执行')
|
||||
|
||||
|
||||
@sv.on_fullmatch(('每日', 'mr', '实时便笺', '便笺', '便签'))
|
||||
async def send_daily_info_pic(bot: HoshinoBot, ev: CQEvent):
|
||||
@get_resin_info.handle()
|
||||
@handle_exception('每日信息')
|
||||
async def send_uid_info(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
custom: ImageAndAt = Depends(),
|
||||
):
|
||||
logger.info('开始执行[每日信息]')
|
||||
at = re.search(r'\[CQ:at,qq=(\d*)]', str(ev.message))
|
||||
|
||||
at = custom.get_first_at()
|
||||
qid = at or cast_to_int(event.author)
|
||||
if at:
|
||||
qid = int(at.group(1))
|
||||
else:
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
|
||||
qid = at
|
||||
logger.info('[每日信息]QQ号: {}'.format(qid))
|
||||
|
||||
qid = int(qid)
|
||||
im = await get_resin_img(qid)
|
||||
if isinstance(im, str):
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
elif isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
await bot.send(ev, '发生了未知错误,请联系管理员检查后台输出!')
|
||||
await matcher.finish('发生了未知错误,请联系管理员检查后台输出!')
|
||||
|
@ -1,25 +1,33 @@
|
||||
import asyncio
|
||||
import threading
|
||||
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot import on_command
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot.adapters.qqguild import Bot, MessageEvent
|
||||
|
||||
from ..base import sv, logger
|
||||
from ..utils.nonebot2.rule import FullCommand
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
from ..utils.download_resource.download_all_resource import (
|
||||
download_all_resource,
|
||||
)
|
||||
|
||||
download_resource = on_command('下载全部资源', rule=FullCommand())
|
||||
|
||||
@sv.on_fullmatch('下载全部资源')
|
||||
async def send_download_resource_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.sender:
|
||||
qid = ev.sender['user_id']
|
||||
else:
|
||||
|
||||
@download_resource.handle()
|
||||
@handle_exception('下载全部资源', '资源下载错误')
|
||||
async def send_download_resource_msg(
|
||||
bot: Bot,
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
if not await SUPERUSER(bot, event):
|
||||
return
|
||||
if qid not in bot.config.SUPERUSERS:
|
||||
return
|
||||
await bot.send(ev, '正在开始下载~可能需要较久的时间!')
|
||||
await matcher.send('正在开始下载~可能需要较久的时间!')
|
||||
im = await download_all_resource()
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
||||
|
||||
async def startup():
|
||||
|
@ -1,28 +1,82 @@
|
||||
import re
|
||||
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot import on_command
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import Depends, CommandArg
|
||||
from nonebot.adapters.qqguild import Message, MessageEvent, MessageSegment
|
||||
|
||||
from ..base import sv, logger
|
||||
from .get_regtime import calc_reg_time
|
||||
from .draw_roleinfo_card import draw_pic
|
||||
from ..utils.nonebot2.rule import FullCommand
|
||||
from ..utils.message.error_reply import UID_HINT
|
||||
from ..utils.message.cast_type import cast_to_int
|
||||
from ..utils.db_operation.db_operation import select_db
|
||||
from ..utils.mhy_api.convert_mysid_to_uid import convert_mysid
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.message.get_image_and_at import ImageAndAt
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
get_role_info = on_command('uid', aliases={'查询'})
|
||||
get_reg_time = on_command(
|
||||
'原神注册时间', aliases={'注册时间', '查询注册时间'}, rule=FullCommand()
|
||||
)
|
||||
|
||||
|
||||
@sv.on_prefix(('原神注册时间', '注册时间'))
|
||||
async def regtime(bot, ev):
|
||||
at = re.search(r'\[CQ:at,qq=(\d*)]', str(ev.message))
|
||||
|
||||
if at:
|
||||
qid = int(at.group(1))
|
||||
else:
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
@get_role_info.handle()
|
||||
@handle_exception('查询角色信息')
|
||||
async def send_role_info(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
args: Message = CommandArg(),
|
||||
custom: ImageAndAt = Depends(),
|
||||
):
|
||||
raw_mes = args.extract_plain_text().strip().replace(' ', '')
|
||||
name = ''.join(re.findall('[\u4e00-\u9fa5]', raw_mes))
|
||||
if name:
|
||||
return
|
||||
|
||||
at = custom.get_first_at()
|
||||
qid = at or cast_to_int(event.author)
|
||||
if at:
|
||||
qid = at
|
||||
qid = str(qid)
|
||||
|
||||
# 获取uid
|
||||
uid = re.findall(r'\d+', raw_mes)
|
||||
if uid:
|
||||
uid = uid[0]
|
||||
else:
|
||||
uid = await select_db(qid, mode='uid')
|
||||
uid = str(uid)
|
||||
logger.info('开始执行[查询角色信息]')
|
||||
|
||||
logger.info('[查询角色信息]参数: {}'.format(args))
|
||||
logger.info('[查询角色信息]uid: {}'.format(uid))
|
||||
|
||||
if '未找到绑定的UID' in uid:
|
||||
await matcher.finish(UID_HINT)
|
||||
|
||||
im = await draw_pic(uid)
|
||||
|
||||
if isinstance(im, str):
|
||||
await matcher.finish(im)
|
||||
elif isinstance(im, bytes):
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
await matcher.finish('发生了未知错误,请联系管理员检查后台输出!')
|
||||
|
||||
|
||||
@get_reg_time.handle()
|
||||
async def regtime(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
custom: ImageAndAt = Depends(),
|
||||
):
|
||||
at = custom.get_first_at()
|
||||
qid = at or cast_to_int(event.author)
|
||||
if at:
|
||||
qid = at
|
||||
qid = str(qid)
|
||||
|
||||
uid = await select_db(qid, mode='uid')
|
||||
uid = str(uid)
|
||||
|
||||
@ -30,57 +84,11 @@ async def regtime(bot, ev):
|
||||
logger.info('[查询注册时间]uid: {}'.format(uid))
|
||||
|
||||
if '未找到绑定的UID' in uid:
|
||||
await bot.send(ev, UID_HINT)
|
||||
await matcher.finish(UID_HINT)
|
||||
|
||||
im = await calc_reg_time(uid)
|
||||
await bot.send(ev, im)
|
||||
|
||||
|
||||
@sv.on_rex(r'^()?()?()?([1256][0-9]{8})()?()?$')
|
||||
@sv.on_rex(
|
||||
r'^(\[CQ:at,qq=[0-9]+\])?( )?'
|
||||
r'(uid|查询|mys)([0-9]+)?'
|
||||
r'(\[CQ:at,qq=[0-9]+\])?( )?$',
|
||||
)
|
||||
async def send_role_info(bot: HoshinoBot, ev: CQEvent):
|
||||
args = ev['match'].groups()
|
||||
at = re.search(r'\[CQ:at,qq=(\d*)]', str(ev.message))
|
||||
|
||||
if at:
|
||||
qid = int(at.group(1))
|
||||
else:
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
|
||||
# 判断uid
|
||||
if args[2] != 'mys':
|
||||
if args[3] is None:
|
||||
if args[2] is None:
|
||||
return
|
||||
uid = await select_db(qid, mode='uid')
|
||||
uid = str(uid)
|
||||
elif len(args[3]) != 9:
|
||||
return
|
||||
else:
|
||||
uid = args[3]
|
||||
else:
|
||||
uid = await convert_mysid(args[3])
|
||||
|
||||
logger.info('开始执行[查询角色信息]')
|
||||
logger.info('[查询角色信息]参数: {}'.format(args))
|
||||
logger.info('[查询角色信息]uid: {}'.format(uid))
|
||||
|
||||
if '未找到绑定的UID' in uid:
|
||||
await bot.send(ev, UID_HINT)
|
||||
|
||||
im = await draw_pic(uid)
|
||||
|
||||
if isinstance(im, str):
|
||||
await bot.send(ev, im)
|
||||
elif isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
else:
|
||||
await bot.send(ev, '发生了未知错误,请联系管理员检查后台输出!')
|
||||
await matcher.finish('发生了未知错误,请联系管理员检查后台输出!')
|
||||
|
@ -1,51 +1,63 @@
|
||||
import random
|
||||
import asyncio
|
||||
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot import get_bot, on_command
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot.adapters.qqguild import MessageEvent
|
||||
|
||||
from ..config import priority
|
||||
|
||||
try:
|
||||
from sign import sign_in, daily_sign
|
||||
except ImportError:
|
||||
from .sign import sign_in, daily_sign
|
||||
|
||||
import asyncio
|
||||
|
||||
from nonebot import get_bot
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
|
||||
from ..base import sv, logger
|
||||
from ..utils.nonebot2.rule import FullCommand
|
||||
from ..utils.message.cast_type import cast_to_int
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
from ..utils.db_operation.db_operation import select_db, config_check
|
||||
|
||||
sign_scheduler = scheduler
|
||||
|
||||
get_sign = on_command('签到', priority=priority, rule=FullCommand())
|
||||
all_recheck = on_command(
|
||||
'全部重签', permission=SUPERUSER, priority=priority, rule=FullCommand()
|
||||
)
|
||||
|
||||
|
||||
# 每日零点半执行米游社原神签到
|
||||
@sv.scheduled_job('cron', hour='0', minute='30')
|
||||
@sign_scheduler.scheduled_job('cron', hour='0', minute='30')
|
||||
async def sign_at_night():
|
||||
if await config_check('SchedSignin'):
|
||||
await send_daily_sign()
|
||||
|
||||
|
||||
# 群聊内 签到 功能
|
||||
@sv.on_rex(r'^(gs|米游社)(签到)$')
|
||||
async def get_sign_func(bot: HoshinoBot, ev: CQEvent):
|
||||
@get_sign.handle()
|
||||
@handle_exception('签到')
|
||||
async def get_sign_func(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
logger.info('开始执行[签到]')
|
||||
qid = int(ev.sender['user_id']) # type: ignore
|
||||
qid = cast_to_int(event.author)
|
||||
logger.info('[签到]QQ号: {}'.format(qid))
|
||||
uid = await select_db(qid, mode='uid')
|
||||
uid = await select_db(str(qid), mode='uid')
|
||||
logger.info('[签到]UID: {}'.format(uid))
|
||||
im = await sign_in(uid)
|
||||
await bot.send(ev, im, at_sender=True)
|
||||
await matcher.finish(im, at_sender=True)
|
||||
|
||||
|
||||
@sv.on_fullmatch('全部重签')
|
||||
async def recheck(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
if qid not in bot.config.SUPERUSERS:
|
||||
return
|
||||
|
||||
@all_recheck.handle()
|
||||
@handle_exception('全部重签')
|
||||
async def recheck(matcher: Matcher):
|
||||
logger.info('开始执行[全部重签]')
|
||||
await bot.send(ev, '已开始执行')
|
||||
await matcher.send('已开始执行')
|
||||
await send_daily_sign()
|
||||
await bot.send(ev, '执行完成')
|
||||
await matcher.finish('执行完成')
|
||||
|
||||
|
||||
async def send_daily_sign():
|
||||
@ -60,7 +72,8 @@ async def send_daily_sign():
|
||||
# 执行私聊推送
|
||||
for qid in private_msg_list:
|
||||
try:
|
||||
await bot.send_private_msg(
|
||||
await bot.call_api(
|
||||
api='send_private_msg',
|
||||
user_id=qid,
|
||||
message=private_msg_list[qid],
|
||||
)
|
||||
@ -87,7 +100,8 @@ async def send_daily_sign():
|
||||
msg_title = group_msg_list[gid]['push_message']
|
||||
# 发送群消息
|
||||
try:
|
||||
await bot.send_group_msg(
|
||||
await bot.call_api(
|
||||
api='send_group_msg',
|
||||
group_id=gid,
|
||||
message=msg_title,
|
||||
)
|
||||
|
@ -1,78 +1,85 @@
|
||||
from nonebot import get_bot, on_startup
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from typing import Any, Tuple
|
||||
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import RegexGroup
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot import get_bot, on_regex, get_driver
|
||||
from nonebot.adapters.qqguild import Bot, MessageEvent, MessageSegment
|
||||
|
||||
from ..base import sv, logger
|
||||
from .draw_update_log import draw_update_log_img
|
||||
from ..utils.message.cast_type import cast_to_int
|
||||
from .restart import restart_message, restart_genshinuid
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
|
||||
gs_restart = on_regex(r'^(gs)(重启)$')
|
||||
get_update_log = on_regex(r'更新记录')
|
||||
gs_update = on_regex(
|
||||
r'^(gs)(强行)?(强制)?(更新)$',
|
||||
block=True,
|
||||
)
|
||||
|
||||
|
||||
@on_startup
|
||||
async def check_msg():
|
||||
try:
|
||||
@get_driver().on_bot_connect
|
||||
async def _():
|
||||
logger.info('检查遗留信息...')
|
||||
bot = get_bot()
|
||||
update_log = await restart_message()
|
||||
if update_log == {}:
|
||||
return
|
||||
bot = get_bot()
|
||||
if update_log['send_type'] == 'group':
|
||||
await bot.send_group_msg(
|
||||
await bot.call_api(
|
||||
api='send_group_msg',
|
||||
group_id=update_log['send_to'],
|
||||
message=update_log['msg'],
|
||||
)
|
||||
else:
|
||||
await bot.send_private_msg(
|
||||
await bot.call_api(
|
||||
api='send_private_msg',
|
||||
user_id=update_log['send_to'],
|
||||
message=update_log['msg'],
|
||||
)
|
||||
logger.info('遗留信息检查完毕!')
|
||||
except Exception:
|
||||
logger.warning('遗留信息检查失败!')
|
||||
|
||||
|
||||
@sv.on_fullmatch('gs重启')
|
||||
async def send_restart_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
if qid not in bot.config.SUPERUSERS:
|
||||
@gs_restart.handle()
|
||||
async def send_restart_msg(
|
||||
bot: Bot,
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
if not await SUPERUSER(bot, event):
|
||||
return
|
||||
logger.warning('开始执行[重启]')
|
||||
|
||||
if ev.group_id:
|
||||
send_id = str(ev.group_id)
|
||||
send_id = cast_to_int(event.author)
|
||||
send_type = 'group'
|
||||
else:
|
||||
send_id = qid
|
||||
send_type = 'private'
|
||||
await bot.send(ev, '正在执行[gs重启]...')
|
||||
await matcher.send('正在执行[gs重启]...')
|
||||
await restart_genshinuid(send_type, str(send_id))
|
||||
|
||||
|
||||
@sv.on_fullmatch('更新记录')
|
||||
async def send_updatelog_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
@get_update_log.handle()
|
||||
async def send_updatelog_msg(
|
||||
matcher: Matcher,
|
||||
):
|
||||
im = await draw_update_log_img(is_update=False)
|
||||
logger.info('正在执行[更新记录]...')
|
||||
if isinstance(im, str):
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
elif isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
await bot.send(ev, '发生了未知错误,请联系管理员检查后台输出!')
|
||||
await matcher.finish('发生了未知错误,请联系管理员检查后台输出!')
|
||||
|
||||
|
||||
@sv.on_rex(r'^(gs)(强行)?(强制)?(更新)$')
|
||||
async def send_update_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
if qid not in bot.config.SUPERUSERS:
|
||||
@gs_update.handle()
|
||||
async def send_update_msg(
|
||||
bot: Bot,
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
args: Tuple[Any, ...] = RegexGroup(),
|
||||
):
|
||||
if not await SUPERUSER(bot, event):
|
||||
return
|
||||
|
||||
args = ev['match'].groups()
|
||||
logger.info('[gs更新] 正在执行 ...')
|
||||
level = 2
|
||||
if args[1] is None:
|
||||
@ -80,12 +87,11 @@ async def send_update_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
if args[2] is None:
|
||||
level -= 1
|
||||
logger.info(f'[gs更新] 更新等级为{level}')
|
||||
await bot.send(ev, f'开始执行[gs更新], 执行等级为{level}')
|
||||
await matcher.send(f'开始执行[gs更新], 执行等级为{level}')
|
||||
im = await draw_update_log_img(level)
|
||||
if isinstance(im, str):
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
elif isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
else:
|
||||
await bot.send(ev, '发生了未知错误,请联系管理员检查后台输出!')
|
||||
await matcher.finish('发生了未知错误,请联系管理员检查后台输出!')
|
||||
|
@ -8,7 +8,7 @@ from pathlib import Path
|
||||
|
||||
from ..utils.db_operation.db_operation import config_check
|
||||
|
||||
bot_start = Path().cwd() / 'run.py'
|
||||
bot_start = Path().cwd() / 'bot.py'
|
||||
restart_sh_path = Path().cwd() / 'gs_restart.sh'
|
||||
update_log_path = Path(__file__).parent / 'update_log.json'
|
||||
|
||||
@ -23,12 +23,12 @@ async def get_restart_sh(extra: str) -> str:
|
||||
|
||||
|
||||
async def restart_genshinuid(send_type: str, send_id: str) -> None:
|
||||
pid = os.getpid()
|
||||
extra = ''
|
||||
if await config_check('UsePoetry'):
|
||||
extra = 'poetry run '
|
||||
extra += sys.executable
|
||||
restart_sh = await get_restart_sh(extra)
|
||||
if not restart_sh_path.exists():
|
||||
with open(restart_sh_path, "w", encoding="utf8") as f:
|
||||
f.write(restart_sh)
|
||||
if platform.system() == 'Linux':
|
||||
@ -45,11 +45,9 @@ async def restart_genshinuid(send_type: str, send_id: str) -> None:
|
||||
with open(str(update_log_path), 'w', encoding='utf-8') as f:
|
||||
json.dump(update_log, f)
|
||||
if platform.system() == 'Linux':
|
||||
subprocess.Popen(
|
||||
f'kill -9 {pid} & {extra} {bot_start}',
|
||||
shell=True,
|
||||
)
|
||||
os.execl(str(restart_sh_path), ' ')
|
||||
else:
|
||||
pid = os.getpid()
|
||||
subprocess.Popen(
|
||||
f'taskkill /F /PID {pid} & {extra} {bot_start}',
|
||||
shell=True,
|
||||
|
@ -1,141 +1,164 @@
|
||||
import hoshino
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
import asyncio
|
||||
from typing import Any, Tuple
|
||||
|
||||
from .topup import topup_
|
||||
from ..base import sv, logger
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot import on_regex, on_command
|
||||
from nonebot.permission import SUPERUSER
|
||||
from nonebot.params import CommandArg, RegexGroup
|
||||
from nonebot.adapters.qqguild import Message, MessageEvent, MessageSegment
|
||||
|
||||
from ..config import priority
|
||||
from .qrlogin import qrcode_login
|
||||
from ..utils.nonebot2.perm import DIRECT
|
||||
from .get_ck_help_msg import get_ck_help
|
||||
from .draw_user_card import get_user_card
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.nonebot2.rule import FullCommand
|
||||
from ..utils.message.cast_type import cast_to_int
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
from .add_ck import deal_ck, get_ck_by_stoken, get_ck_by_all_stoken
|
||||
from ..utils.db_operation.db_operation import bind_db, delete_db, switch_db
|
||||
|
||||
hoshino_bot = hoshino.get_bot()
|
||||
add_cookie = on_command('添加', permission=DIRECT)
|
||||
get_ck_msg = on_command(
|
||||
'绑定ck说明',
|
||||
aliases={'ck帮助', '绑定ck'},
|
||||
block=True,
|
||||
rule=FullCommand(),
|
||||
)
|
||||
bind_info = on_command(
|
||||
'绑定信息', priority=priority, block=True, rule=FullCommand()
|
||||
)
|
||||
refresh_ck = on_command(
|
||||
'刷新CK',
|
||||
aliases={'刷新ck', '刷新Ck', '刷新Cookies'},
|
||||
priority=priority,
|
||||
block=True,
|
||||
rule=FullCommand(),
|
||||
)
|
||||
refresh_all_ck = on_command(
|
||||
'刷新全部CK',
|
||||
aliases={'刷新全部ck', '刷新全部Ck', '刷新全部Cookies'},
|
||||
priority=priority,
|
||||
block=True,
|
||||
rule=FullCommand(),
|
||||
permission=SUPERUSER,
|
||||
)
|
||||
bind = on_regex(
|
||||
r'^(绑定|切换|解绑|删除)(uid|UID|mys|MYS)([0-9]+)?$', priority=priority
|
||||
)
|
||||
get_qrcode_login = on_command(
|
||||
'扫码登录',
|
||||
aliases={'扫码登陆', '扫码登入'},
|
||||
permission=DIRECT,
|
||||
rule=FullCommand(),
|
||||
)
|
||||
|
||||
|
||||
@sv.on_fullmatch(('刷新全部CK', '刷新全部ck', '刷新全部Ck', '刷新全部Cookies'))
|
||||
async def send_refresh_allck_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.sender:
|
||||
qid = int(ev.sender['user_id'])
|
||||
else:
|
||||
return
|
||||
if qid not in bot.config.SUPERUSERS:
|
||||
return
|
||||
logger.info('开始执行[刷新全部ck]')
|
||||
@refresh_all_ck.handle()
|
||||
async def send_refresh_all_ck_msg(
|
||||
matcher: Matcher,
|
||||
):
|
||||
logger.info('开始执行[刷新全部CK]')
|
||||
im = await get_ck_by_all_stoken()
|
||||
if isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
if isinstance(im, str):
|
||||
await matcher.finish(im)
|
||||
await matcher.finish(MessageSegment.image(im))
|
||||
|
||||
|
||||
@sv.on_fullmatch(('刷新CK', '刷新ck', '刷新Ck', '刷新Cookies'))
|
||||
async def send_refresh_ck_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
logger.info('开始执行[刷新ck]')
|
||||
if ev.sender:
|
||||
qid = ev.sender['user_id']
|
||||
else:
|
||||
return
|
||||
@refresh_ck.handle()
|
||||
async def send_refresh_ck_msg(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
logger.info('开始执行[刷新CK]')
|
||||
qid = cast_to_int(event.author)
|
||||
im = await get_ck_by_stoken(qid)
|
||||
if isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
if isinstance(im, str):
|
||||
await matcher.finish(im)
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
|
||||
|
||||
@sv.on_fullmatch('绑定信息')
|
||||
async def send_bind_card(bot: HoshinoBot, ev: CQEvent):
|
||||
logger.info('开始执行[查询用户绑定状态]')
|
||||
if ev.sender:
|
||||
qid = ev.sender['user_id']
|
||||
else:
|
||||
return
|
||||
im = await get_user_card(qid)
|
||||
im = await convert_img(im)
|
||||
logger.info('[查询用户绑定状态]完成!等待图片发送中...')
|
||||
await bot.send(ev, im)
|
||||
|
||||
|
||||
@sv.on_fullmatch(('扫码登陆', '扫码登录', '扫码登入'))
|
||||
async def send_qr_card(bot: HoshinoBot, ev: CQEvent):
|
||||
im = await qrcode_login(hoshino_bot, ev.group_id, ev.user_id)
|
||||
@get_qrcode_login.handle()
|
||||
async def send_qrcode_login(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
logger.info('开始执行[扫码登陆]')
|
||||
qid = cast_to_int(event.author)
|
||||
im = await qrcode_login(matcher, qid)
|
||||
if not im:
|
||||
return
|
||||
im = await deal_ck(im, ev.user_id) # type: ignore
|
||||
if isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await bot.send(ev, im)
|
||||
im = await deal_ck(im, qid)
|
||||
if isinstance(im, str):
|
||||
await matcher.finish(im)
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
|
||||
|
||||
@hoshino_bot.on_message('private') # type: ignore
|
||||
async def send_add_ck_msg(ctx):
|
||||
message = ctx['raw_message']
|
||||
sid = int(ctx['self_id'])
|
||||
userid = int(ctx['sender']['user_id'])
|
||||
gid = 0
|
||||
if message.startswith('添加'):
|
||||
message = message.replace('添加', '').replace(' ', '')
|
||||
im = await deal_ck(message, userid) # type: ignore
|
||||
else:
|
||||
return
|
||||
if isinstance(im, bytes):
|
||||
im = await convert_img(im)
|
||||
await hoshino_bot.send_msg(
|
||||
self_id=sid, user_id=userid, group_id=gid, message=im
|
||||
)
|
||||
@bind_info.handle()
|
||||
async def send_bind_card(
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
):
|
||||
logger.info('开始执行[查询用户绑定状态]')
|
||||
qid = cast_to_int(event.author)
|
||||
if qid is None:
|
||||
await matcher.finish('QID为空,请重试!')
|
||||
im = await get_user_card(str(qid))
|
||||
logger.info('[查询用户绑定状态]完成!等待图片发送中...')
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
|
||||
|
||||
@add_cookie.handle()
|
||||
@handle_exception('Cookie', '校验失败!请输入正确的Cookies!')
|
||||
async def send_add_ck_msg(
|
||||
event: MessageEvent, matcher: Matcher, args: Message = CommandArg()
|
||||
):
|
||||
mes = args.extract_plain_text().strip().replace(' ', '')
|
||||
qid = cast_to_int(event.author)
|
||||
if qid is None:
|
||||
await matcher.finish('QID为空,请重试!')
|
||||
qid = str(qid)
|
||||
im = await deal_ck(mes, qid)
|
||||
if isinstance(im, str):
|
||||
await matcher.finish(im)
|
||||
await matcher.finish(MessageSegment.file_image(im))
|
||||
|
||||
|
||||
# 群聊内 绑定uid或者mysid 的命令,会绑定至当前qq号上
|
||||
@sv.on_rex(r'^(绑定|切换|解绑|删除)(uid|UID|mys|MYS)([0-9]+)?$')
|
||||
async def send_link_uid_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
args = ev['match'].groups()
|
||||
@bind.handle()
|
||||
@handle_exception('绑定ID', '绑定ID异常')
|
||||
async def send_link_uid_msg(
|
||||
event: MessageEvent, matcher: Matcher, args: Tuple[Any, ...] = RegexGroup()
|
||||
):
|
||||
logger.info('开始执行[绑定/解绑用户信息]')
|
||||
logger.info('[绑定/解绑]参数: {}'.format(str(args)))
|
||||
if ev.sender:
|
||||
qid = ev.sender['user_id']
|
||||
else:
|
||||
return
|
||||
logger.info('[绑定/解绑]参数: {}'.format(args))
|
||||
qid = cast_to_int(event.author)
|
||||
if qid is None:
|
||||
await matcher.finish('QID为空,请重试!')
|
||||
logger.info('[绑定/解绑]UserID: {}'.format(qid))
|
||||
|
||||
if args[0] in ('绑定'):
|
||||
if args[2] is None:
|
||||
await bot.send(ev, '请输入正确的uid或者mysid!')
|
||||
await matcher.finish('请输入正确的uid或者mysid!')
|
||||
|
||||
if args[1] in ('uid', 'UID'):
|
||||
im = await bind_db(qid, args[2])
|
||||
im = await bind_db(str(qid), args[2])
|
||||
else:
|
||||
im = await bind_db(qid, None, args[2])
|
||||
im = await bind_db(str(qid), None, args[2])
|
||||
elif args[0] in ('切换'):
|
||||
im = await switch_db(qid, args[2])
|
||||
im = await switch_db(str(qid), args[2])
|
||||
else:
|
||||
if args[1] in ('uid', 'UID'):
|
||||
im = await delete_db(qid, {'UID': args[2]})
|
||||
im = await delete_db(str(qid), {'UID': args[2]})
|
||||
else:
|
||||
im = await delete_db(qid, {'MYSID': args[2]})
|
||||
await bot.send(ev, im, at_sender=True)
|
||||
im = await delete_db(str(qid), {'MYSID': args[2]})
|
||||
await matcher.finish(im, at_sender=True)
|
||||
|
||||
|
||||
@sv.on_fullmatch(('绑定ck说明', 'ck帮助', '绑定ck'))
|
||||
async def send_ck_msg(bot: HoshinoBot, ev: CQEvent):
|
||||
@get_ck_msg.handle()
|
||||
async def send_ck_help(matcher: Matcher):
|
||||
msg_list = await get_ck_help()
|
||||
forward_msg = []
|
||||
for msg in msg_list:
|
||||
forward_msg.append(
|
||||
{
|
||||
"type": "node",
|
||||
"data": {"name": "小冰", "uin": "2854196306", "content": msg},
|
||||
}
|
||||
)
|
||||
await bot.send_group_forward_msg(
|
||||
group_id=ev.group_id, messages=forward_msg
|
||||
)
|
||||
|
||||
|
||||
@sv.on_prefix(("gsrc", "原神充值"))
|
||||
async def topup(bot: HoshinoBot, ev: CQEvent):
|
||||
qid = ev.user_id
|
||||
goods_id = ev.message.extract_plain_text()
|
||||
if goods_id == "":
|
||||
goods_id = 0
|
||||
else:
|
||||
goods_id = int(goods_id)
|
||||
group_id = ev.group_id
|
||||
await topup_(bot, qid, group_id, goods_id)
|
||||
await matcher.send(msg)
|
||||
await asyncio.sleep(0.5)
|
||||
|
@ -29,7 +29,7 @@ gs_font_15 = genshin_font_origin(15)
|
||||
gs_font_26 = genshin_font_origin(26)
|
||||
|
||||
|
||||
async def get_user_card(qid: int) -> bytes:
|
||||
async def get_user_card(qid: str) -> bytes:
|
||||
uid_list: List = await select_db(qid, 'list') # type: ignore
|
||||
w, h = 500, len(uid_list) * 210 + 330
|
||||
img = await get_simple_bg(w, h)
|
||||
@ -38,7 +38,7 @@ async def get_user_card(qid: int) -> bytes:
|
||||
uid_title = Image.open(TEXT_PATH / 'uid_title.png')
|
||||
uid_title_draw = ImageDraw.Draw(uid_title)
|
||||
uid_title_draw.text(
|
||||
(47, 70), f'QQ号{str(qid)}', (106, 100, 89), font=gs_font_26
|
||||
(47, 70), f'频道ID {str(qid)}', (106, 100, 89), font=gs_font_26
|
||||
)
|
||||
img.paste(uid_title, (0, 50), uid_title)
|
||||
img.paste(uid_hint, (0, 145 + len(uid_list) * 210), uid_hint)
|
||||
|
@ -7,16 +7,15 @@ from typing import Any, Tuple, Union, Literal
|
||||
|
||||
import qrcode
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from qrcode.constants import ERROR_CORRECT_L
|
||||
from nonebot.adapters.qqguild import MessageSegment
|
||||
|
||||
from ..utils.message.send_msg import send_forward_msg
|
||||
from ..utils.db_operation.db_operation import select_db
|
||||
from ..utils.mhy_api.get_mhy_data import (
|
||||
check_qrcode,
|
||||
get_cookie_token,
|
||||
create_qrcode_url,
|
||||
get_mihoyo_bbs_info,
|
||||
get_stoken_by_game_token,
|
||||
get_cookie_token_by_stoken,
|
||||
)
|
||||
|
||||
disnote = '''免责声明:您将通过扫码完成获取米游社sk以及ck。
|
||||
@ -30,15 +29,15 @@ disnote = '''免责声明:您将通过扫码完成获取米游社sk以及ck。
|
||||
def get_qrcode_base64(url):
|
||||
qr = qrcode.QRCode(
|
||||
version=1,
|
||||
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
||||
error_correction=ERROR_CORRECT_L,
|
||||
box_size=10,
|
||||
border=4,
|
||||
)
|
||||
qr.add_data(url)
|
||||
qr.make(fit=True)
|
||||
img = qr.make_image(fill_color="black", back_color="white")
|
||||
img = qr.make_image(fill_color='black', back_color='white')
|
||||
img_byte = io.BytesIO()
|
||||
img.save(img_byte, format="PNG")
|
||||
img.save(img_byte, format='PNG') # type: ignore
|
||||
img_byte = img_byte.getvalue()
|
||||
return base64.b64encode(img_byte).decode()
|
||||
|
||||
@ -50,80 +49,43 @@ async def refresh(
|
||||
while True:
|
||||
await asyncio.sleep(2)
|
||||
status_data = await check_qrcode(
|
||||
code_data["app_id"], code_data["ticket"], code_data["device"]
|
||||
code_data['app_id'], code_data['ticket'], code_data['device']
|
||||
)
|
||||
if status_data["retcode"] != 0:
|
||||
logger.warn("二维码已过期")
|
||||
if status_data['retcode'] != 0:
|
||||
logger.warning('二维码已过期')
|
||||
return False, None
|
||||
if status_data["data"]["stat"] == "Scanned":
|
||||
if status_data['data']['stat'] == 'Scanned':
|
||||
if not scanned:
|
||||
logger.info("二维码已扫描")
|
||||
logger.info('二维码已扫描')
|
||||
scanned = True
|
||||
continue
|
||||
if status_data["data"]["stat"] == "Confirmed":
|
||||
logger.info("二维码已确认")
|
||||
# print(status_data["data"]["payload"]["raw"])
|
||||
if status_data['data']['stat'] == 'Confirmed':
|
||||
logger.info('二维码已确认')
|
||||
# print(status_data['data']['payload']['raw'])
|
||||
break
|
||||
return True, json.loads(status_data["data"]["payload"]["raw"])
|
||||
return True, json.loads(status_data['data']['payload']['raw'])
|
||||
|
||||
|
||||
async def qrcode_login(bot, group_id, user_id) -> str:
|
||||
async def send_group_msg(msg: str):
|
||||
await bot.call_action(
|
||||
action='send_group_msg',
|
||||
group_id=group_id,
|
||||
message=msg,
|
||||
)
|
||||
return ""
|
||||
|
||||
async def qrcode_login(matcher: Matcher, user_id) -> str:
|
||||
code_data = await create_qrcode_url()
|
||||
try:
|
||||
im = []
|
||||
qrc = f'[CQ:image,file=base64://{get_qrcode_base64(code_data["url"])}]'
|
||||
im.append('请使用米游社扫描下方二维码登录:')
|
||||
im.append(qrc)
|
||||
im.append(disnote)
|
||||
await send_forward_msg(bot, group_id, "扫码小助手", str(user_id), im)
|
||||
except Exception:
|
||||
logger.warn(f"[扫码登录] {group_id} 图片发送失败")
|
||||
await matcher.send(
|
||||
MessageSegment.file_image(get_qrcode_base64(code_data["url"])) # type: ignore
|
||||
)
|
||||
await matcher.send('请绑定UID之后使用米游社扫描上方二维码登录')
|
||||
await matcher.send(disnote)
|
||||
except Exception as e:
|
||||
logger.debug(e)
|
||||
logger.warning('[扫码登录] {user_id} 图片发送失败')
|
||||
status, game_token_data = await refresh(code_data)
|
||||
if status:
|
||||
assert game_token_data is not None # 骗过 pyright
|
||||
logger.info("game_token获取成功")
|
||||
logger.info('game_token获取成功')
|
||||
cookie_token = await get_cookie_token(**game_token_data)
|
||||
stoken_data = await get_stoken_by_game_token(
|
||||
account_id=int(game_token_data["uid"]),
|
||||
game_token=game_token_data["token"],
|
||||
account_id=int(game_token_data['uid']),
|
||||
game_token=game_token_data['token'],
|
||||
)
|
||||
account_id = game_token_data['uid']
|
||||
stoken = stoken_data['data']['token']['token']
|
||||
mid = stoken_data['data']['user_info']['mid']
|
||||
app_cookie = f'stuid={account_id};stoken={stoken};mid={mid}'
|
||||
ck = await get_cookie_token_by_stoken(stoken, account_id, app_cookie)
|
||||
ck = ck['data']['cookie_token']
|
||||
cookie_check = f'account_id={account_id};cookie_token={ck}'
|
||||
get_uid = await get_mihoyo_bbs_info(account_id, cookie_check)
|
||||
# 剔除除了原神之外的其他游戏
|
||||
im = None
|
||||
if get_uid:
|
||||
for i in get_uid['data']['list']:
|
||||
if i['game_id'] == 2:
|
||||
uid_check = i['game_role_id']
|
||||
break
|
||||
else:
|
||||
im = f'你的米游社账号{account_id}尚未绑定原神账号,请前往米游社操作!'
|
||||
return await send_group_msg(im)
|
||||
else:
|
||||
im = '请求失败, 请稍后再试...'
|
||||
return await send_group_msg(im)
|
||||
uid_bind = await select_db(user_id, mode='uid')
|
||||
# 没有在gsuid绑定uid的情况
|
||||
if uid_bind == "未找到绑定的UID~":
|
||||
logger.warning('game_token获取失败')
|
||||
im = '你还没有绑定uid,请输入[绑定uid123456]绑定你的uid,再发送[扫码登录]进行绑定'
|
||||
return await send_group_msg(im)
|
||||
# 比对gsuid数据库和扫码登陆获取到的uid
|
||||
if str(uid_bind) == uid_check or str(uid_bind) == account_id:
|
||||
return SimpleCookie(
|
||||
{
|
||||
'stoken_v2': stoken_data['data']['token']['token'],
|
||||
@ -134,8 +96,5 @@ async def qrcode_login(bot, group_id, user_id) -> str:
|
||||
).output(header='', sep=';')
|
||||
else:
|
||||
logger.warning('game_token获取失败')
|
||||
im = 'game_token获取失败:被非绑定指定uid用户扫取,取消绑定,请重新发送[扫码登录]登录账号'
|
||||
else:
|
||||
logger.warning('game_token获取失败')
|
||||
im = 'game_token获取失败:二维码已过期'
|
||||
return await send_group_msg(im)
|
||||
await matcher.send('game_token获取失败:二维码已过期')
|
||||
return ''
|
||||
|
@ -1,92 +0,0 @@
|
||||
import io
|
||||
import base64
|
||||
import asyncio
|
||||
import traceback
|
||||
|
||||
import qrcode
|
||||
from nonebot.log import logger
|
||||
|
||||
from ..utils.message.send_msg import send_forward_msg
|
||||
from ..utils.db_operation.db_operation import select_db
|
||||
from ..utils.mhy_api.get_mhy_data import topup, checkorder, fetchgoods
|
||||
|
||||
disnote = '''免责声明:
|
||||
该充值接口由米游社提供,不对充值结果负责。
|
||||
请在充值前仔细阅读米哈游的充值条款。
|
||||
'''
|
||||
|
||||
|
||||
def get_qrcode_base64(url):
|
||||
qr = qrcode.QRCode(
|
||||
version=1,
|
||||
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
||||
box_size=10,
|
||||
border=4,
|
||||
)
|
||||
qr.add_data(url)
|
||||
qr.make(fit=True)
|
||||
img = qr.make_image(fill_color="black", back_color="white")
|
||||
img_byte = io.BytesIO()
|
||||
img.save(img_byte, format="PNG")
|
||||
img_byte = img_byte.getvalue()
|
||||
return base64.b64encode(img_byte).decode()
|
||||
|
||||
|
||||
async def refresh(order, uid):
|
||||
times = 0
|
||||
while True:
|
||||
await asyncio.sleep(5)
|
||||
order_status = await checkorder(order, uid)
|
||||
if order_status != 900:
|
||||
pass
|
||||
else:
|
||||
return "支付成功"
|
||||
times += 1
|
||||
if times > 60:
|
||||
return "支付超时"
|
||||
|
||||
|
||||
async def topup_(bot, qid, group_id, goods_id):
|
||||
async def send_group_msg(msg: str):
|
||||
await bot.call_action(
|
||||
action='send_group_msg',
|
||||
group_id=group_id,
|
||||
message=msg,
|
||||
)
|
||||
return ""
|
||||
|
||||
uid = await select_db(qid, mode="uid")
|
||||
if uid is None:
|
||||
await send_group_msg("未绑定米游社账号")
|
||||
return
|
||||
fetchgoods_data = await fetchgoods()
|
||||
try:
|
||||
goods_data = fetchgoods_data[goods_id]
|
||||
except Exception:
|
||||
await send_group_msg("商品不存在,最大为" + str(len(fetchgoods_data) - 1))
|
||||
return
|
||||
try:
|
||||
order = await topup(uid, goods_data)
|
||||
except Exception:
|
||||
await send_group_msg("出错了,可能是cookie过期或接口出错")
|
||||
logger.warn(f"[充值] {group_id} {qid}")
|
||||
return
|
||||
try:
|
||||
im = []
|
||||
b64_data = get_qrcode_base64(order["encode_order"])
|
||||
qrc = f'[CQ:image,file=base64://{b64_data}]'
|
||||
im.append(f"充值uid:{uid}")
|
||||
im.append(
|
||||
f"商品名称:{goods_data['goods_name']}×{str(goods_data['goods_unit'])}"
|
||||
if int(goods_data['goods_unit']) > 0
|
||||
else goods_data["goods_name"],
|
||||
)
|
||||
im.append(f'商品价格:{int(order["amount"])/100}')
|
||||
im.append(f"订单号:{order['order_no']}")
|
||||
im.append(disnote)
|
||||
im.append(qrc)
|
||||
await send_forward_msg(bot, group_id, "小助手", str(qid), im)
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
logger.warn(f"[充值] {group_id} 图片发送失败")
|
||||
await send_group_msg(await refresh(order, uid))
|
@ -1,10 +1,11 @@
|
||||
from sqlmodel import SQLModel
|
||||
from nonebot import get_driver
|
||||
from nonebot.log import logger
|
||||
from nonebot import get_bot, on_startup
|
||||
|
||||
from ..utils.db_operation.db_operation import config_check
|
||||
|
||||
config = get_bot().config
|
||||
driver = get_driver()
|
||||
config = driver.config
|
||||
|
||||
|
||||
async def run_webconsole():
|
||||
@ -16,22 +17,28 @@ async def run_webconsole():
|
||||
user_auth_i18n.set_language('zh_CN')
|
||||
|
||||
# 导入app
|
||||
try:
|
||||
from .mount_app import auth, site
|
||||
except RuntimeError:
|
||||
logger.warning("当前 Driver 非 ReverseDriver,WebConsole 已禁用")
|
||||
return
|
||||
|
||||
logger.info('尝试挂载WebConsole')
|
||||
|
||||
await site.db.async_run_sync(
|
||||
SQLModel.metadata.create_all, is_session=False # type: ignore
|
||||
)
|
||||
# 创建默认测试用户, 请及时修改密码!!!
|
||||
await auth.create_role_user()
|
||||
|
||||
logger.info(
|
||||
('WebConsole挂载成功:' f'http://{config.HOST}:{config.PORT}/genshinuid')
|
||||
logger.opt(colors=True).info(
|
||||
(
|
||||
'WebConsole挂载成功:'
|
||||
f'<blue>http://{config.host}:{config.port}/genshinuid</blue>'
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@on_startup
|
||||
@driver.on_startup
|
||||
async def start_check():
|
||||
if await config_check('OpenWeb'):
|
||||
await run_webconsole()
|
||||
|
@ -1,5 +1,6 @@
|
||||
import fastapi_amis_admin
|
||||
from fastapi import Request
|
||||
from nonebot.typing import overrides
|
||||
from fastapi_user_auth import admin as user_auth_admin
|
||||
from fastapi_amis_admin.admin import admin as amis_admin
|
||||
from fastapi_amis_admin.utils.translation import i18n as _
|
||||
@ -17,7 +18,6 @@ from fastapi_amis_admin.amis.components import (
|
||||
ButtonToolbar,
|
||||
)
|
||||
|
||||
from .nb2 import overrides
|
||||
from ..version import GenshinUID_version
|
||||
|
||||
login_html = '''
|
||||
@ -64,7 +64,6 @@ footer_html = f'''
|
||||
</p>
|
||||
'''
|
||||
|
||||
|
||||
# 还原高版本的注册按钮丢失
|
||||
@overrides(user_auth_admin.UserLoginFormAdmin)
|
||||
async def get_form(self, request: Request) -> Form:
|
||||
@ -109,7 +108,7 @@ def attach_page_head(page: Page) -> Page:
|
||||
Html(html=login_html),
|
||||
Grid(
|
||||
columns=[
|
||||
{'body': [page.body], 'lg': 2, 'md': 4, 'valign': 'middle'}
|
||||
{'body': [page.body], 'lg': 3, 'md': 4, 'valign': 'middle'}
|
||||
],
|
||||
align='center',
|
||||
valign='middle',
|
||||
|
@ -1,15 +1,24 @@
|
||||
# flake8: noqa
|
||||
import platform
|
||||
import contextlib
|
||||
from pathlib import Path
|
||||
from typing import Any, Set, Dict, List, Callable
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Any,
|
||||
Set,
|
||||
List,
|
||||
Union,
|
||||
Callable,
|
||||
Optional,
|
||||
cast,
|
||||
)
|
||||
|
||||
from quart import Quart
|
||||
from nonebot import get_bot
|
||||
import fastapi_amis_admin
|
||||
from pydantic import BaseModel
|
||||
from sqlmodel import Relationship
|
||||
from sqlalchemy.orm import backref
|
||||
from fastapi import FastAPI, Request
|
||||
import fastapi_amis_admin # noqa: F401
|
||||
from nonebot import get_app, get_driver
|
||||
from fastapi_amis_admin import amis, admin
|
||||
from fastapi_amis_admin.crud import BaseApiOut
|
||||
from sqlalchemy.ext.asyncio import AsyncEngine
|
||||
@ -40,8 +49,8 @@ from fastapi_amis_admin.amis.components import (
|
||||
|
||||
from ..version import GenshinUID_version
|
||||
from ..genshinuid_user.add_ck import _deal_ck
|
||||
from .login_page import amis_admin, user_auth_admin # noqa
|
||||
from ..utils.db_operation.database.db_config import DATABASE_URL
|
||||
from .login_page import amis_admin, user_auth_admin # noqa # 不要删
|
||||
from ..utils.db_operation.database.models import (
|
||||
Config,
|
||||
UidData,
|
||||
@ -50,21 +59,32 @@ from ..utils.db_operation.database.models import (
|
||||
NewCookiesTable,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from quart import Quart
|
||||
from asgiref.typing import Scope, HTTPScope, WebSocketScope
|
||||
|
||||
AppType = Union[FastAPI, 'Quart']
|
||||
|
||||
|
||||
class FastApiMiddleware:
|
||||
def __init__(self, app: Quart, fastapi: FastAPI, routes: Set[str]) -> None:
|
||||
def __init__(
|
||||
self, app: 'Quart', fastapi: FastAPI, routes: Set[str]
|
||||
) -> None:
|
||||
self.fastapi = fastapi
|
||||
self.app = app.asgi_app
|
||||
self.routes = routes
|
||||
|
||||
async def __call__(
|
||||
self, scope: Dict[str, Any], receive: Callable, send: Callable
|
||||
self, scope: 'Scope', receive: Callable, send: Callable
|
||||
) -> None:
|
||||
if scope['type'] in ('http', 'websocket'):
|
||||
scope = cast(Union['HTTPScope', 'WebSocketScope'], scope)
|
||||
for path in self.routes:
|
||||
if scope['path'].startswith(path):
|
||||
return await self.fastapi(scope, receive, send)
|
||||
return await self.app(scope, receive, send)
|
||||
return await self.fastapi(
|
||||
scope, receive, send # type: ignore
|
||||
)
|
||||
return await self.app(scope, receive, send) # type: ignore
|
||||
|
||||
|
||||
# 自定义后台管理站点
|
||||
@ -89,8 +109,28 @@ class GenshinUIDAdminSite(AuthAdminSite):
|
||||
return app
|
||||
|
||||
|
||||
# 创建FastAPI应用
|
||||
app = FastAPI()
|
||||
def get_asgi() -> Optional[AppType]:
|
||||
try:
|
||||
return get_app()
|
||||
except AssertionError:
|
||||
return None
|
||||
|
||||
|
||||
# 从 nb 获取 FastAPI
|
||||
app = get_asgi()
|
||||
if app is None:
|
||||
raise RuntimeError('App is not ReverseDriver')
|
||||
|
||||
with contextlib.suppress(ImportError):
|
||||
from quart import Quart # noqa: F811
|
||||
|
||||
if isinstance(app, Quart):
|
||||
fastapi = FastAPI()
|
||||
app.asgi_app = FastApiMiddleware(app, fastapi, {'/genshinuid'}) # type: ignore
|
||||
app = fastapi
|
||||
|
||||
|
||||
app = cast(FastAPI, app)
|
||||
settings = Settings(
|
||||
database_url_async=DATABASE_URL,
|
||||
database_url='',
|
||||
@ -99,8 +139,6 @@ settings = Settings(
|
||||
site_title='GenshinUID网页控制台',
|
||||
language='zh_CN',
|
||||
)
|
||||
quart = get_bot().server_app
|
||||
quart.asgi_app = FastApiMiddleware(quart, app, {'/genshinuid'}) # type: ignore
|
||||
|
||||
|
||||
# 显示主键
|
||||
@ -152,16 +190,13 @@ admin.BaseModelAdmin.get_create_form = patched_get_create_form
|
||||
# 创建AdminSite实例
|
||||
site = GenshinUIDAdminSite(settings)
|
||||
auth = site.auth
|
||||
config = get_bot().config
|
||||
|
||||
if float(fastapi_amis_admin.__version__[:3]) >= 0.3:
|
||||
|
||||
class MyUser(User, table=True):
|
||||
point: float = Field(default=0, title=_('Point')) # type: ignore
|
||||
phone: str = Field(None, title=_('Tel'), max_length=15) # type: ignore
|
||||
parent_id: int = Field(
|
||||
None, title=_('Parent'), foreign_key='auth_user.id' # type: ignore
|
||||
)
|
||||
parent_id: int = Field(None, title=_('Parent'), foreign_key='auth_user.id') # type: ignore
|
||||
children: List['User'] = Relationship(
|
||||
sa_relationship_kwargs=dict(
|
||||
backref=backref('parent', remote_side='User.id'),
|
||||
@ -170,9 +205,10 @@ if float(fastapi_amis_admin.__version__[:3]) >= 0.3:
|
||||
|
||||
auth.user_model = MyUser
|
||||
|
||||
config = get_driver().config
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=[f'http://{config.HOST}:{config.PORT}/genshinuid'],
|
||||
allow_origins=[f'http://{config.host}:{config.port}'],
|
||||
allow_credentials=True,
|
||||
allow_methods=['*'],
|
||||
allow_headers=['*'],
|
||||
@ -180,12 +216,17 @@ app.add_middleware(
|
||||
|
||||
gsuid_webconsole_help = '''
|
||||
## 初次使用
|
||||
|
||||
欢迎进入网页控制台!
|
||||
|
||||
Admin账户可以通过左侧的选项进入不同的数据库直接修改,**首次登陆的Admin账户别忘了修改你的密码!**
|
||||
|
||||
普通账户可以通过左侧的选项进行绑定CK或者SK
|
||||
|
||||
未来还会加入更多功能!
|
||||
|
||||
## 丨我该如何获取Cookies?[#92](https://github.com/KimigaiiWuyi/GenshinUID/issues/92)([@RemKeeper](https://github.com/RemKeeper))
|
||||
|
||||
```js
|
||||
var cookie = document.cookie;
|
||||
var Str_Num = cookie.indexOf('_MHYUUID=');
|
||||
@ -198,12 +239,16 @@ if (ask == true) {
|
||||
msg = 'Cancel'
|
||||
}
|
||||
```
|
||||
|
||||
1. 复制上面全部代码,然后打开[米游社BBS](https://bbs.mihoyo.com/ys/)
|
||||
2. 在页面上右键检查或者Ctrl+Shift+i
|
||||
3. 选择控制台(Console),粘贴,回车,在弹出的窗口点确认(点完自动复制)
|
||||
4. 然后在和机器人的私聊窗口,粘贴发送即可
|
||||
|
||||
**警告:Cookies属于个人隐私,其效用相当于账号密码,请勿随意公开!**
|
||||
|
||||
## 丨获取米游社Stoken([AutoMihoyoBBS](https://github.com/Womsxd/AutoMihoyoBBS#%E8%8E%B7%E5%8F%96%E7%B1%B3%E6%B8%B8%E7%A4%BECookie))
|
||||
|
||||
```js
|
||||
var cookie = document.cookie;
|
||||
var ask = confirm('Cookie:' + cookie + '按确认,然后粘贴至Cookies或者Login_ticket选框内');
|
||||
@ -214,10 +259,12 @@ if (ask == true) {
|
||||
msg = 'Cancel'
|
||||
}
|
||||
```
|
||||
|
||||
1. 复制上面全部代码,然后打开[米游社账户登录界面](http://user.mihoyo.com/)
|
||||
2. 在页面上右键检查或者Ctrl+Shift+i
|
||||
3. 选择控制台(Console),粘贴,回车,在弹出的窗口点确认(点完自动复制)
|
||||
4. 然后在和机器人的私聊窗口,粘贴发送即可
|
||||
|
||||
**警告:Cookies属于个人隐私,其效用相当于账号密码,请勿随意公开!**
|
||||
|
||||
## 获取CK通则
|
||||
|
@ -1,15 +0,0 @@
|
||||
from typing import TypeVar, Callable
|
||||
|
||||
T_Wrapped = TypeVar("T_Wrapped", bound=Callable)
|
||||
|
||||
|
||||
def overrides(InterfaceClass: object) -> Callable[[T_Wrapped], T_Wrapped]:
|
||||
"""标记一个方法为父类 interface 的 implement"""
|
||||
|
||||
def overrider(func: T_Wrapped) -> T_Wrapped:
|
||||
assert func.__name__ in dir(
|
||||
InterfaceClass
|
||||
), f"Error method: {func.__name__}"
|
||||
return func
|
||||
|
||||
return overrider
|
@ -1,9 +1,12 @@
|
||||
import re
|
||||
|
||||
from nonebot import MessageSegment
|
||||
from hoshino.typing import CQEvent, HoshinoBot
|
||||
from nonebot import on_command
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.params import CommandArg
|
||||
from nonebot.adapters.qqguild import Bot, Message, MessageEvent
|
||||
|
||||
from ..base import sv
|
||||
from ..config import priority
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
from .get_wiki_text import (
|
||||
char_wiki,
|
||||
audio_wiki,
|
||||
@ -13,149 +16,126 @@ from .get_wiki_text import (
|
||||
artifacts_wiki,
|
||||
)
|
||||
|
||||
get_weapon = on_command('武器', priority=priority)
|
||||
get_char = on_command('角色', priority=priority)
|
||||
get_cost = on_command('材料', priority=priority)
|
||||
get_polar = on_command('命座', priority=priority)
|
||||
get_talents = on_command('天赋', priority=priority)
|
||||
get_enemies = on_command('原魔', priority=priority)
|
||||
# get_audio = on_command('语音', priority=priority)
|
||||
get_artifacts = on_command('圣遗物', priority=priority)
|
||||
get_food = on_command('食物', priority=priority)
|
||||
|
||||
@sv.on_prefix('语音')
|
||||
async def send_audio(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
message = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
return
|
||||
if message == '':
|
||||
return
|
||||
|
||||
'''频道无法使用语音相关
|
||||
@get_audio.handle()
|
||||
@handle_exception('语音', '语音发送失败,可能是FFmpeg环境未配置。')
|
||||
async def send_audio(matcher: Matcher, args: Message = CommandArg()):
|
||||
message = args.extract_plain_text().strip().replace(' ', '')
|
||||
name = ''.join(re.findall('[\u4e00-\u9fa5]', message))
|
||||
im = await audio_wiki(name, message)
|
||||
if name == '列表':
|
||||
await bot.send(ev, MessageSegment.image(im))
|
||||
await matcher.finish(MessageSegment.image(im))
|
||||
else:
|
||||
if isinstance(im, str):
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
else:
|
||||
await bot.send(ev, MessageSegment.record(im))
|
||||
await matcher.finish(MessageSegment.record(im))
|
||||
'''
|
||||
|
||||
|
||||
@sv.on_prefix('原魔')
|
||||
async def send_enemies(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
message = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
return
|
||||
if message == '':
|
||||
return
|
||||
|
||||
@get_enemies.handle()
|
||||
@handle_exception('怪物')
|
||||
async def send_enemies(matcher: Matcher, args: Message = CommandArg()):
|
||||
message = args.extract_plain_text().strip().replace(' ', '')
|
||||
im = await enemies_wiki(message)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
||||
|
||||
@sv.on_prefix('食物')
|
||||
async def send_food(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
message = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
return
|
||||
if message == '':
|
||||
return
|
||||
|
||||
@get_food.handle()
|
||||
@handle_exception('食物')
|
||||
async def send_food(matcher: Matcher, args: Message = CommandArg()):
|
||||
message = args.extract_plain_text().strip().replace(' ', '')
|
||||
im = await foods_wiki(message)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
||||
|
||||
@sv.on_prefix('圣遗物')
|
||||
async def send_artifacts(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
message = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
return
|
||||
if message == '':
|
||||
return
|
||||
|
||||
@get_artifacts.handle()
|
||||
@handle_exception('圣遗物')
|
||||
async def send_artifacts(matcher: Matcher, args: Message = CommandArg()):
|
||||
message = args.extract_plain_text().strip().replace(' ', '')
|
||||
im = await artifacts_wiki(message)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
||||
|
||||
@sv.on_prefix('武器')
|
||||
async def send_weapon(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
message = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
return
|
||||
if message == '':
|
||||
return
|
||||
|
||||
@get_weapon.handle()
|
||||
@handle_exception('武器')
|
||||
async def send_weapon(matcher: Matcher, args: Message = CommandArg()):
|
||||
message = args.extract_plain_text().strip().replace(' ', '')
|
||||
name = ''.join(re.findall('[\u4e00-\u9fa5]', message))
|
||||
level = re.findall(r'\d+', message)
|
||||
if len(level) == 1:
|
||||
im = await weapon_wiki(name, level=level[0])
|
||||
else:
|
||||
im = await weapon_wiki(name)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
||||
|
||||
@sv.on_prefix('天赋')
|
||||
async def send_talents(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
message = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
return
|
||||
if message == '':
|
||||
return
|
||||
|
||||
'''频道无法发送合并转发消息
|
||||
@get_talents.handle()
|
||||
@handle_exception('天赋')
|
||||
async def send_talents(
|
||||
bot: Bot,
|
||||
event: MessageEvent,
|
||||
matcher: Matcher,
|
||||
args: Message = CommandArg(),
|
||||
):
|
||||
message = args.extract_plain_text().strip().replace(' ', '')
|
||||
name = ''.join(re.findall('[\u4e00-\u9fa5]', message))
|
||||
num = re.findall(r'\d+', message)
|
||||
if len(num) == 1:
|
||||
im = await char_wiki(name, 'talents', num[0])
|
||||
if isinstance(im, list):
|
||||
await bot.send_group_forward_msg(group_id=ev.group_id, messages=im)
|
||||
await bot.call_api(
|
||||
'send_group_forward_msg', group_id=event.group_id, messages=im
|
||||
)
|
||||
await matcher.finish()
|
||||
return
|
||||
else:
|
||||
im = '参数不正确。'
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
'''
|
||||
|
||||
|
||||
@sv.on_prefix('角色')
|
||||
async def send_char(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
message = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
return
|
||||
if message == '':
|
||||
return
|
||||
|
||||
@get_char.handle()
|
||||
@handle_exception('角色')
|
||||
async def send_char(matcher: Matcher, args: Message = CommandArg()):
|
||||
message = args.extract_plain_text().strip().replace(' ', '')
|
||||
name = ''.join(re.findall('[\u4e00-\u9fa5]', message))
|
||||
level = re.findall(r'\d+', message)
|
||||
if len(level) == 1:
|
||||
im = await char_wiki(name, 'char', level=level[0])
|
||||
else:
|
||||
im = await char_wiki(name)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
||||
|
||||
@sv.on_prefix('材料')
|
||||
async def send_cost(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
message = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
return
|
||||
if message == '':
|
||||
return
|
||||
|
||||
@get_cost.handle()
|
||||
@handle_exception('材料')
|
||||
async def send_cost(matcher: Matcher, args: Message = CommandArg()):
|
||||
message = args.extract_plain_text().strip().replace(' ', '')
|
||||
im = await char_wiki(message, 'costs')
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
||||
|
||||
@sv.on_prefix('命座')
|
||||
async def send_polar(bot: HoshinoBot, ev: CQEvent):
|
||||
if ev.message:
|
||||
message = ev.message.extract_plain_text().replace(' ', '')
|
||||
else:
|
||||
return
|
||||
if message == '':
|
||||
return
|
||||
|
||||
@get_polar.handle()
|
||||
@handle_exception('命座')
|
||||
async def send_polar(matcher: Matcher, args: Message = CommandArg()):
|
||||
message = args.extract_plain_text().strip().replace(' ', '')
|
||||
num = int(re.findall(r'\d+', message)[0]) # str
|
||||
m = ''.join(re.findall('[\u4e00-\u9fa5]', message))
|
||||
if num <= 0 or num > 6:
|
||||
await bot.send(ev, '你家{}有{}命?'.format(m, num))
|
||||
await get_polar.finish('你家{}有{}命?'.format(m, num))
|
||||
return
|
||||
im = await char_wiki(m, 'constellations', num)
|
||||
await bot.send(ev, im)
|
||||
await matcher.finish(im)
|
||||
|
@ -2,22 +2,33 @@ import random
|
||||
import asyncio
|
||||
import threading
|
||||
|
||||
from ..base import sv, logger
|
||||
from nonebot import on_command
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot_plugin_apscheduler import scheduler
|
||||
from nonebot.adapters.qqguild import MessageSegment
|
||||
|
||||
from .draw_abyss_total import TOTAL_IMG, draw_xk_abyss_img
|
||||
from ..utils.draw_image_tools.send_image_tool import convert_img
|
||||
from ..utils.exception.handle_exception import handle_exception
|
||||
|
||||
draw_total_scheduler = scheduler
|
||||
get_abyss_total = on_command('深渊概览', aliases={'深渊统计', '深渊使用率'})
|
||||
|
||||
|
||||
@sv.scheduled_job('interval', hours=3)
|
||||
@draw_total_scheduler.scheduled_job('interval', hours=3)
|
||||
async def scheduled_draw_abyss():
|
||||
await asyncio.sleep(random.randint(0, 60))
|
||||
await draw_xk_abyss_img()
|
||||
|
||||
|
||||
@sv.on_fullmatch(('深渊概览', '深渊统计', '深渊使用率'))
|
||||
async def send_abyss_pic(bot, ev):
|
||||
img = await convert_img(TOTAL_IMG)
|
||||
logger.info('获得gs帮助图片成功!')
|
||||
await bot.send(ev, img)
|
||||
@get_abyss_total.handle()
|
||||
@handle_exception('深渊概览')
|
||||
async def send_guide_pic(matcher: Matcher):
|
||||
if TOTAL_IMG.exists():
|
||||
logger.info('获得深渊概览成功!')
|
||||
await matcher.finish(MessageSegment.file_image(TOTAL_IMG))
|
||||
else:
|
||||
await matcher.finish('深渊概览图不存在!')
|
||||
|
||||
|
||||
threading.Thread(
|
||||
|
@ -17,10 +17,7 @@ path = Path(__file__).parents[1] / 'genshinuid_adv'
|
||||
wb = load_workbook(str(path / 'Genshin All Char.xlsx'))
|
||||
ws = wb.active
|
||||
for char_i in range(2, 336, 5): # 角色行
|
||||
char = ws.cell(char_i, 1).value
|
||||
if not isinstance(char, str):
|
||||
continue
|
||||
char_name = char.replace('\n', '')
|
||||
char_name = ws.cell(char_i, 1).value.replace('\n', '') # type: ignore
|
||||
char_sample = copy.deepcopy(sample)
|
||||
for i in range(5):
|
||||
row = i + char_i
|
||||
|
@ -251,7 +251,7 @@ class CookiesDAL:
|
||||
await self.db_session.flush()
|
||||
return True
|
||||
|
||||
async def add_cookie_db(self, userid: int, uid: str, cookies: str) -> bool:
|
||||
async def add_cookie_db(self, userid: str, uid: str, cookies: str) -> bool:
|
||||
"""
|
||||
:说明:
|
||||
绑定Cookies
|
||||
|
@ -11,7 +11,7 @@ class UidDataDAL:
|
||||
def __init__(self, db_session: Session):
|
||||
self.db_session = db_session
|
||||
|
||||
async def get_user_data(self, userid: int) -> Optional[UidData]:
|
||||
async def get_user_data(self, userid: str) -> Optional[UidData]:
|
||||
"""
|
||||
:说明:
|
||||
获取用户的绑定信息
|
||||
@ -37,7 +37,7 @@ class UidDataDAL:
|
||||
bind_list.append(item.__dict__)
|
||||
return bind_list
|
||||
|
||||
async def user_exists(self, userid: int) -> bool:
|
||||
async def user_exists(self, userid: str) -> bool:
|
||||
"""
|
||||
:说明:
|
||||
是否存在用户的绑定信息
|
||||
@ -67,7 +67,7 @@ class UidDataDAL:
|
||||
uid_list.extend(item.UID.split("_"))
|
||||
return uid_list
|
||||
|
||||
async def get_uid_list(self, userid: int) -> List[str]:
|
||||
async def get_uid_list(self, userid: str) -> List[str]:
|
||||
"""
|
||||
:说明:
|
||||
获得用户的绑定UID列表
|
||||
@ -83,7 +83,7 @@ class UidDataDAL:
|
||||
return uid_list
|
||||
return []
|
||||
|
||||
async def get_uid(self, userid: int) -> str:
|
||||
async def get_uid(self, userid: str) -> str:
|
||||
"""
|
||||
:说明:
|
||||
获得用户绑定的UID
|
||||
@ -98,7 +98,7 @@ class UidDataDAL:
|
||||
else:
|
||||
return '未找到绑定的UID~'
|
||||
|
||||
async def switch_uid(self, userid: int, uid: Optional[str] = None) -> str:
|
||||
async def switch_uid(self, userid: str, uid: Optional[str] = None) -> str:
|
||||
"""
|
||||
:说明:
|
||||
切换绑定的UID列表,绑定一个UID的情况下返回无法切换
|
||||
@ -126,7 +126,7 @@ class UidDataDAL:
|
||||
else:
|
||||
return '你还没有绑定过UID噢~'
|
||||
|
||||
async def get_mysid_list(self, userid: int) -> List[str]:
|
||||
async def get_mysid_list(self, userid: str) -> List[str]:
|
||||
"""
|
||||
:说明:
|
||||
获得用户的绑定MYSID列表
|
||||
@ -142,7 +142,7 @@ class UidDataDAL:
|
||||
return mys_list
|
||||
return []
|
||||
|
||||
async def get_mysid(self, userid: int) -> str:
|
||||
async def get_mysid(self, userid: str) -> str:
|
||||
"""
|
||||
:说明:
|
||||
获得用户绑定的MYSID
|
||||
@ -157,7 +157,7 @@ class UidDataDAL:
|
||||
else:
|
||||
return "未找到绑定的MYSID~"
|
||||
|
||||
async def get_anyid(self, userid: int) -> str:
|
||||
async def get_anyid(self, userid: str) -> str:
|
||||
"""
|
||||
:说明:
|
||||
获得用户绑定的ID信息
|
||||
@ -176,12 +176,12 @@ class UidDataDAL:
|
||||
else:
|
||||
return '未找到绑定的ID信息~'
|
||||
|
||||
async def bind_db(self, userid: int, data: dict) -> str:
|
||||
async def bind_db(self, userid: str, data: dict) -> str:
|
||||
"""
|
||||
:说明:
|
||||
绑定UID或者MYSID
|
||||
:参数:
|
||||
* userid (int): QQ号。
|
||||
* userid (str): 频道用户 ID。
|
||||
* data (dict): 绑定的UID或者MYSID, 至少填写一项。
|
||||
data = {'UID': UID, 'MYSID': MYSID}
|
||||
:返回:
|
||||
@ -229,7 +229,7 @@ class UidDataDAL:
|
||||
await self.db_session.flush() # type: ignore
|
||||
return _bind
|
||||
|
||||
async def delete_db(self, userid: int, data: Optional[dict]) -> str:
|
||||
async def delete_db(self, userid: str, data: Optional[dict]) -> str:
|
||||
"""
|
||||
:说明:
|
||||
删除用户的绑定UID或者MYSID
|
||||
@ -284,7 +284,7 @@ class UidDataDAL:
|
||||
|
||||
async def update_db(
|
||||
self,
|
||||
userid: int,
|
||||
userid: str,
|
||||
data: Optional[dict],
|
||||
):
|
||||
"""
|
||||
|
@ -33,7 +33,10 @@ class PushData(SQLModel, table=True):
|
||||
|
||||
class UidData(SQLModel, table=True):
|
||||
__table_args__ = {'keep_existing': True}
|
||||
USERID: int = Field(default=100000000, primary_key=True, title='QQ号')
|
||||
ID: int = Field(
|
||||
default=1, primary_key=True, sa_column_kwargs={"autoincrement": 1}
|
||||
)
|
||||
USERID: str = Field(default="100000000", primary_key=True, title='QQ号')
|
||||
UID: Optional[str] = Field(title='UID')
|
||||
MYSID: Optional[str] = Field(title='米游社通行证(废弃)')
|
||||
|
||||
@ -42,7 +45,7 @@ class NewCookiesTable(SQLModel, table=True):
|
||||
__table_args__ = {'keep_existing': True}
|
||||
UID: int = Field(default=100000000, primary_key=True, title='UID')
|
||||
Cookies: str = Field(title='CK')
|
||||
QID: int = Field(title='QQ号')
|
||||
QID: str = Field(title='QQ号')
|
||||
StatusA: str = Field(title='全局推送开关')
|
||||
StatusB: str = Field(title='自动签到')
|
||||
StatusC: str = Field(title='自动米游币')
|
||||
|
@ -27,7 +27,9 @@ async def check_db():
|
||||
try:
|
||||
if int(str(row[0])[0]) < 6:
|
||||
aid = re.search(r'account_id=(\d*)', row[1])
|
||||
mihoyo_id_data = aid.group(0).split('=') # type: ignore
|
||||
if not aid:
|
||||
raise Exception('cannot match account_id')
|
||||
mihoyo_id_data = aid.group(0).split('=')
|
||||
mihoyo_id = mihoyo_id_data[1]
|
||||
mys_data = await get_mihoyo_bbs_info(mihoyo_id, row[1])
|
||||
for i in mys_data['data']['list']:
|
||||
|
@ -9,7 +9,7 @@ from .database.db_config import async_session
|
||||
|
||||
|
||||
async def get_push_status(uid, func) -> List:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
PushData = PushDataDAL(session)
|
||||
push_dict = await PushData.get_user_data(uid)
|
||||
@ -23,7 +23,7 @@ async def get_push_status(uid, func) -> List:
|
||||
|
||||
|
||||
async def update_push_status(uid: int, func: str, status: str) -> bool:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
PushData = PushDataDAL(session)
|
||||
return await PushData.update_user_data(
|
||||
@ -32,7 +32,7 @@ async def update_push_status(uid: int, func: str, status: str) -> bool:
|
||||
|
||||
|
||||
async def update_push_value(uid: int, func: str, value: int) -> bool:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
PushData = PushDataDAL(session)
|
||||
return await PushData.update_user_data(
|
||||
@ -43,7 +43,7 @@ async def update_push_value(uid: int, func: str, value: int) -> bool:
|
||||
async def update_is_pushed(
|
||||
uid: int, func: str, is_pushed: str = 'off'
|
||||
) -> bool:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
PushData = PushDataDAL(session)
|
||||
return await PushData.update_user_data(
|
||||
@ -52,7 +52,7 @@ async def update_is_pushed(
|
||||
|
||||
|
||||
async def bind_db(userid, uid=None, mys=None):
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
UidData = UidDataDAL(session)
|
||||
im = await UidData.bind_db(userid, {'UID': uid, 'MYSID': mys})
|
||||
@ -68,7 +68,7 @@ async def get_all_bind() -> List[Dict]:
|
||||
|
||||
|
||||
async def get_all_uid() -> List:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
UidData = UidDataDAL(session)
|
||||
lst = await UidData.get_all_uid_list()
|
||||
@ -76,7 +76,7 @@ async def get_all_uid() -> List:
|
||||
|
||||
|
||||
async def get_all_cookie() -> List:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Cookies = CookiesDAL(session)
|
||||
lst = await Cookies.get_all_cookie_list()
|
||||
@ -84,16 +84,14 @@ async def get_all_cookie() -> List:
|
||||
|
||||
|
||||
async def get_all_stoken() -> List:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Cookies = CookiesDAL(session)
|
||||
lst = await Cookies.get_all_stoken_list()
|
||||
return lst
|
||||
|
||||
|
||||
async def select_db(
|
||||
userid: int, mode: str = 'auto'
|
||||
) -> Union[List[str], str, None]:
|
||||
async def select_db(userid: str, mode='auto') -> Union[List, str, None]:
|
||||
"""
|
||||
:说明:
|
||||
选择绑定uid/mys库
|
||||
@ -110,7 +108,7 @@ async def select_db(
|
||||
其他情况下data[0]为需要的uid/mysid
|
||||
data[1]表示data[0]是`uid` or `mysid`
|
||||
"""
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
UidData = UidDataDAL(session)
|
||||
if mode == 'auto':
|
||||
@ -126,7 +124,7 @@ async def select_db(
|
||||
return im
|
||||
|
||||
|
||||
async def switch_db(userid: int, uid: Optional[str] = None) -> str:
|
||||
async def switch_db(userid: str, uid: Optional[str] = None) -> str:
|
||||
"""
|
||||
:说明:
|
||||
切换绑定的UID列表,绑定一个UID的情况下返回无法切换
|
||||
@ -137,14 +135,14 @@ async def switch_db(userid: int, uid: Optional[str] = None) -> str:
|
||||
:返回:
|
||||
* im (str): 回调信息。
|
||||
"""
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
UidData = UidDataDAL(session)
|
||||
im = await UidData.switch_uid(userid, uid)
|
||||
return im
|
||||
|
||||
|
||||
async def delete_db(userid: int, data: dict) -> str:
|
||||
async def delete_db(userid: str, data: dict) -> str:
|
||||
"""
|
||||
:说明:
|
||||
删除当前绑定的UID信息
|
||||
@ -155,15 +153,15 @@ async def delete_db(userid: int, data: dict) -> str:
|
||||
:返回:
|
||||
* im (str): 回调信息。
|
||||
"""
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
UidData = UidDataDAL(session)
|
||||
im = await UidData.delete_db(userid, data)
|
||||
return im
|
||||
|
||||
|
||||
async def cookies_db(uid: str, cookies: str, qid: int):
|
||||
async with async_session() as session:
|
||||
async def cookies_db(uid: str, cookies: str, qid: str):
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Cookies = CookiesDAL(session)
|
||||
im = await Cookies.add_cookie_db(qid, uid, cookies)
|
||||
@ -171,7 +169,7 @@ async def cookies_db(uid: str, cookies: str, qid: int):
|
||||
|
||||
|
||||
async def error_db(cookies: str, error: str):
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Cookies = CookiesDAL(session)
|
||||
im = await Cookies.add_error_db(cookies, error)
|
||||
@ -179,7 +177,7 @@ async def error_db(cookies: str, error: str):
|
||||
|
||||
|
||||
async def owner_cookies(uid: str) -> str:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Cookies = CookiesDAL(session)
|
||||
owner_ck = await Cookies.get_user_ck(uid)
|
||||
@ -191,7 +189,7 @@ async def owner_cookies(uid: str) -> str:
|
||||
|
||||
|
||||
async def delete_cookies(uid: str) -> str:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Cookies = CookiesDAL(session)
|
||||
result = await Cookies.delete_user(uid)
|
||||
@ -202,7 +200,7 @@ async def delete_cookies(uid: str) -> str:
|
||||
|
||||
|
||||
async def get_stoken(uid: str) -> str:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Cookies = CookiesDAL(session)
|
||||
stoken = await Cookies.get_user_stoken(uid)
|
||||
@ -210,7 +208,7 @@ async def get_stoken(uid: str) -> str:
|
||||
|
||||
|
||||
async def get_user_bind_data(uid: str) -> dict:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Cookies = CookiesDAL(session)
|
||||
lst = await Cookies.get_user_data_dict(uid)
|
||||
@ -218,7 +216,7 @@ async def get_user_bind_data(uid: str) -> dict:
|
||||
|
||||
|
||||
async def stoken_db(s_cookies: str, uid: str) -> str:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Cookies = CookiesDAL(session)
|
||||
im = await Cookies.add_stoken_db(uid, s_cookies)
|
||||
@ -226,7 +224,7 @@ async def stoken_db(s_cookies: str, uid: str) -> str:
|
||||
|
||||
|
||||
async def open_push(uid, qid, status, func):
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Cookies = CookiesDAL(session)
|
||||
im = await Cookies.update_user_status(
|
||||
@ -243,7 +241,7 @@ async def empty_cache():
|
||||
|
||||
|
||||
async def config_check(func, mode='CHECK') -> bool:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Config = ConfigDAL(session)
|
||||
im = False
|
||||
@ -257,7 +255,7 @@ async def config_check(func, mode='CHECK') -> bool:
|
||||
|
||||
|
||||
async def get_all_signin_list() -> List:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Cookies = CookiesDAL(session)
|
||||
im = await Cookies.get_status_list('StatusB')
|
||||
@ -265,7 +263,7 @@ async def get_all_signin_list() -> List:
|
||||
|
||||
|
||||
async def get_all_push_list() -> List:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
Cookies = CookiesDAL(session)
|
||||
im = await Cookies.get_status_list('StatusA')
|
||||
@ -273,7 +271,7 @@ async def get_all_push_list() -> List:
|
||||
|
||||
|
||||
async def get_push_data(uid: int) -> dict:
|
||||
async with async_session() as session:
|
||||
async with async_session() as session: # type: ignore
|
||||
async with session.begin():
|
||||
PushData = PushDataDAL(session)
|
||||
push_data = await PushData.get_user_data(uid)
|
||||
|
@ -1,9 +1,7 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import hoshino
|
||||
|
||||
MAIN_PATH = Path(hoshino.config.RES_DIR) / 'GenshinUID'
|
||||
MAIN_PATH = Path() / 'data' / 'GenshinUID'
|
||||
sys.path.append(str(MAIN_PATH))
|
||||
CONFIG_PATH = MAIN_PATH / 'config.json'
|
||||
RESOURCE_PATH = MAIN_PATH / 'resource'
|
||||
|
@ -1,53 +1,63 @@
|
||||
# flake8: noqa
|
||||
# from nonebot.log import logger
|
||||
# from aiocqhttp.exceptions import ActionFailed
|
||||
# from hoshino.typing import List, CQEvent, Iterable
|
||||
from functools import wraps
|
||||
from typing import Optional
|
||||
|
||||
# FIXME: - 在 Hoshino 中可用
|
||||
# def handle_exception(name: str, log_msg: str = None, fail_msg: str = None): # type: ignore
|
||||
# """
|
||||
# :说明:
|
||||
# 捕获命令执行过程中发生的异常并回报。
|
||||
# :参数:
|
||||
# * ``name: str``: 项目的名称。
|
||||
# * ``log_msg: str = None``: 自定义捕获异常后在日志中留存的信息。留空则使用默认信息。
|
||||
# * ``fail_msg: str = None``: 自定义捕获异常后向用户回报的信息,仅在提供自定义日志信息时有效。开头带@则艾特用户。留空则与日志信息相同。
|
||||
# """
|
||||
from nonebot.log import logger
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot.exception import FinishedException
|
||||
from nonebot.adapters.onebot.v11 import ActionFailed
|
||||
|
||||
# def wrapper(func):
|
||||
# @wraps(func)
|
||||
# async def inner(
|
||||
# log_msg: str = log_msg, fail_msg: str = fail_msg, **kwargs
|
||||
# ):
|
||||
# print(kwargs)
|
||||
# matcher: CQEvent = kwargs['matcher']
|
||||
# try:
|
||||
# await func(**kwargs)
|
||||
# except ActionFailed as e:
|
||||
# # 此为bot本身由于风控或网络问题发不出消息,并非代码本身出问题
|
||||
# await matcher.send(f'发送消息失败{e.result["wording"]}')
|
||||
# logger.exception(f'发送{name}消息失败')
|
||||
# except Exception as e:
|
||||
# # 如果e内包含敏感信息,应在此处进行处理
|
||||
# if 'SQL' in str(e):
|
||||
# e = '数据库操作失败!可能正在[校验全部Cookies]\n敏感信息已抹去...请等待一段时间后重试!'
|
||||
# # 代码本身出问题
|
||||
# if log_msg:
|
||||
# if not fail_msg:
|
||||
# fail_msg = log_msg
|
||||
# if fail_msg[0] == '@':
|
||||
# await matcher.send(
|
||||
# f'{fail_msg[1:]}\n错误信息为{e}', at_sender=True
|
||||
# )
|
||||
# else:
|
||||
# await matcher.send(f'{fail_msg}\n错误信息为{e}')
|
||||
# if log_msg[0] == '@':
|
||||
# log_msg = log_msg[1:]
|
||||
# logger.exception(log_msg)
|
||||
# else:
|
||||
# await matcher.send(f'发生错误 {e},请检查后台输出。')
|
||||
# logger.exception(f'获取{name}信息错误')
|
||||
|
||||
# return inner
|
||||
def handle_exception(
|
||||
name: str, log_msg: Optional[str] = None, fail_msg: Optional[str] = None
|
||||
):
|
||||
"""
|
||||
:说明:
|
||||
捕获命令执行过程中发生的异常并回报。
|
||||
:参数:
|
||||
* ``name: str``: 项目的名称。
|
||||
* ``log_msg: str = None``: 自定义捕获异常后在日志中留存的信息。留空则使用默认信息。
|
||||
* ``fail_msg: str = None``: 自定义捕获异常后向用户回报的信息,仅在提供自定义日志信息时有效。
|
||||
开头带@则艾特用户。留空则与日志信息相同。
|
||||
"""
|
||||
|
||||
# return wrapper
|
||||
def wrapper(func):
|
||||
@wraps(func)
|
||||
async def inner(
|
||||
log_msg: Optional[str] = log_msg,
|
||||
fail_msg: Optional[str] = fail_msg,
|
||||
**kwargs,
|
||||
):
|
||||
matcher: Matcher = kwargs['matcher']
|
||||
try:
|
||||
await func(**kwargs)
|
||||
except ActionFailed as e:
|
||||
# 此为bot本身由于风控或网络问题发不出消息,并非代码本身出问题
|
||||
await matcher.send(f'发送消息失败{e.info["wording"]}')
|
||||
logger.exception(f'发送{name}消息失败')
|
||||
except FinishedException:
|
||||
# `finish` 会抛出此异常,应予以抛出而不处理
|
||||
raise
|
||||
except Exception as e:
|
||||
# 如果e内包含敏感信息,应在此处进行处理
|
||||
if 'SQL' in str(e):
|
||||
e = '数据库操作失败!可能正在[校验全部Cookies]\n敏感信息已抹去...请等待一段时间后重试!'
|
||||
# 代码本身出问题
|
||||
if log_msg:
|
||||
if not fail_msg:
|
||||
fail_msg = log_msg
|
||||
if fail_msg[0] == '@':
|
||||
await matcher.send(
|
||||
f'{fail_msg[1:]}\n错误信息为{e}', at_sender=True
|
||||
)
|
||||
else:
|
||||
await matcher.send(f'{fail_msg}\n错误信息为{e}')
|
||||
if log_msg[0] == '@':
|
||||
log_msg = log_msg[1:]
|
||||
logger.exception(log_msg)
|
||||
else:
|
||||
await matcher.send(f'发生错误 {e},请检查后台输出。')
|
||||
logger.exception(f'获取{name}信息错误')
|
||||
|
||||
return inner
|
||||
|
||||
return wrapper
|
||||
|
7
GenshinUID/utils/message/cast_type.py
Normal file
7
GenshinUID/utils/message/cast_type.py
Normal file
@ -0,0 +1,7 @@
|
||||
from typing import Optional, cast
|
||||
|
||||
from nonebot.adapters.qqguild.api.model import User
|
||||
|
||||
|
||||
def cast_to_int(user: Optional[User]) -> int:
|
||||
return cast(int, cast(User, user).id)
|
@ -1,19 +0,0 @@
|
||||
from typing import List
|
||||
|
||||
|
||||
async def get_all_friend_list(bot) -> List[int]:
|
||||
friend_list = []
|
||||
friend_dict_list = await bot.call_action(action='get_friend_list')
|
||||
for friend in friend_dict_list:
|
||||
friend_list.append(friend['user_id'])
|
||||
return friend_list
|
||||
|
||||
|
||||
async def get_group_member_list(bot, group_id: int) -> List[int]:
|
||||
member_list = []
|
||||
group_member_list = await bot.call_api(
|
||||
action='get_group_member_list', group_id=group_id
|
||||
)
|
||||
for group_member in group_member_list:
|
||||
member_list.append(group_member['user_id'])
|
||||
return member_list
|
@ -1,20 +1,18 @@
|
||||
from typing import Union
|
||||
from typing import Optional
|
||||
|
||||
from nonebot.adapters.qqguild import MessageEvent
|
||||
|
||||
|
||||
# https://v2.nonebot.dev/docs/advanced/di/dependency-injection#class-%E4%BD%9C%E4%B8%BA%E4%BE%9D%E8%B5%96
|
||||
class ImageAndAt:
|
||||
def __init__(self, event):
|
||||
def __init__(self, event: MessageEvent):
|
||||
self.images = []
|
||||
self.at = []
|
||||
for i in event.message:
|
||||
if i.type == "image":
|
||||
data = i.data
|
||||
if url := data.get("url"):
|
||||
self.images.append(url)
|
||||
else:
|
||||
continue
|
||||
elif i.type == "at":
|
||||
self.at.append(i.data["qq"])
|
||||
for i in event.get_message():
|
||||
if i.type == "attachment":
|
||||
self.images.append(i.data["url"])
|
||||
elif i.type == "mention_user":
|
||||
self.at.append(i.data["user_id"])
|
||||
|
||||
def get_at(self):
|
||||
return self.at
|
||||
@ -22,14 +20,8 @@ class ImageAndAt:
|
||||
def get_image(self):
|
||||
return self.images
|
||||
|
||||
def get_first_image(self) -> Union[str, None]:
|
||||
try:
|
||||
return self.images[0]
|
||||
except IndexError:
|
||||
return None
|
||||
def get_first_image(self) -> Optional[str]:
|
||||
return self.images[0] if len(self.images) else None
|
||||
|
||||
def get_first_at(self) -> Union[int, None]:
|
||||
try:
|
||||
return self.at[0]
|
||||
except IndexError:
|
||||
return None
|
||||
def get_first_at(self) -> Optional[str]:
|
||||
return self.at[0] if len(self.at) else None
|
||||
|
@ -1,12 +1,12 @@
|
||||
from typing import List
|
||||
|
||||
from ...base import hoshino_bot
|
||||
from nonebot.adapters.qqguild import Bot
|
||||
|
||||
|
||||
# 发送聊天记录
|
||||
async def send_forward_msg(
|
||||
bot: hoshino_bot,
|
||||
group_id: int,
|
||||
bot: Bot,
|
||||
userid: int,
|
||||
name: str,
|
||||
uin: str,
|
||||
msgs: List[str],
|
||||
@ -18,6 +18,6 @@ async def send_forward_msg(
|
||||
}
|
||||
|
||||
messages = [to_json(msg) for msg in msgs]
|
||||
await bot.call_action(
|
||||
action='send_group_forward_msg', group_id=group_id, messages=messages
|
||||
await bot.call_api(
|
||||
"send_private_forward_msg", user_id=userid, messages=messages
|
||||
)
|
||||
|
@ -17,7 +17,6 @@ from ..mhy_api.mhy_api_tools import (
|
||||
random_hex,
|
||||
random_text,
|
||||
get_ds_token,
|
||||
gen_payment_sign,
|
||||
generate_passport_ds,
|
||||
generate_dynamic_secret,
|
||||
old_version_get_ds_token,
|
||||
@ -57,9 +56,6 @@ from ..mhy_api.mhy_api import ( # noqa
|
||||
MIHOYO_BBS_PLAYER_INFO_URL,
|
||||
MIHOYO_BBS_PLAYER_INFO_URL_OS,
|
||||
GET_COOKIE_TOKEN_BY_GAME_TOKEN,
|
||||
CheckOrderurl,
|
||||
CreateOrderurl,
|
||||
fetchGoodsurl,
|
||||
)
|
||||
|
||||
PROXY_URL = string_config.get_config('proxy')
|
||||
@ -549,7 +545,7 @@ async def get_gcg_info(uid: str):
|
||||
|
||||
async def create_qrcode_url():
|
||||
device_id: str = ''.join(random.choices(ascii_letters + digits, k=64))
|
||||
app_id: str = '8'
|
||||
app_id: str = '4'
|
||||
data = await _mhy_request(
|
||||
CREATE_QRCODE,
|
||||
'POST',
|
||||
@ -858,77 +854,3 @@ async def get_regtime_data(uid: str) -> Any:
|
||||
use_proxy=True,
|
||||
)
|
||||
return data
|
||||
|
||||
|
||||
async def fetchgoods():
|
||||
data = {
|
||||
"released_flag": True,
|
||||
"game": "hk4e_cn",
|
||||
"region": "cn_gf01",
|
||||
"uid": "1",
|
||||
"account": "1",
|
||||
}
|
||||
goodslist = await _mhy_request(
|
||||
url=fetchGoodsurl,
|
||||
method='POST',
|
||||
data=data,
|
||||
)
|
||||
# print(json.dumps(goodslist.json(),indent=4,ensure_ascii=False))
|
||||
return goodslist["data"]["goods_list"]
|
||||
|
||||
|
||||
async def topup(uid, goods):
|
||||
device_id = str(uuid.uuid4())
|
||||
HEADER = copy.deepcopy(_HEADER)
|
||||
HEADER["Cookie"] = await owner_cookies(uid)
|
||||
account = HEADER["Cookie"].split("account_id=")[1].split(";")[0]
|
||||
order = {
|
||||
"account": str(account),
|
||||
"region": "cn_gf01",
|
||||
"uid": uid,
|
||||
"delivery_url": "",
|
||||
"device": device_id,
|
||||
"channel_id": 1,
|
||||
"client_ip": "",
|
||||
"client_type": 4,
|
||||
"game": "hk4e_cn",
|
||||
"amount": goods["price"],
|
||||
# "amount": 600,
|
||||
"goods_num": 1,
|
||||
"goods_id": goods["goods_id"],
|
||||
"goods_title": f"{goods['goods_name']}×{str(goods['goods_unit'])}"
|
||||
if int(goods['goods_unit']) > 0
|
||||
else goods["goods_name"],
|
||||
"price_tier": goods["tier_id"],
|
||||
# "price_tier": "Tier_1",
|
||||
"currency": "CNY",
|
||||
"pay_plat": "alipay",
|
||||
}
|
||||
data = {"order": order, "sign": gen_payment_sign(order)}
|
||||
HEADER["x-rpc-device_id"] = device_id
|
||||
HEADER["x-rpc-client_type"] = "4"
|
||||
order = await _mhy_request(
|
||||
url=CreateOrderurl,
|
||||
method='POST',
|
||||
header=HEADER,
|
||||
data=data,
|
||||
)
|
||||
return order["data"]
|
||||
|
||||
|
||||
async def checkorder(order, uid):
|
||||
HEADER = copy.deepcopy(_HEADER)
|
||||
HEADER["Cookie"] = await owner_cookies(uid)
|
||||
data = {
|
||||
"order_no": order["order_no"],
|
||||
"game": "hk4e_cn",
|
||||
"region": "cn_gf01",
|
||||
"uid": uid,
|
||||
}
|
||||
order = await _mhy_request(
|
||||
url=CheckOrderurl,
|
||||
method='GET',
|
||||
header=HEADER,
|
||||
params=data,
|
||||
)
|
||||
return order["data"]["status"]
|
||||
|
@ -115,9 +115,3 @@ bbs_Listurl = (
|
||||
bbs_Detailurl = BBS_URL + '/post/api/getPostFull?post_id={}'
|
||||
bbs_Shareurl = BBS_URL + '/apihub/api/getShareConf?entity_id={}&entity_type=1'
|
||||
bbs_Likeurl = f'{BBS_URL}/apihub/sapi/upvotePost'
|
||||
|
||||
# 原神充值中心
|
||||
fetchGoodsurl = f"{HK4_SDK_URL}/hk4e_cn/mdk/shopwindow/shopwindow/fetchGoods"
|
||||
CreateOrderurl = f"{HK4_SDK_URL}/hk4e_cn/mdk/atropos/api/createOrder"
|
||||
CheckOrderurl = f"{HK4_SDK_URL}/hk4e_cn/mdk/atropos/api/checkOrder"
|
||||
PriceTierurl = f"{HK4_SDK_URL}/hk4e_cn/mdk/shopwindow/shopwindow/listPriceTier"
|
||||
|
@ -1,4 +1,3 @@
|
||||
import hmac
|
||||
import json
|
||||
import time
|
||||
import random
|
||||
@ -76,17 +75,3 @@ def generate_passport_ds(q: str = '', b: Optional[Dict[str, Any]] = None):
|
||||
return _random_str_ds(
|
||||
"JwYDpKvLj6MrMqqYU6jTKF17KNO2PXoS", string.ascii_letters, True, q, b
|
||||
)
|
||||
|
||||
|
||||
def HMCASHA256(data, key):
|
||||
key = key.encode('utf-8')
|
||||
message = data.encode('utf-8')
|
||||
sign = hmac.new(key, message, digestmod=hashlib.sha256).digest()
|
||||
return sign.hex()
|
||||
|
||||
|
||||
def gen_payment_sign(data):
|
||||
data = dict(sorted(data.items(), key=lambda x: x[0]))
|
||||
value = "".join([str(i) for i in data.values()])
|
||||
sign = HMCASHA256(value, "6bdc3982c25f3f3c38668a32d287d16b")
|
||||
return sign
|
||||
|
9
GenshinUID/utils/nonebot2/perm.py
Normal file
9
GenshinUID/utils/nonebot2/perm.py
Normal file
@ -0,0 +1,9 @@
|
||||
from nonebot.permission import Permission
|
||||
from nonebot.adapters.qqguild.event import DirectMessageCreateEvent
|
||||
|
||||
|
||||
async def is_direct(_: DirectMessageCreateEvent) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
DIRECT = Permission(is_direct)
|
15
GenshinUID/utils/nonebot2/rule.py
Normal file
15
GenshinUID/utils/nonebot2/rule.py
Normal file
@ -0,0 +1,15 @@
|
||||
from nonebot.rule import Rule
|
||||
from nonebot.adapters.qqguild import Message
|
||||
from nonebot.params import Depends, CommandArg
|
||||
|
||||
|
||||
async def full_command(arg: Message = CommandArg()) -> bool:
|
||||
return not bool(str(arg))
|
||||
|
||||
|
||||
def FullCommand() -> Rule:
|
||||
return Rule(full_command)
|
||||
|
||||
|
||||
def FullCommandDepend():
|
||||
return Depends(full_command)
|
154
GenshinUID/utils/nonebot2/send.py
Normal file
154
GenshinUID/utils/nonebot2/send.py
Normal file
@ -0,0 +1,154 @@
|
||||
import json
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Union, Optional
|
||||
|
||||
from nonebot.log import logger
|
||||
from aiohttp import ClientSession
|
||||
from nonebot.drivers import Request
|
||||
from nonebot.typing import overrides
|
||||
from nonebot.adapters.qqguild.bot import Bot
|
||||
from pydantic import BaseModel, parse_obj_as
|
||||
from nonebot.adapters.qqguild.adapter import Adapter
|
||||
from nonebot.adapters.qqguild.api.request import _request
|
||||
from nonebot.adapters.qqguild.api.handle import API_HANDLERS
|
||||
from nonebot.adapters.qqguild.api.model import Message as APIMessage
|
||||
from nonebot.adapters.qqguild.message import Message, MessageSegment
|
||||
from nonebot.adapters.qqguild.event import (
|
||||
Event,
|
||||
MessageEvent,
|
||||
DirectMessageCreateEvent,
|
||||
)
|
||||
from nonebot.adapters.qqguild.api.model import (
|
||||
MessageArk,
|
||||
MessageEmbed,
|
||||
MessageMarkdown,
|
||||
MessageReference,
|
||||
)
|
||||
|
||||
|
||||
class LocalImage(MessageSegment):
|
||||
@overrides(MessageSegment)
|
||||
def __str__(self) -> str:
|
||||
return "<local_image>"
|
||||
|
||||
|
||||
def local_image(data: Union[str, Path, bytes, BytesIO]) -> LocalImage:
|
||||
if isinstance(data, (str, Path)):
|
||||
with open(data, "rb") as f:
|
||||
b = f.read()
|
||||
elif isinstance(data, BytesIO):
|
||||
b = data.getvalue()
|
||||
else:
|
||||
b = data
|
||||
return LocalImage("local_image", data={"content": b})
|
||||
|
||||
|
||||
class MessageSend(BaseModel):
|
||||
content: Optional[str] = None
|
||||
embed: Optional[MessageEmbed] = None
|
||||
ark: Optional[MessageArk] = None
|
||||
markdown: Optional[MessageMarkdown] = None
|
||||
message_reference: Optional[MessageReference] = None
|
||||
image: Optional[str] = None
|
||||
msg_id: Optional[str] = None
|
||||
|
||||
|
||||
def patch_send():
|
||||
logger.info("注入本地图片发送猴子补丁")
|
||||
|
||||
@overrides(Bot)
|
||||
async def send(
|
||||
self,
|
||||
event: Event,
|
||||
message: Union[str, Message, MessageSegment],
|
||||
**kwargs,
|
||||
) -> Any:
|
||||
if (
|
||||
not isinstance(event, MessageEvent)
|
||||
or not event.channel_id
|
||||
or not event.id
|
||||
):
|
||||
raise RuntimeError("Event cannot be replied to!")
|
||||
message = (
|
||||
MessageSegment.text(message)
|
||||
if isinstance(message, str)
|
||||
else message
|
||||
)
|
||||
|
||||
message = message if isinstance(message, Message) else Message(message)
|
||||
content = message.extract_content() or None
|
||||
guild_id = None
|
||||
if isinstance(event, DirectMessageCreateEvent):
|
||||
event_dict = event.__dict__
|
||||
guild_id = event_dict['guild_id']
|
||||
if embed := (message["embed"] or None):
|
||||
embed = embed[-1].data["embed"]
|
||||
if ark := (message["ark"] or None):
|
||||
ark = ark[-1].data["ark"]
|
||||
if image := (message["attachment"] or None):
|
||||
image = image[-1].data["url"]
|
||||
if local_image := (message["local_image"] or None):
|
||||
local_image = local_image[-1].data["content"]
|
||||
if markdown := (message["markdown"] or None):
|
||||
markdown = markdown[-1].data["markdown"]
|
||||
return await self.post_messages(
|
||||
channel_id=event.channel_id,
|
||||
guild_id=guild_id,
|
||||
msg_id=event.id,
|
||||
content=content,
|
||||
embed=embed,
|
||||
ark=ark,
|
||||
markdown=markdown,
|
||||
image=image,
|
||||
file_image=local_image,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
Bot.send = send
|
||||
|
||||
async def post_messages(
|
||||
adapter: Adapter, bot: Bot, channel_id: int, guild_id: int, **data
|
||||
) -> Union[APIMessage, List[APIMessage]]:
|
||||
headers = {"Authorization": adapter.get_authorization(bot.bot_info)}
|
||||
model_data = MessageSend(**data).dict(exclude_none=True)
|
||||
d_api = adapter.get_api_base() / f"channels/{channel_id}/messages"
|
||||
if guild_id:
|
||||
d_api = adapter.get_api_base() / f"dms/{guild_id}/messages"
|
||||
if "file_image" in model_data.keys() and (
|
||||
file_image := model_data.pop("file_image")
|
||||
):
|
||||
new_data: Dict[str, Union[BytesIO, str]] = {
|
||||
"file_image": BytesIO(file_image)
|
||||
}
|
||||
for k, v in model_data.items():
|
||||
# 当字段类型为对象或数组时需要将字段序列化为 JSON 字符串后进行调用
|
||||
# https://bot.q.qq.com/wiki/develop/api/openapi/message/post_messages.html#form-data-%E6%A0%BC%E5%BC%8F%E7%A4%BA%E4%BE%8B
|
||||
if isinstance(v, BaseModel):
|
||||
new_data[k] = v.json()
|
||||
elif isinstance(v, (list, dict)):
|
||||
new_data[k] = json.dumps(v)
|
||||
|
||||
else:
|
||||
new_data[k] = v
|
||||
async with ClientSession(headers=headers) as session:
|
||||
req = await session.post(
|
||||
d_api,
|
||||
data=new_data,
|
||||
)
|
||||
data = await req.json()
|
||||
else:
|
||||
request = Request(
|
||||
"POST",
|
||||
d_api,
|
||||
json=model_data,
|
||||
headers=headers,
|
||||
)
|
||||
data = await _request(adapter, bot, request)
|
||||
if guild_id:
|
||||
return parse_obj_as(List[APIMessage], data)
|
||||
else:
|
||||
return parse_obj_as(APIMessage, data)
|
||||
|
||||
API_HANDLERS["post_messages"] = post_messages
|
||||
logger.success("本地图片发送猴子补丁已注入")
|
15
GenshinUID/utils/nonebot2/utils.py
Normal file
15
GenshinUID/utils/nonebot2/utils.py
Normal file
@ -0,0 +1,15 @@
|
||||
from typing import List
|
||||
|
||||
from nonebot import get_driver
|
||||
|
||||
|
||||
def get_superusers() -> List[int]:
|
||||
config = get_driver().config
|
||||
superusers: List[int] = []
|
||||
for su in config.superusers:
|
||||
if "onebot:" in su:
|
||||
# su[7:] == onebot:
|
||||
su = su[7:]
|
||||
if su.isdigit():
|
||||
superusers.append(int(su))
|
||||
return superusers
|
12
__init__.py
12
__init__.py
@ -3,11 +3,11 @@ import shutil
|
||||
from typing import List
|
||||
from pathlib import Path
|
||||
|
||||
import hoshino
|
||||
from nonebot.log import logger
|
||||
from nonebot import load_plugins
|
||||
from nonebot import require, load_plugins
|
||||
|
||||
dir_ = Path(__file__).parent
|
||||
require('nonebot_plugin_apscheduler')
|
||||
|
||||
|
||||
def copy_and_delete_files():
|
||||
@ -27,7 +27,7 @@ def copy_and_delete_files():
|
||||
elif path.name in {"resource", "player"}:
|
||||
dst = Path().joinpath(
|
||||
(
|
||||
hoshino.config.RES_DIR + "/GenshinUID/"
|
||||
"data/GenshinUID/"
|
||||
f"{'players' if path.name == 'player' else path.name}"
|
||||
)
|
||||
)
|
||||
@ -37,7 +37,7 @@ def copy_and_delete_files():
|
||||
dst,
|
||||
dirs_exist_ok=True,
|
||||
)
|
||||
logger.info(f"复制文件夹 {path} -> {dst} 成功")
|
||||
logger.success(f"复制文件夹 {path} -> {dst} 成功")
|
||||
except shutil.Error as e:
|
||||
failed_src: List[Path] = []
|
||||
exc: str
|
||||
@ -56,10 +56,10 @@ def copy_and_delete_files():
|
||||
else:
|
||||
try:
|
||||
shutil.rmtree(path)
|
||||
logger.info(f"删除文件夹 {path} 成功")
|
||||
logger.success(f"删除文件夹 {path} 成功")
|
||||
except OSError as e:
|
||||
logger.warning(f"删除文件夹 {path} 失败:{e.strerror}")
|
||||
|
||||
|
||||
copy_and_delete_files()
|
||||
load_plugins(str(dir_ / 'GenshinUID'), 'hoshino.modules.GenshinUID.GenshinUID')
|
||||
load_plugins(str(dir_ / "GenshinUID"))
|
||||
|
14
deploy/.env.dev
Normal file
14
deploy/.env.dev
Normal file
@ -0,0 +1,14 @@
|
||||
# 配置 NoneBot2 监听的 IP/主机名(不建议修改)
|
||||
HOST=0.0.0.0
|
||||
# 配置 NoneBot2 监听的端口(不建议修改)
|
||||
PORT=8080
|
||||
# 配置 NoneBot 超级用户(例如你的QQ号)
|
||||
SUPERUSERS=["123456789"]
|
||||
# 配置命令起始字符
|
||||
COMMAND_START=["/", ""]
|
||||
|
||||
# 建议别删下面这行
|
||||
FASTAPI_RELOAD=false
|
||||
# 建议别删上面这行
|
||||
|
||||
更多配置参见:https://v2.nonebot.dev/docs/tutorial/configuration
|
14
deploy/cookiecutter.yml
Normal file
14
deploy/cookiecutter.yml
Normal file
@ -0,0 +1,14 @@
|
||||
default_context:
|
||||
py: py
|
||||
project_name: nb2
|
||||
use_src: true
|
||||
adapters:
|
||||
- builtin:
|
||||
- module_name: "nonebot.adapters.onebot.v11"
|
||||
project_link: "nonebot-adapter-onebot"
|
||||
name: "OneBot V11"
|
||||
desc: "OneBot V11 协议"
|
||||
author: "yanyongyu"
|
||||
homepage: "https://onebot.adapters.nonebot.dev/"
|
||||
tags: []
|
||||
is_official: true
|
21
deploy/update_pyproject.py
Normal file
21
deploy/update_pyproject.py
Normal file
@ -0,0 +1,21 @@
|
||||
from typing import List
|
||||
|
||||
import tomlkit
|
||||
|
||||
|
||||
def main():
|
||||
with open("./nb2/pyproject.toml", "r", encoding="utf-8") as f:
|
||||
data = tomlkit.load(f)
|
||||
plugins: List[str] = data["tool"]["nonebot"]["plugins"] # type: ignore
|
||||
if "GenshinUID" in plugins:
|
||||
return
|
||||
plugins.append("GenshinUID")
|
||||
|
||||
with open("./nb2/pyproject.toml", "w", encoding="utf-8") as f:
|
||||
tomlkit.dump(data, f)
|
||||
|
||||
print("Update pyproject.toml done.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1753
poetry.lock
generated
1753
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,34 +1,3 @@
|
||||
[tool.poetry]
|
||||
name = "GenshinUID"
|
||||
version = "0.1.0"
|
||||
description = "基于HoshinoBot/NoneBot2/QQ官方频道Bot(PythonSDK)的原神Uid查询/原神Wiki/米社签到/树脂提醒插件"
|
||||
authors = ["KimigaiiWuyi <444835641@qq.com>"]
|
||||
license = "GPL-3.0-or-later"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.8"
|
||||
httpx = "^0.23.0"
|
||||
beautifulsoup4 = "^4.11.1"
|
||||
lxml = "^4.9.1"
|
||||
openpyxl = "^3.0.10"
|
||||
aiohttp = "^3.8.1"
|
||||
SQLAlchemy = "^1.4.39"
|
||||
Pillow = "^9.2.0"
|
||||
aiosqlite = "^0.17.0"
|
||||
sqlmodel = "^0.0.8"
|
||||
GitPython = "^3.1.27"
|
||||
fastapi_amis_admin = "^0.2.1"
|
||||
fastapi_user_auth = "^0.2.1"
|
||||
pydantic = "^1.10.2"
|
||||
aiofiles = "^22.1.0"
|
||||
qrcode = {extras = ["pil"], version = "^7.3.1"}
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
flake8 = "^4.0.1"
|
||||
black = "^22.6.0"
|
||||
isort = "^5.11.5"
|
||||
pre-commit = "^2.20.0"
|
||||
|
||||
[tool.black]
|
||||
line-length = 79
|
||||
target-version = ["py38", "py39", "py310"]
|
||||
@ -45,10 +14,63 @@ skip_gitignore = true
|
||||
force_sort_within_sections = true
|
||||
extra_standard_library = ["typing_extensions"]
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
asyncio_mode = "auto"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry]
|
||||
name = "GenshinUID"
|
||||
version = "3.1.0"
|
||||
description = "基于HoshinoBot/NoneBot2/QQ官方频道/微信Bot的原神面板查询/原神Wiki/米社签到/树脂提醒插件"
|
||||
authors = ["KimigaiiWuyi <444835641@qq.com>"]
|
||||
license = "GPL-3.0-or-later"
|
||||
readme = "README.md"
|
||||
homepage = "https://github.com/KimigaiiWuyi/GenshinUID/tree/nonebot2-beta1"
|
||||
repository = "https://github.com/KimigaiiWuyi/GenshinUID"
|
||||
documentation = "https://github.com/KimigaiiWuyi/GenshinUID/wiki"
|
||||
packages = [
|
||||
{ include = "GenshinUID" }
|
||||
]
|
||||
exclude = ["tests", "deploy"]
|
||||
|
||||
[tool.poetry.urls]
|
||||
"Bug Tracker" = "https://github.com/KimigaiiWuyi/GenshinUID/issues"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.8.1"
|
||||
nonebot2 = ">=2.0.0b4"
|
||||
nonebot-adapter-qqguild = ">=0.1.2"
|
||||
httpx = ">=0.23.0"
|
||||
beautifulsoup4 = ">=4.11.1"
|
||||
lxml = ">=4.9.2"
|
||||
openpyxl = ">=3.0.10"
|
||||
aiohttp = ">=3.8.1"
|
||||
sqlalchemy = ">=1.4.39"
|
||||
pillow = ">=9.2.0"
|
||||
aiosqlite = ">=0.17.0"
|
||||
nonebot-plugin-apscheduler = ">=0.1.4"
|
||||
aiofiles = ">=0.8.0"
|
||||
sqlmodel = ">=0.0.8"
|
||||
gitpython = ">=3.1.27"
|
||||
fastapi-amis-admin = ">=0.2.1"
|
||||
fastapi-user-auth = ">=0.2.1"
|
||||
qrcode = {extras = ["pil"], version = "^7.3.1"}
|
||||
|
||||
[[tool.poetry.source]]
|
||||
name = 'aliyun.mirrors'
|
||||
url = "http://mirrors.aliyun.com/pypi/simple/"
|
||||
name = "USTC"
|
||||
url = "https://pypi.mirrors.ustc.edu.cn/simple"
|
||||
default = false
|
||||
secondary = true
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
flake8 = "^6.0.0"
|
||||
black = "^22.12.0"
|
||||
isort = "^5.11.5"
|
||||
pre-commit = "^2.21.0"
|
||||
nonebug = "^0.2.2"
|
||||
pytest = "^7.2.0"
|
||||
pytest-asyncio = "^0.20.3"
|
||||
pycln = "^2.1.2"
|
||||
|
114
requirements.txt
114
requirements.txt
@ -1,50 +1,64 @@
|
||||
--trusted-host mirrors.aliyun.com
|
||||
--extra-index-url http://mirrors.aliyun.com/pypi/simple
|
||||
|
||||
aiofiles==22.1.0 ; python_version >= "3.8" and python_version < "4.0"
|
||||
aiohttp==3.8.3 ; python_version >= "3.8" and python_version < "4.0"
|
||||
aiosignal==1.3.1 ; python_version >= "3.8" and python_version < "4.0"
|
||||
aiosqlite==0.17.0 ; python_version >= "3.8" and python_version < "4.0"
|
||||
anyio==3.6.2 ; python_version >= "3.8" and python_version < "4.0"
|
||||
async-timeout==4.0.2 ; python_version >= "3.8" and python_version < "4.0"
|
||||
attrs==22.2.0 ; python_version >= "3.8" and python_version < "4.0"
|
||||
bcrypt==4.0.1 ; python_version >= "3.8" and python_version < "4.0"
|
||||
beautifulsoup4==4.11.1 ; python_version >= "3.8" and python_version < "4.0"
|
||||
certifi==2022.12.7 ; python_version >= "3.8" and python_version < "4.0"
|
||||
charset-normalizer==2.1.1 ; python_version >= "3.8" and python_version < "4.0"
|
||||
colorama==0.4.6 ; python_version >= "3.8" and python_version < "4.0" and platform_system == "Windows"
|
||||
dnspython==2.2.1 ; python_version >= "3.8" and python_version < "4.0"
|
||||
email-validator==1.3.0 ; python_version >= "3.8" and python_version < "4.0"
|
||||
et-xmlfile==1.1.0 ; python_version >= "3.8" and python_version < "4.0"
|
||||
fastapi-amis-admin==0.2.5 ; python_version >= "3.8" and python_version < "4.0"
|
||||
fastapi-user-auth==0.2.4 ; python_version >= "3.8" and python_version < "4.0"
|
||||
fastapi==0.88.0 ; python_version >= "3.8" and python_version < "4.0"
|
||||
frozenlist==1.3.3 ; python_version >= "3.8" and python_version < "4.0"
|
||||
gitdb==4.0.10 ; python_version >= "3.8" and python_version < "4.0"
|
||||
gitpython==3.1.30 ; python_version >= "3.8" and python_version < "4.0"
|
||||
greenlet==2.0.1 ; python_version >= "3.8" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32") and python_version < "4.0"
|
||||
h11==0.14.0 ; python_version >= "3.8" and python_version < "4.0"
|
||||
httpcore==0.16.3 ; python_version >= "3.8" and python_version < "4.0"
|
||||
httpx==0.23.1 ; python_version >= "3.8" and python_version < "4.0"
|
||||
idna==3.4 ; python_version >= "3.8" and python_version < "4.0"
|
||||
lxml==4.9.2 ; python_version >= "3.8" and python_version < "4.0"
|
||||
multidict==6.0.4 ; python_version >= "3.8" and python_version < "4.0"
|
||||
openpyxl==3.0.10 ; python_version >= "3.8" and python_version < "4.0"
|
||||
passlib==1.7.4 ; python_version >= "3.8" and python_version < "4.0"
|
||||
pillow==9.3.0 ; python_version >= "3.8" and python_version < "4.0"
|
||||
pydantic==1.10.4 ; python_version >= "3.8" and python_version < "4.0"
|
||||
python-multipart==0.0.5 ; python_version >= "3.8" and python_version < "4.0"
|
||||
qrcode[pil]==7.3.1 ; python_version >= "3.8" and python_version < "4.0"
|
||||
rfc3986[idna2008]==1.5.0 ; python_version >= "3.8" and python_version < "4.0"
|
||||
six==1.16.0 ; python_version >= "3.8" and python_version < "4.0"
|
||||
smmap==5.0.0 ; python_version >= "3.8" and python_version < "4.0"
|
||||
sniffio==1.3.0 ; python_version >= "3.8" and python_version < "4.0"
|
||||
soupsieve==2.3.2.post1 ; python_version >= "3.8" and python_version < "4.0"
|
||||
sqlalchemy-database==0.0.11 ; python_version >= "3.8" and python_version < "4.0"
|
||||
sqlalchemy2-stubs==0.0.2a31 ; python_version >= "3.8" and python_version < "4.0"
|
||||
sqlalchemy==1.4.41 ; python_version >= "3.8" and python_version < "4.0"
|
||||
sqlmodel==0.0.8 ; python_version >= "3.8" and python_version < "4.0"
|
||||
sqlmodelx==0.0.4 ; python_version >= "3.8" and python_version < "4.0"
|
||||
starlette==0.22.0 ; python_version >= "3.8" and python_version < "4.0"
|
||||
typing-extensions==4.4.0 ; python_version >= "3.8" and python_version < "4.0"
|
||||
yarl==1.8.2 ; python_version >= "3.8" and python_version < "4.0"
|
||||
aiofiles==23.1.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
aiohttp==3.8.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
aiosignal==1.3.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
aiosqlite==0.18.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
anyio==3.6.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
apscheduler==3.10.1 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
async-timeout==4.0.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
attrs==22.2.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
backports-zoneinfo==0.2.1 ; python_full_version >= "3.8.1" and python_version < "3.9"
|
||||
bcrypt==4.0.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
beautifulsoup4==4.11.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
certifi==2022.12.7 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
charset-normalizer==3.1.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
colorama==0.4.6 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" and platform_system == "Windows" or python_full_version >= "3.8.1" and python_version < "4.0" and sys_platform == "win32"
|
||||
dnspython==2.3.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
email-validator==1.3.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
et-xmlfile==1.1.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi-amis-admin==0.5.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi-user-auth==0.5.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
fastapi==0.93.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
frozenlist==1.3.3 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
gitdb==4.0.10 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
gitpython==3.1.31 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
greenlet==2.0.2 ; python_full_version >= "3.8.1" and (platform_machine == "aarch64" or platform_machine == "ppc64le" or platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "win32" or platform_machine == "WIN32") and python_full_version < "4.0.0"
|
||||
h11==0.14.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
httpcore==0.16.3 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
httpx==0.23.3 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
idna==3.4 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
loguru==0.6.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
lxml==4.9.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
multidict==6.0.4 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
nonebot-adapter-qqguild==0.2.1 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
nonebot-plugin-apscheduler==0.2.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
nonebot2==2.0.0rc3 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
openpyxl==3.1.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
passlib==1.7.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
pillow==9.4.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
pydantic==1.10.6 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
pydantic[dotenv]==1.10.6 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
pygtrie==2.5.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
pypng==0.20220715.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
python-dotenv==1.0.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
python-multipart==0.0.6 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
pytz-deprecation-shim==0.1.0.post0 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
pytz==2022.7.1 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
qrcode[pil]==7.4.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
rfc3986[idna2008]==1.5.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
setuptools==67.6.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
six==1.16.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
smmap==5.0.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
sniffio==1.3.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
soupsieve==2.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
sqlalchemy-database==0.1.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
sqlalchemy2-stubs==0.0.2a32 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
sqlalchemy==1.4.41 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
sqlmodel==0.0.8 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
sqlmodelx==0.0.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
starlette==0.25.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
|
||||
tomlkit==0.11.6 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
typing-extensions==4.5.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
tzdata==2022.7 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
tzlocal==4.2 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
win32-setctime==1.1.0 ; python_full_version >= "3.8.1" and python_version < "4.0" and sys_platform == "win32"
|
||||
yarl==1.8.2 ; python_full_version >= "3.8.1" and python_version < "4.0"
|
||||
|
1
tests/.env
Normal file
1
tests/.env
Normal file
@ -0,0 +1 @@
|
||||
ENVIRONMENT=test
|
4
tests/.env.test
Normal file
4
tests/.env.test
Normal file
@ -0,0 +1,4 @@
|
||||
LOG_LEVEL=TRACE
|
||||
NICKNAME=["test"]
|
||||
SUPERUSERS=["10000"]
|
||||
COMMAND_START=["", "/"]
|
34
tests/conftest.py
Normal file
34
tests/conftest.py
Normal file
@ -0,0 +1,34 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
import pytest
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from nonebot.plugin import Plugin
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def load_metadata(nonebug_init: None) -> Optional["Plugin"]:
|
||||
import nonebot
|
||||
|
||||
return nonebot.load_plugin("GenshinUID.genshinuid_meta")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def load_adv(nonebug_init: None) -> Optional["Plugin"]:
|
||||
import nonebot
|
||||
|
||||
return nonebot.load_plugin("GenshinUID.genshinuid_adv")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def load_etc(nonebug_init: None) -> Optional["Plugin"]:
|
||||
import nonebot
|
||||
|
||||
return nonebot.load_plugin("GenshinUID.genshinuid_etcimg")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def load_guide(nonebug_init: None) -> Optional["Plugin"]:
|
||||
import nonebot
|
||||
|
||||
return nonebot.load_plugin("GenshinUID.genshinuid_guide")
|
25
tests/test_adv.py
Normal file
25
tests/test_adv.py
Normal file
@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
from nonebug import App
|
||||
|
||||
MESSAGE = """「安柏」
|
||||
-=-=-=-=-=-=-=-=-=-
|
||||
推荐5★武器:阿莫斯之弓、天空之翼、终末嗟叹之诗
|
||||
推荐4★武器:绝弦
|
||||
推荐圣遗物搭配:
|
||||
[昔日宗室之仪]四件套"""
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(argnames="alias", argvalues=["安柏用什么", "安柏怎么养"])
|
||||
async def test_adv_char_chat(app: App, alias, load_adv: None):
|
||||
from utils import make_event
|
||||
from nonebot.adapters.onebot.v11 import Bot, Message
|
||||
|
||||
from GenshinUID.genshinuid_adv import get_char_adv
|
||||
|
||||
async with app.test_matcher(get_char_adv) as ctx:
|
||||
bot = ctx.create_bot(base=Bot)
|
||||
event = make_event(message=Message(alias))
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_call_send(event, MESSAGE, True)
|
||||
ctx.should_finished()
|
121
tests/test_etc.py
Normal file
121
tests/test_etc.py
Normal file
@ -0,0 +1,121 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from nonebug import App
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(argnames="alias", argvalues=["版本规划", "原石预估"])
|
||||
async def test_get_primogems_data(app: App, alias, load_etc: None):
|
||||
from utils import make_event
|
||||
from nonebot.adapters.onebot.v11 import Bot, Message, MessageSegment
|
||||
|
||||
from GenshinUID.version import Genshin_version
|
||||
from GenshinUID.genshinuid_etcimg import get_primogems_data
|
||||
|
||||
with open(
|
||||
Path(
|
||||
(
|
||||
"../GenshinUID/genshinuid_etcimg"
|
||||
f"/primogems_data/{Genshin_version[:3]}.png"
|
||||
)
|
||||
),
|
||||
"rb",
|
||||
) as f:
|
||||
data = f.read()
|
||||
|
||||
async with app.test_matcher(get_primogems_data) as ctx:
|
||||
bot = ctx.create_bot(base=Bot)
|
||||
event = make_event(message=Message(alias))
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_call_send(
|
||||
event,
|
||||
MessageSegment.image(data),
|
||||
True,
|
||||
)
|
||||
ctx.should_finished()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_primogems_version(app: App, load_etc: None):
|
||||
from utils import make_event
|
||||
from nonebot.adapters.onebot.v11 import Bot, Message, MessageSegment
|
||||
|
||||
from GenshinUID.version import Genshin_version
|
||||
from GenshinUID.genshinuid_etcimg import get_primogems_data
|
||||
|
||||
with open(
|
||||
Path(
|
||||
(
|
||||
"../GenshinUID/genshinuid_etcimg"
|
||||
f"/primogems_data/{Genshin_version[:3]}.png"
|
||||
)
|
||||
),
|
||||
"rb",
|
||||
) as f:
|
||||
data = f.read()
|
||||
|
||||
async with app.test_matcher(get_primogems_data) as ctx:
|
||||
bot = ctx.create_bot(base=Bot)
|
||||
event = make_event(message=Message(f"版本规划{Genshin_version[:3]}"))
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_call_send(
|
||||
event,
|
||||
MessageSegment.image(data),
|
||||
True,
|
||||
)
|
||||
ctx.should_finished()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_primogems_failed(app: App, load_etc: None):
|
||||
from utils import make_event
|
||||
from nonebot.adapters.onebot.v11 import Bot, Message
|
||||
|
||||
from GenshinUID.genshinuid_etcimg import get_primogems_data
|
||||
|
||||
# primogems_img.exists() is False
|
||||
async with app.test_matcher(get_primogems_data) as ctx:
|
||||
bot = ctx.create_bot(base=Bot)
|
||||
|
||||
event = make_event(message=Message("版本规划1.0"))
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_finished()
|
||||
|
||||
# str(args) in version is False
|
||||
async with app.test_matcher(get_primogems_data) as ctx:
|
||||
event = make_event(message=Message("版本规划abc"))
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_finished()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
argnames="alias",
|
||||
argvalues=[
|
||||
"伤害乘区",
|
||||
"血量表",
|
||||
"抗性表",
|
||||
"血量排行",
|
||||
"伤害乘区",
|
||||
],
|
||||
)
|
||||
async def test_get_img_data(app: App, alias, load_etc: None):
|
||||
from utils import make_event
|
||||
from nonebot.adapters.onebot.v11 import Bot, Message, MessageSegment
|
||||
|
||||
from GenshinUID.genshinuid_etcimg import get_img_data
|
||||
|
||||
with open(
|
||||
Path(f"../GenshinUID/genshinuid_etcimg/img_data/{alias}.jpg"),
|
||||
"rb",
|
||||
) as f:
|
||||
data = f.read()
|
||||
|
||||
async with app.test_matcher(get_img_data) as ctx:
|
||||
bot = ctx.create_bot(base=Bot)
|
||||
|
||||
event = make_event(message=Message(f"查询{alias}"))
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_call_send(event, MessageSegment.image(data), True)
|
||||
ctx.should_finished()
|
123
tests/test_guide.py
Normal file
123
tests/test_guide.py
Normal file
@ -0,0 +1,123 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from nonebug import App
|
||||
|
||||
# TODO: update guide tests
|
||||
# @pytest.mark.asyncio
|
||||
# @pytest.mark.parametrize(
|
||||
# argnames="alias",
|
||||
# argvalues=[
|
||||
# "钟离推荐",
|
||||
# "钟离攻略",
|
||||
# "岩王爷攻略", # alias
|
||||
# ],
|
||||
# )
|
||||
# async def test_get_guide_pic(app: App, alias, load_guide: None):
|
||||
# from utils import make_event
|
||||
# from nonebot.adapters.onebot.v11 import Bot, Message, MessageSegment
|
||||
|
||||
# from GenshinUID.genshinuid_guide import get_guide_pic
|
||||
|
||||
# async with app.test_matcher(get_guide_pic) as ctx:
|
||||
# bot = ctx.create_bot(base=Bot)
|
||||
|
||||
# event = make_event(message=Message(alias))
|
||||
# ctx.receive_event(bot, event)
|
||||
# ctx.should_call_send(
|
||||
# event,
|
||||
# MessageSegment.image(
|
||||
# "https://file.microgg.cn/MiniGG/guide/钟离.jpg"
|
||||
# ),
|
||||
# True,
|
||||
# )
|
||||
# ctx.should_finished()
|
||||
|
||||
|
||||
# @pytest.mark.asyncio
|
||||
# async def test_get_guide_pic_traveler(app: App, load_guide: None):
|
||||
# from utils import make_event
|
||||
# from nonebot.adapters.onebot.v11 import Bot, Message, MessageSegment
|
||||
|
||||
# from GenshinUID.genshinuid_guide import get_guide_pic
|
||||
|
||||
# async with app.test_matcher(get_guide_pic) as ctx:
|
||||
# bot = ctx.create_bot(base=Bot)
|
||||
|
||||
# event = make_event(message=Message("旅行者风推荐"))
|
||||
# ctx.receive_event(bot, event)
|
||||
# ctx.should_call_send(
|
||||
# event,
|
||||
# MessageSegment.image(
|
||||
# "https://file.microgg.cn/MiniGG/guide/旅行者-风.jpg"
|
||||
# ),
|
||||
# True,
|
||||
# )
|
||||
# ctx.should_finished()
|
||||
|
||||
|
||||
# @pytest.mark.asyncio
|
||||
# async def test_get_guide_pic_failed(app: App, load_guide: None):
|
||||
# from utils import make_event
|
||||
# from nonebot.adapters.onebot.v11 import Bot, Message
|
||||
|
||||
# from GenshinUID.genshinuid_guide import get_guide_pic
|
||||
|
||||
# async with app.test_matcher(get_guide_pic) as ctx:
|
||||
# bot = ctx.create_bot(base=Bot)
|
||||
|
||||
# event = make_event(message=Message("蔡徐坤攻略"))
|
||||
# ctx.receive_event(bot, event)
|
||||
# ctx.should_finished()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
argnames="alias",
|
||||
argvalues=[
|
||||
"参考面板钟离",
|
||||
"参考面板岩王爷", # alias
|
||||
],
|
||||
)
|
||||
async def test_get_bluekun_pic(app: App, alias, load_guide: None):
|
||||
from utils import make_event
|
||||
from nonebot.adapters.onebot.v11 import Bot, Message, MessageSegment
|
||||
|
||||
from GenshinUID.genshinuid_guide import get_bluekun_pic
|
||||
|
||||
with open(Path("../GenshinUID/genshinuid_guide/img/钟离.jpg"), "rb") as f:
|
||||
data = f.read()
|
||||
async with app.test_matcher(get_bluekun_pic) as ctx:
|
||||
bot = ctx.create_bot(base=Bot)
|
||||
|
||||
event = make_event(message=Message(alias))
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_call_send(event, MessageSegment.image(data), True)
|
||||
ctx.should_finished()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
argnames="alias",
|
||||
argvalues=[
|
||||
"岩",
|
||||
"冰",
|
||||
],
|
||||
)
|
||||
async def test_get_bluekun_pic_element(app: App, alias, load_guide: None):
|
||||
from utils import make_event
|
||||
from nonebot.adapters.onebot.v11 import Bot, Message, MessageSegment
|
||||
|
||||
from GenshinUID.genshinuid_guide import get_bluekun_pic
|
||||
|
||||
with open(
|
||||
Path(f"../GenshinUID/genshinuid_guide/img/{alias}.jpg"), "rb"
|
||||
) as f:
|
||||
data = f.read()
|
||||
async with app.test_matcher(get_bluekun_pic) as ctx:
|
||||
bot = ctx.create_bot(base=Bot)
|
||||
|
||||
event = make_event(message=Message(f"参考面板{alias}"))
|
||||
ctx.receive_event(bot, event)
|
||||
ctx.should_call_send(event, MessageSegment.image(data), True)
|
||||
ctx.should_finished()
|
35
tests/test_metadata.py
Normal file
35
tests/test_metadata.py
Normal file
@ -0,0 +1,35 @@
|
||||
import pytest
|
||||
from nonebug import App
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_metadata(app: App, load_metadata: None):
|
||||
from GenshinUID.genshinuid_meta import __plugin_meta__
|
||||
|
||||
assert __plugin_meta__.name == 'GenshinUID'
|
||||
assert (
|
||||
__plugin_meta__.description == '基于NoneBot2的原神Uid查询/原神Wiki/米游社签到/树脂提醒插件'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_register_menu(app: App, load_metadata: None):
|
||||
from GenshinUID.genshinuid_meta import sub_menus, register_menu
|
||||
|
||||
@register_menu(
|
||||
'test',
|
||||
'trigger',
|
||||
'test register_menu',
|
||||
trigger_method='114514',
|
||||
detail_des='test register_menu',
|
||||
)
|
||||
async def _example() -> None:
|
||||
pass
|
||||
|
||||
assert len(sub_menus) == 1
|
||||
menu = sub_menus[0]
|
||||
assert menu['func'] == 'test'
|
||||
assert menu['trigger_condition'] == 'trigger'
|
||||
assert menu['trigger_method'] == '114514'
|
||||
assert menu['brief_des'] == 'test register_menu'
|
||||
assert menu['detail_des'] == 'test register_menu'
|
108
tests/utils.py
Normal file
108
tests/utils.py
Normal file
@ -0,0 +1,108 @@
|
||||
# https://gist.github.com/38e4df0f6f7879d9324b15ac910229ac
|
||||
from typing import Any, Dict, Optional, cast
|
||||
|
||||
from nonebot.adapters.onebot.v11 import Adapter, Message
|
||||
from nonebot.adapters.onebot.v11.event import Event, Sender
|
||||
|
||||
|
||||
def make_sender(
|
||||
user_id: int = 10001,
|
||||
nickname: str = "test",
|
||||
sex: str = "unknown",
|
||||
age: int = 1,
|
||||
card: str = "test",
|
||||
area: str = "北京",
|
||||
level: str = "1",
|
||||
role: str = "owner",
|
||||
title: str = "test",
|
||||
):
|
||||
"""
|
||||
:说明:
|
||||
生成发送人信息类型。
|
||||
https://github.com/botuniverse/onebot-11/blob/master/event/message.md
|
||||
|
||||
|
||||
:参数:
|
||||
|
||||
* ``user_id: int = 10001``: 发送者 QQ 号。
|
||||
* ``nickname: str = "test"``: 昵称。
|
||||
* ``sex: str = "unknown"``: 性别,`male` 或 `female` 或 `unknown`。
|
||||
* ``age: int = 1``: 年龄。
|
||||
* ``card: str = "test"``: 群名片/备注。
|
||||
* ``area: str = "北京"``: 地区。
|
||||
* ``level: str = "1"``: 成员等级。
|
||||
* ``role: str = "owner"``: 角色,`owner` 或 `admin` 或 `member`。
|
||||
* ``title: str = "test"``: 专属头衔。
|
||||
"""
|
||||
|
||||
return Sender(
|
||||
user_id=user_id,
|
||||
nickname=nickname,
|
||||
sex=sex,
|
||||
age=age,
|
||||
card=card,
|
||||
area=area,
|
||||
level=level,
|
||||
role=role,
|
||||
title=title,
|
||||
)
|
||||
|
||||
|
||||
def make_event(
|
||||
sender: Sender = make_sender(),
|
||||
message: Optional[Message] = None,
|
||||
time: int = 0,
|
||||
self_id: int = 10000,
|
||||
post_type: str = "message",
|
||||
message_type: str = "private",
|
||||
sub_type: str = "friend",
|
||||
group_id: int = 10002,
|
||||
anonymous: Optional[Dict[str, Any]] = None,
|
||||
message_id: int = 1,
|
||||
user_id: int = 10001,
|
||||
font: int = 0,
|
||||
**kwargs,
|
||||
) -> Event:
|
||||
"""
|
||||
:说明:
|
||||
|
||||
根据消息类型自动生成事件。
|
||||
https://github.com/botuniverse/onebot-11/blob/master/event/message.md
|
||||
|
||||
:参数:
|
||||
|
||||
* ``time: int = 0``: 事件发生的时间戳。
|
||||
* ``self_id: int = 10000``: 收到事件的机器人 QQ 号。
|
||||
* ``post_type: str = "message"``: 上报类型。
|
||||
* ``message_type: str = "private"``: 消息类型,`friend` 是私聊消息,`group是群消息`。
|
||||
* ``sub_type: str = "friend"``: 消息子类型:
|
||||
* 私聊消息:如果是好友则是 `friend`,如果是群临时会话则是 `group`。
|
||||
* 群消息:正常消息是 normal,匿名消息是 anonymous,系统提示(如「管理员已禁止群内匿名聊天」)是 notice
|
||||
* ``message_id: int = 1``: 消息 ID。
|
||||
* ``user_id: int = 10001``: 发送者 QQ 号。
|
||||
* ``message: Message = None``: 消息内容。
|
||||
* ``font: int = 0``: 字体。
|
||||
* ``sender: Sender = None``: 发送人信息。
|
||||
"""
|
||||
raw_message = message.extract_plain_text() if message else ''
|
||||
return cast(
|
||||
Event,
|
||||
Adapter.json_to_event(
|
||||
{
|
||||
"time": time,
|
||||
"self_id": self_id,
|
||||
"post_type": post_type,
|
||||
"message_type": message_type,
|
||||
"sub_type": sub_type,
|
||||
"message_id": message_id,
|
||||
"user_id": user_id,
|
||||
"message": message,
|
||||
"raw_message": raw_message,
|
||||
"font": font,
|
||||
"sender": sender,
|
||||
"group_id": group_id,
|
||||
"anonymous": anonymous,
|
||||
**kwargs,
|
||||
},
|
||||
),
|
||||
)
|
Reference in New Issue
Block a user