From 3a197c0c1d3865a6fd81d852915a33f8e905c8fa Mon Sep 17 00:00:00 2001 From: HibiKier <45528451+HibiKier@users.noreply.github.com> Date: Sat, 21 Dec 2024 23:52:17 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E9=81=93=E5=85=B7=E9=94=99=E8=AF=AF=20(#1790)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zhenxun/builtin_plugins/shop/__init__.py | 42 +++++++++----------- zhenxun/builtin_plugins/shop/_data_source.py | 4 +- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/zhenxun/builtin_plugins/shop/__init__.py b/zhenxun/builtin_plugins/shop/__init__.py index 5c48c3f2..104ae88e 100644 --- a/zhenxun/builtin_plugins/shop/__init__.py +++ b/zhenxun/builtin_plugins/shop/__init__.py @@ -14,7 +14,6 @@ from nonebot_plugin_alconna import ( on_alconna, store_true, ) -from nonebot_plugin_session import EventSession from nonebot_plugin_uninfo import Uninfo from zhenxun.configs.utils import BaseBlock, PluginExtraData @@ -23,6 +22,7 @@ from zhenxun.utils.depends import UserName from zhenxun.utils.enum import BlockType, PluginType from zhenxun.utils.exception import GoodsNotFound from zhenxun.utils.message import MessageUtils +from zhenxun.utils.platform import PlatformUtils from ._data_source import ShopManage, gold_rank @@ -107,35 +107,29 @@ _matcher.shortcut( @_matcher.assign("$main") -async def _(session: EventSession, arparma: Arparma): +async def _(session: Uninfo, arparma: Arparma): image = await ShopManage.build_shop_image() logger.info("查看商店", arparma.header_result, session=session) await MessageUtils.build_message(image).send() @_matcher.assign("my-cost") -async def _(session: EventSession, arparma: Arparma): - if session.id1: - logger.info("查看金币", arparma.header_result, session=session) - gold = await ShopManage.my_cost(session.id1, session.platform) - await MessageUtils.build_message(f"你的当前余额: {gold}").send(reply_to=True) - else: - await MessageUtils.build_message("用户id为空...").send(reply_to=True) +async def _(session: Uninfo, arparma: Arparma): + logger.info("查看金币", arparma.header_result, session=session) + gold = await ShopManage.my_cost( + session.user.id, PlatformUtils.get_platform(session) + ) + await MessageUtils.build_message(f"你的当前余额: {gold}").send(reply_to=True) @_matcher.assign("my-props") -async def _(session: EventSession, arparma: Arparma, nickname: str = UserName()): - if session.id1: - logger.info("查看道具", arparma.header_result, session=session) - if image := await ShopManage.my_props( - session.id1, - nickname, - session.platform, - ): - await MessageUtils.build_message(image.pic2bytes()).finish(reply_to=True) - return await MessageUtils.build_message("你的道具为空捏...").send(reply_to=True) - else: - await MessageUtils.build_message("用户id为空...").send(reply_to=True) +async def _(session: Uninfo, arparma: Arparma, nickname: str = UserName()): + logger.info("查看道具", arparma.header_result, session=session) + if image := await ShopManage.my_props( + session.user.id, nickname, PlatformUtils.get_platform(session) + ): + await MessageUtils.build_message(image.pic2bytes()).finish(reply_to=True) + return await MessageUtils.build_message("你的道具为空捏...").send(reply_to=True) @_matcher.assign("buy") @@ -163,7 +157,7 @@ async def _( bot: Bot, event: Event, message: UniMsg, - session: EventSession, + session: Uninfo, arparma: Arparma, name: Match[str], num: Query[int] = AlconnaQuery("num", 1), @@ -177,7 +171,9 @@ async def _( bot, event, session, message, name.result, num.result, "" ) logger.info( - f"使用道具 {name}, 数量: {num}", arparma.header_result, session=session + f"使用道具 {name.result}, 数量: {num.result}", + arparma.header_result, + session=session, ) if isinstance(result, str): await MessageUtils.build_message(result).send(reply_to=True) diff --git a/zhenxun/builtin_plugins/shop/_data_source.py b/zhenxun/builtin_plugins/shop/_data_source.py index 45e0f754..ec8c3d97 100644 --- a/zhenxun/builtin_plugins/shop/_data_source.py +++ b/zhenxun/builtin_plugins/shop/_data_source.py @@ -332,7 +332,9 @@ class ShopManage: return f"{goods_info.goods_name} 单次使用最大数量为{param.max_num_limit}..." await cls.run_before_after(goods, param, "before", **kwargs) result = await cls.__run(goods, param, session, **kwargs) - await UserConsole.use_props(session.id1, goods_info.uuid, num, session.platform) # type: ignore + await UserConsole.use_props( + session.user.id, goods_info.uuid, num, PlatformUtils.get_platform(session) + ) await cls.run_before_after(goods, param, "after", **kwargs) if not result and param.send_success_msg: result = f"使用道具 {goods.name} {num} 次成功!"