Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
BraveCowardp committed Jul 26, 2024
2 parents 1f69198 + b664621 commit c559bab
Show file tree
Hide file tree
Showing 4 changed files with 302 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ nb orm check
|:-----:|:----:|:----:|:----:|:----:|
| 抽卡记录帮助 | 群员 || 群聊 | 查看使用帮助 |
| 鸣潮抽卡信息绑定 | 群员 || 群聊 | 绑定获取抽卡记录需要的参数 |
| 抽卡记录 | 群员 || 群聊 | 显示抽卡记录信息,目前只会显示出金抽数 |
| 抽卡记录 | 群员 || 群聊 | 显示抽卡记录信息,目前只会显示出金抽数,可以通过@群友查看其他已绑定抽卡信息群友的抽卡记录 |

## TODO
- [ ] 增加抽卡记录信息显示内容,加一些渲染,优化排版
67 changes: 52 additions & 15 deletions nonebot_plugin_wwgachalogs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
from nonebot.plugin import PluginMetadata
from nonebot import require, on_command
from nonebot.adapters.onebot.v11 import Message
from nonebot.adapters.onebot.v11 import Message, Bot
from nonebot.adapters.onebot.v11.event import GroupMessageEvent
from nonebot.params import CommandArg
from nonebot.typing import T_State
from nonebot.log import logger
from urllib.parse import urlparse, parse_qs

require("nonebot_plugin_orm")
require("nonebot_plugin_alconna")
require("nonebot_plugin_saa")

from nonebot_plugin_orm import async_scoped_session
from nonebot_plugin_alconna.uniseg import UniMsg, At, UniMessage
from nonebot_plugin_saa import AggregatedMessageFactory, Text
from .config import Config
from .db import GachaDatabase
from .model import CardPoolTypes, UserInfo
Expand Down Expand Up @@ -40,12 +45,24 @@

@wwgacha_bind_info.handle()
async def handle_wwgacha_bind_info(event: GroupMessageEvent, state: T_State, session: async_scoped_session, args: Message = CommandArg()):
info_list = args.extract_plain_text().split()
if len(info_list) != 2:
await wwgacha_bind_info.finish("参数个数有误,应为playerid和recordid")

plain_msg = args.extract_plain_text()
info_list = plain_msg.split()
playerid = ""
recordid = ""
if plain_msg.startswith('http'):
message = plain_msg.replace("#", "")
try:
parsed_url = urlparse(message)
query_params = parse_qs(parsed_url.query)
playerid = query_params.get('player_id', [None])[0]
recordid = query_params.get('record_id', [None])[0]
if not playerid or not recordid:
await wwgacha_bind_info.finish("缺少player_id或record_id,请复制完整链接")
except Exception:
await wwgacha_bind_info.finish("无法解析链接,请复制完整链接")
elif len(info_list) != 2:
await wwgacha_bind_info.finish("参数个数有误,应为playerid和recordid")

for info in info_list:
if len(info) == 9:
playerid = info
Expand All @@ -55,6 +72,8 @@ async def handle_wwgacha_bind_info(event: GroupMessageEvent, state: T_State, ses
if playerid == "" or recordid == "":
await wwgacha_bind_info.finish("playerid应为9位,recordid应为32位,请检查")

logger.debug(f"playerid:{playerid}, recordid:{recordid}")

uncheck_user = UserInfo(userid=event.user_id, playerid=playerid, recordid=recordid)
# 检查用户信息是否有效
gachalogs = GachaLogs(user=uncheck_user)
Expand Down Expand Up @@ -94,20 +113,32 @@ async def _(state: T_State, session: async_scoped_session):


@wwgacha_get_gachalogs.handle()
async def handle_wwgacha_get_gachalogs(event: GroupMessageEvent, session: async_scoped_session):
async def handle_wwgacha_get_gachalogs(event: GroupMessageEvent, session: async_scoped_session, msg: UniMsg, bot: Bot):
userid = event.user_id

if msg.has(At):
ats: UniMessage[At] = msg.get(At)
if len(ats) != 1:
await wwgacha_get_gachalogs.finish("目前仅支持查询1人抽卡记录,请重新输入")

userid = int(ats[0].target)

gachadatabase = GachaDatabase(session=session)
user = await gachadatabase.get_user_info(userid=userid)

quser_info = await bot.get_group_member_info(group_id=event.group_id, user_id=userid)
nickname = quser_info['nickname']
card = quser_info['card'] if quser_info['card'] != '' else nickname

if user == None:
await wwgacha_get_gachalogs.finish("尚未绑定抽卡信息,请使用\"鸣潮抽卡信息绑定\"命令绑定")
await wwgacha_get_gachalogs.finish(f"{card}({userid})尚未绑定抽卡信息,请使用\"鸣潮抽卡信息绑定\"命令绑定")

gachalogs = GachaLogs(user=user)
gacha_log_dict = await gachalogs.get_gacha_info()
if gacha_log_dict == None:
await wwgacha_get_gachalogs.finish("抽卡记录获取有误,请重试")

msg = ""
send_msg = f"{card}({userid})的抽卡记录:\n"
for gacha_type in CardPoolTypes:
gold_info_list = gacha_log_dict[gacha_type.name].get_gold_info_list()
logger.debug(gold_info_list)
Expand All @@ -117,20 +148,26 @@ async def handle_wwgacha_get_gachalogs(event: GroupMessageEvent, session: async_
gacha_num = gold_info['gacha_num']
info += f"{name}:[{gacha_num}] "

msg += info + "\n"


await wwgacha_get_gachalogs.finish(msg)
send_msg += info + "\n"
await wwgacha_get_gachalogs.finish(send_msg)


@wwgacha_help.handle()
async def handle_wwgacha_help():
await wwgacha_help.finish("""PC端方法
help_msg = AggregatedMessageFactory([
Text("""PC端方法
1.进入游戏,打开唤取界面,点击唤取记录
2.右键鸣潮图标,选择打开文件所在位置
3.依次打开目录 Wuthering Waves Game\\Client\\Saved Logs 找到 Client.log 文件
4.使用文本编辑器打开,ctrl + F搜索 https://aki-gm-resources.aki-game.com/aki/gacha/index.html 找到位置
5.找到链接携带的player_id和record_id参数
6.发送 "鸣潮抽卡信息绑定 player_id record_id" 即可绑定抽卡信息,可长期使用
例如:鸣潮抽卡信息绑定 100123456 b3545192e2d8ac6a6b0d069e6f54e83f
""")
例如:鸣潮抽卡信息绑定 100123456 b3545192e2d8ac6a6b0d069e6f54e83f"""),
Text("""Android 手机方法
1.进入游戏,打开唤取界面
2.关闭网络
3.点击唤取记录
4.长按左上角空白处,全选,复制
5.向机器人发送\"鸣潮抽卡信息绑定 + 你复制的内容\"""")
])
await help_msg.finish()
Loading

0 comments on commit c559bab

Please sign in to comment.