From 01fceaa4fefe50a9c880221aece17a7c83968551 Mon Sep 17 00:00:00 2001 From: Mualamx Date: Fri, 10 Oct 2025 10:58:46 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=86=9C=E5=9C=BA?= =?UTF-8?q?=E5=B8=81=E6=8D=A2=E7=82=B9=E5=88=B8=E3=80=81=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7=E7=82=B9=E5=88=B8=EF=BC=8C?= =?UTF-8?q?=E5=81=B7=E5=81=B7=E5=8A=A0=E5=90=8E=E9=97=A8=E6=94=B9=E5=86=9C?= =?UTF-8?q?=E5=9C=BA=E5=B8=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 6 +++++ command.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ config.py | 1 + farm/farm.py | 22 ++++++++++++++++ 4 files changed, 102 insertions(+) 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() From eb937dd309704fd4150b7ac20336f9c86de90f15 Mon Sep 17 00:00:00 2001 From: Mualamx Date: Fri, 10 Oct 2025 13:32:45 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=86=9C=E5=9C=BA?= =?UTF-8?q?=E5=B8=81=E6=8D=A2=E7=82=B9=E5=88=B8=E3=80=81=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E7=94=A8=E6=88=B7=E7=82=B9=E5=88=B8=EF=BC=8C?= =?UTF-8?q?=E5=81=B7=E5=81=B7=E5=8A=A0=E5=90=8E=E9=97=A8=E6=94=B9=E5=86=9C?= =?UTF-8?q?=E5=9C=BA=E5=B8=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- farm/farm.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/farm/farm.py b/farm/farm.py index 0b340ae..c2236f0 100644 --- a/farm/farm.py +++ b/farm/farm.py @@ -1150,11 +1150,15 @@ class CFarmManager: @classmethod async def pointToVipPointByUid(cls, uid: str, num: int) -> str: + """农场币兑换点券 + num:用户传参,即将兑换的点券 + pro:兑换倍数;兑换倍数乘以num即为需要消耗的农场币 + """ if num <= 0: return "点券兑换数量必须大于0" - pro = float(Config.get_config("zhenxun_plugin_farm", "点券兑换倍数")) - pro *= float(num) + pro = int(Config.get_config("zhenxun_plugin_farm", "点券兑换倍数")) + pro *= num point = await g_pDBService.user.getUserPointByUid(uid) if point < pro: @@ -1164,7 +1168,7 @@ class CFarmManager: await g_pDBService.user.updateUserPointByUid(uid, int(point)) p = await g_pDBService.user.getUserVipPointByUid(uid) - number = float(num) + p + number = num + p await g_pDBService.user.updateUserVipPointByUid(uid, int(number)) From 4ab21b7f7bf344ed48f76b900113fdb9fae6451d Mon Sep 17 00:00:00 2001 From: Mualamx Date: Sun, 12 Oct 2025 03:35:14 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=A5=20=E5=88=A0=E9=99=A4=E5=90=8E?= =?UTF-8?q?=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- command.py | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/command.py b/command.py index 3bb43d2..5cd3886 100644 --- a/command.py +++ b/command.py @@ -95,8 +95,7 @@ diuse_farm = on_alconna( 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管理员变更农场币"), + Subcommand("my-vipPoint", help_text="我的点券") ), priority=5, block=True, @@ -696,26 +695,3 @@ async def _(session: Uninfo): ).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)