diff --git a/__init__.py b/__init__.py index 77ba75b..9c139ae 100644 --- a/__init__.py +++ b/__init__.py @@ -58,6 +58,12 @@ __plugin_meta__ = PluginMetadata( help="金币兑换农场币的倍数 默认值为: 2倍", default_value="2", ), + RegisterConfig( + key="点券兑换倍数", + value="2000", + help="农场币兑换点券的倍数 比例为2000:1", + default_value="2000", + ), RegisterConfig( key="手续费", value="0.2", diff --git a/command.py b/command.py index 229f673..32c4117 100644 --- a/command.py +++ b/command.py @@ -92,6 +92,9 @@ diuse_farm = on_alconna( Subcommand("change-name", Args["name?", str], help_text="更改农场名"), Subcommand("sign-in", help_text="农场签到"), Subcommand("admin-up", Args["num?", int], help_text="农场下阶段"), + Subcommand("point-to-vipPoint", Args["num?", int], help_text="农场币换点券"), + Subcommand("my-vipPoint", help_text="我的点券"), + Subcommand("mx-change", Args["num?", int], help_text="mx管理员变更农场币"), ), priority=5, block=True, @@ -606,3 +609,73 @@ async def _(session: Uninfo, num: Query[int] = AlconnaQuery("num", 0)): return await g_pDBService.userSoil.nextPhase(uid, num.result) + + +diuse_farm.shortcut( + "农场币换点券(.*?)", + command="我的农场", + arguments=["point-to-vipPoint"], + prefix=True, +) + + +@diuse_farm.assign("point-to-vipPoint") +async def _(session: Uninfo, num: Query[int] = AlconnaQuery("num", 0)): + if num.result <= 0: + await MessageUtils.build_message("请在指令后跟需要购买点券的数量").finish( + reply_to=True + ) + + uid = str(session.user.id) + + if not await g_pToolManager.isRegisteredByUid(uid): + return + + result = await g_pFarmManager.pointToVipPointByUid(uid, num.result) + await MessageUtils.build_message(result).send(reply_to=True) + + +diuse_farm.shortcut( + "我的点券", + command="我的农场", + arguments=["my-vipPoint"], + prefix=True, +) + + +@diuse_farm.assign("my-vipPoint") +async def _(session: Uninfo): + uid = str(session.user.id) + vipPoint = await g_pDBService.user.getUserVipPointByUid(uid) + + if not await g_pToolManager.isRegisteredByUid(uid): + return + + await MessageUtils.build_message( + g_sTranslation["basic"]["vipPoint"].format(vipPoint=vipPoint) + ).send(reply_to=True) + + +diuse_farm.shortcut( + "mx管理员变更农场币(.*?)", + command="我的农场", + arguments=["mx-change"], + prefix=True, +) + + +@diuse_farm.assign("mx-change") +async def _(session: Uninfo, num: Query[int] = AlconnaQuery("num", 0)): + if num.result <= 0: + await MessageUtils.build_message("请在指令后跟需要农场币的数量").finish( + reply_to=True + ) + + uid = str(session.user.id) + + if not await g_pToolManager.isRegisteredByUid(uid): + return + + await g_pDBService.user.updateUserPointByUid(uid, int(num.result)) + message = f"伟大的米线大人把你的农场币变更为: {num.result} 农场币" + await MessageUtils.build_message(message).send(reply_to=True) diff --git a/config.py b/config.py index c878887..cbd3030 100644 --- a/config.py +++ b/config.py @@ -34,6 +34,7 @@ g_sTranslation = { "basic": { "notFarm": "尚未开通农场,快at我发送 开通农场 开通吧 🌱🚜", "point": "你的当前农场币为: {point} 🌾💰", + "vipPoint": "你的当前点券为: {vipPoint} 🌾💰", }, "register": { "success": "✅ 农场开通成功!\n💼 初始资金:{point}农场币 🥳🎉", diff --git a/farm/farm.py b/farm/farm.py index f88e110..6183416 100644 --- a/farm/farm.py +++ b/farm/farm.py @@ -1106,5 +1106,27 @@ class CFarmManager: text=g_sTranslation["soilInfo"][soilLevelText], ) + @classmethod + async def pointToVipPointByUid(cls, uid: str, num: int) -> str: + if num <= 0: + return "点券兑换数量必须大于0" + + pro = float(Config.get_config("zhenxun_plugin_farm", "点券兑换倍数")) + pro *= float(num) + + point = await g_pDBService.user.getUserPointByUid(uid) + if point < pro: + return f"你的农场币不足,当前农场币为{point},兑换还需要{pro - point}农场币" + + point -= pro + await g_pDBService.user.updateUserPointByUid(uid, int(point)) + + p = await g_pDBService.user.getUserVipPointByUid(uid) + number = float(num) + p + + await g_pDBService.user.updateUserVipPointByUid(uid, int(number)) + + return f"兑换{num}点券成功,当前点券:{number},当前农场币:{point}" + g_pFarmManager = CFarmManager()