zhenxun_bot/zhenxun/builtin_plugins/sign_in/goods_register.py
HibiKier 99f1388e23
首次启动时提供使用web ui方式完全配置 (#1870)
*  添加全局优先级hook

*  添加基础配置api

*  添加数据库连接测试

* 💬 提示重启

* 🩹 填充过配置时友好提示

* 🐛 首次生成简易配置后自动加载

*  添加配置后重启接口

*  添加重启标志文件

*  添加重启脚本命令

*  添加重启系统限制

*  首次配置判断是否为win系统

* 🔥 移除bat

*  添加关于菜单

*  支持整合包插件安装和添加整合包文档

* 🩹 检测数据库路径

* 🩹 修改数据库路径检测

* 🩹 修改数据库路径检测

* 🩹 修复路径注入

* 🎨 显示添加优先级

* 🐛 修改PriorityLifecycle字典类名称

*  修复路径问题

*  修复路径检测

*  新增路径验证功能,确保用户输入的路径安全并在项目根目录内

*  优化路径验证功能,增加对非法字符和路径长度的检查,确保用户输入的路径更加安全

* 🚨 auto fix by pre-commit hooks

*  优化获取文件列表的代码格式

* 📝 修改README中webui示例图

*  更新PriorityLifecycle.on_startup装饰器

*  简化安装依赖的命令构建逻辑

* 🚨 auto fix by pre-commit hooks

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-06-16 09:11:41 +08:00

74 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from decimal import Decimal
import nonebot
from nonebot_plugin_uninfo import Uninfo
from zhenxun.models.sign_user import SignUser
from zhenxun.models.user_console import UserConsole
from zhenxun.utils.decorator.shop import shop_register
from zhenxun.utils.platform import PlatformUtils
driver = nonebot.get_driver()
@shop_register(
name=("好感度双倍加持卡Ⅰ", "好感度双倍加持卡Ⅱ", "好感度双倍加持卡Ⅲ"),
price=(30, 150, 250),
des=(
"下次签到双倍好感度概率 + 10%(谁才是真命天子?)(同类商品将覆盖)",
"下次签到双倍好感度概率 + 20%(平平庸庸)(同类商品将覆盖)",
"下次签到双倍好感度概率 + 30%(金币才是真命天子!)(同类商品将覆盖)",
),
load_status=True,
icon=(
"favorability_card_1.png",
"favorability_card_2.png",
"favorability_card_3.png",
),
**{
"好感度双倍加持卡_prob": 0.1,
"好感度双倍加持卡Ⅱ_prob": 0.2,
"好感度双倍加持卡Ⅲ_prob": 0.3,
}, # type: ignore
)
async def _(session: Uninfo, user_id: int, prob: float):
platform = PlatformUtils.get_platform(session)
user_console = await UserConsole.get_user(session.user.id, platform)
user, _ = await SignUser.get_or_create(
user_id=user_id,
defaults={"platform": platform, "user_console": user_console},
)
user.add_probability = Decimal(prob)
await user.save(update_fields=["add_probability"])
@shop_register(
name="测试道具A",
price=99,
des="随便侧而出",
load_status=False,
icon="sword.png",
)
async def _(user_id: int, group_id: int):
# print(user_id, group_id, "使用测试道具")
pass
@shop_register.before_handle(name="测试道具A", load_status=False)
async def _(user_id: int, group_id: int):
# print(user_id, group_id, "第一个使用前函数before handle")
pass
@shop_register.before_handle(name="测试道具A", load_status=False)
async def _(user_id: int, group_id: int):
# print(user_id, group_id, "第二个使用前函数before handle222")
# raise NotMeetUseConditionsException("太笨了!") # 抛出异常,阻断使用,并返回信息
pass
@shop_register.after_handle(name="测试道具A", load_status=False)
async def _(user_id: int, group_id: int):
# print(user_id, group_id, "第一个使用后函数after handle")
pass