2025-05-28 19:48:12 +08:00
|
|
|
|
import inspect
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
from nonebot.adapters import Event
|
2025-03-16 19:11:05 +08:00
|
|
|
|
from nonebot.rule import to_me
|
2025-06-06 10:56:22 +08:00
|
|
|
|
from nonebot_plugin_alconna import (
|
|
|
|
|
|
Alconna,
|
|
|
|
|
|
AlconnaQuery,
|
|
|
|
|
|
Args,
|
|
|
|
|
|
At,
|
|
|
|
|
|
Match,
|
|
|
|
|
|
MultiVar,
|
|
|
|
|
|
Option,
|
|
|
|
|
|
Query,
|
|
|
|
|
|
Subcommand,
|
|
|
|
|
|
on_alconna,
|
|
|
|
|
|
store_true,
|
|
|
|
|
|
)
|
2025-03-16 19:11:05 +08:00
|
|
|
|
from nonebot_plugin_uninfo import Uninfo
|
2025-04-07 18:52:27 +08:00
|
|
|
|
from nonebot_plugin_waiter import waiter
|
2025-03-16 19:11:05 +08:00
|
|
|
|
|
2025-05-12 17:28:33 +08:00
|
|
|
|
from zhenxun.configs.config import BotConfig
|
2025-03-19 18:00:50 +08:00
|
|
|
|
from zhenxun.services.log import logger
|
2025-03-17 18:07:25 +08:00
|
|
|
|
from zhenxun.utils.message import MessageUtils
|
2025-03-16 19:11:05 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
from .config import g_bSignStatus, g_sTranslation
|
2025-04-29 18:11:09 +08:00
|
|
|
|
from .dbService import g_pDBService
|
2025-03-19 18:00:50 +08:00
|
|
|
|
from .farm.farm import g_pFarmManager
|
|
|
|
|
|
from .farm.shop import g_pShopManager
|
2025-05-27 18:15:11 +08:00
|
|
|
|
from .json import g_pJsonManager
|
|
|
|
|
|
from .tool import g_pToolManager
|
2025-03-16 19:11:05 +08:00
|
|
|
|
|
|
|
|
|
|
diuse_register = on_alconna(
|
2025-03-17 18:07:25 +08:00
|
|
|
|
Alconna("开通农场"),
|
|
|
|
|
|
priority=5,
|
2025-03-16 19:11:05 +08:00
|
|
|
|
rule=to_me(),
|
2025-03-17 18:07:25 +08:00
|
|
|
|
block=True,
|
2025-06-29 23:35:38 +08:00
|
|
|
|
use_cmd_start=True,
|
2025-03-16 19:11:05 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-16 19:11:05 +08:00
|
|
|
|
@diuse_register.handle()
|
2025-04-26 10:25:06 +08:00
|
|
|
|
async def handle_register(session: Uninfo):
|
2025-03-16 19:11:05 +08:00
|
|
|
|
uid = str(session.user.id)
|
2025-04-29 18:11:09 +08:00
|
|
|
|
user = await g_pDBService.user.getUserInfoByUid(uid)
|
2025-03-16 19:11:05 +08:00
|
|
|
|
|
|
|
|
|
|
if user:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await MessageUtils.build_message(g_sTranslation["register"]["repeat"]).send(
|
|
|
|
|
|
reply_to=True
|
|
|
|
|
|
)
|
2025-04-26 10:25:06 +08:00
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
raw_name = str(session.user.name)
|
2025-06-06 10:56:22 +08:00
|
|
|
|
safe_name = g_pToolManager.sanitize_username(raw_name)
|
2025-04-27 17:00:58 +08:00
|
|
|
|
|
2025-04-26 10:25:06 +08:00
|
|
|
|
# 初始化用户信息
|
2025-04-29 18:11:09 +08:00
|
|
|
|
success = await g_pDBService.user.initUserInfoByUid(
|
2025-06-06 10:56:22 +08:00
|
|
|
|
uid=uid, name=safe_name, exp=0, point=500
|
2025-04-26 10:25:06 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
msg = (
|
2025-06-29 01:45:24 +08:00
|
|
|
|
g_sTranslation["register"]["success"].format(point=500)
|
2025-04-27 17:00:58 +08:00
|
|
|
|
if success
|
2025-06-06 10:56:22 +08:00
|
|
|
|
else g_sTranslation["register"]["error"]
|
2025-04-26 10:25:06 +08:00
|
|
|
|
)
|
|
|
|
|
|
logger.info(f"用户注册 {'成功' if success else '失败'}:{uid}")
|
2025-03-17 18:07:25 +08:00
|
|
|
|
|
2025-04-26 10:25:06 +08:00
|
|
|
|
except Exception as e:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
msg = g_sTranslation["register"]["error"]
|
|
|
|
|
|
logger.error(f"注册异常 | UID:{uid} | 错误:{e}")
|
2025-04-27 17:00:58 +08:00
|
|
|
|
|
2025-04-26 10:25:06 +08:00
|
|
|
|
await MessageUtils.build_message(msg).send(reply_to=True)
|
2025-04-27 17:00:58 +08:00
|
|
|
|
|
2025-03-17 18:07:25 +08:00
|
|
|
|
|
|
|
|
|
|
diuse_farm = on_alconna(
|
|
|
|
|
|
Alconna(
|
|
|
|
|
|
"我的农场",
|
|
|
|
|
|
Option("--all", action=store_true),
|
2025-05-12 17:28:33 +08:00
|
|
|
|
Subcommand("detail", help_text="农场详述"),
|
2025-03-17 18:07:25 +08:00
|
|
|
|
Subcommand("my-point", help_text="我的农场币"),
|
2025-05-28 19:48:12 +08:00
|
|
|
|
Subcommand("seed-shop", Args["res?", MultiVar(str)], help_text="种子商店"),
|
2025-03-20 18:06:38 +08:00
|
|
|
|
Subcommand("buy-seed", Args["name?", str]["num?", int], help_text="购买种子"),
|
|
|
|
|
|
Subcommand("my-seed", help_text="我的种子"),
|
2025-03-20 00:45:05 +08:00
|
|
|
|
Subcommand("sowing", Args["name?", str]["num?", int], help_text="播种"),
|
2025-03-20 18:06:38 +08:00
|
|
|
|
Subcommand("harvest", help_text="收获"),
|
2025-03-21 00:25:20 +08:00
|
|
|
|
Subcommand("eradicate", help_text="铲除"),
|
|
|
|
|
|
Subcommand("my-plant", help_text="我的作物"),
|
2025-08-06 17:51:26 +08:00
|
|
|
|
Subcommand("lock-plant", Args["name?", str], help_text="作物加锁"),
|
|
|
|
|
|
Subcommand("unlock-plant", Args["name?", str], help_text="作物解锁"),
|
2025-03-21 00:25:20 +08:00
|
|
|
|
Subcommand("sell-plant", Args["name?", str]["num?", int], help_text="出售作物"),
|
2025-03-21 18:14:50 +08:00
|
|
|
|
Subcommand("stealing", Args["target?", At], help_text="偷菜"),
|
|
|
|
|
|
Subcommand("buy-point", Args["num?", int], help_text="购买农场币"),
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# Subcommand("sell-point", Args["num?", int], help_text="转换金币")
|
2025-05-26 15:10:12 +08:00
|
|
|
|
Subcommand("change-name", Args["name?", str], help_text="更改农场名"),
|
2025-05-27 18:15:11 +08:00
|
|
|
|
Subcommand("sign-in", help_text="农场签到"),
|
2025-05-29 18:20:03 +08:00
|
|
|
|
Subcommand("admin-up", Args["num?", int], help_text="农场下阶段"),
|
2025-10-10 10:58:46 +08:00
|
|
|
|
Subcommand("point-to-vipPoint", Args["num?", int], help_text="农场币换点券"),
|
2025-10-12 03:35:14 +08:00
|
|
|
|
Subcommand("my-vipPoint", help_text="我的点券")
|
2025-03-17 18:07:25 +08:00
|
|
|
|
),
|
|
|
|
|
|
priority=5,
|
|
|
|
|
|
block=True,
|
2025-06-06 10:56:22 +08:00
|
|
|
|
use_cmd_start=True,
|
2025-03-17 18:07:25 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-17 18:07:25 +08:00
|
|
|
|
@diuse_farm.assign("$main")
|
2025-04-27 17:00:58 +08:00
|
|
|
|
async def _(session: Uninfo):
|
2025-03-17 18:07:25 +08:00
|
|
|
|
uid = str(session.user.id)
|
2025-03-18 18:39:02 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-04-07 18:52:27 +08:00
|
|
|
|
return
|
2025-03-18 18:39:02 +08:00
|
|
|
|
|
2025-04-27 17:00:58 +08:00
|
|
|
|
image = await g_pFarmManager.drawFarmByUid(uid)
|
2025-03-19 18:00:50 +08:00
|
|
|
|
await MessageUtils.build_message(image).send(reply_to=True)
|
2025-03-17 18:07:25 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-05-12 17:28:33 +08:00
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"农场详述",
|
|
|
|
|
|
command="我的农场",
|
|
|
|
|
|
arguments=["detail"],
|
|
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-05-12 17:28:33 +08:00
|
|
|
|
@diuse_farm.assign("detail")
|
|
|
|
|
|
async def _(session: Uninfo):
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-05-12 17:28:33 +08:00
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
info = await g_pFarmManager.drawDetailFarmByUid(uid)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await MessageUtils.alc_forward_msg(
|
|
|
|
|
|
[info], session.self_id, BotConfig.self_nickname
|
|
|
|
|
|
).send()
|
|
|
|
|
|
|
2025-05-12 17:28:33 +08:00
|
|
|
|
|
2025-03-17 18:07:25 +08:00
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"我的农场币",
|
|
|
|
|
|
command="我的农场",
|
|
|
|
|
|
arguments=["my-point"],
|
|
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-17 18:07:25 +08:00
|
|
|
|
@diuse_farm.assign("my-point")
|
|
|
|
|
|
async def _(session: Uninfo):
|
|
|
|
|
|
uid = str(session.user.id)
|
2025-04-29 18:11:09 +08:00
|
|
|
|
point = await g_pDBService.user.getUserPointByUid(uid)
|
2025-03-17 18:07:25 +08:00
|
|
|
|
|
2025-03-19 18:00:50 +08:00
|
|
|
|
if point < 0:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await MessageUtils.build_message(g_sTranslation["basic"]["notFarm"]).send()
|
2025-04-07 18:52:27 +08:00
|
|
|
|
return False
|
2025-03-19 18:00:50 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await MessageUtils.build_message(
|
|
|
|
|
|
g_sTranslation["basic"]["point"].format(point=point)
|
|
|
|
|
|
).send(reply_to=True)
|
|
|
|
|
|
|
2025-03-17 18:07:25 +08:00
|
|
|
|
|
|
|
|
|
|
diuse_farm.shortcut(
|
2025-04-09 17:14:37 +08:00
|
|
|
|
"种子商店(.*?)",
|
2025-03-17 18:07:25 +08:00
|
|
|
|
command="我的农场",
|
2025-03-20 18:06:38 +08:00
|
|
|
|
arguments=["seed-shop"],
|
2025-03-17 18:07:25 +08:00
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-20 18:06:38 +08:00
|
|
|
|
@diuse_farm.assign("seed-shop")
|
2025-05-28 19:48:12 +08:00
|
|
|
|
async def _(session: Uninfo, res: Match[tuple[str, ...]]):
|
2025-03-17 18:07:25 +08:00
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-04-07 18:52:27 +08:00
|
|
|
|
return
|
2025-03-19 18:00:50 +08:00
|
|
|
|
|
2025-05-28 19:48:12 +08:00
|
|
|
|
if res.result is inspect._empty:
|
|
|
|
|
|
raw = []
|
|
|
|
|
|
else:
|
|
|
|
|
|
raw = res.result
|
|
|
|
|
|
|
|
|
|
|
|
filterKey: str | int | None = None
|
|
|
|
|
|
page: int = 1
|
|
|
|
|
|
|
|
|
|
|
|
if len(raw) >= 1 and raw[0] is not None:
|
|
|
|
|
|
first = raw[0]
|
|
|
|
|
|
if isinstance(first, str) and first.isdigit():
|
|
|
|
|
|
page = int(first)
|
|
|
|
|
|
else:
|
|
|
|
|
|
filterKey = first
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if (
|
|
|
|
|
|
len(raw) >= 2
|
|
|
|
|
|
and raw[1] is not None
|
|
|
|
|
|
and isinstance(raw[1], str)
|
|
|
|
|
|
and raw[1].isdigit()
|
|
|
|
|
|
):
|
2025-05-28 19:48:12 +08:00
|
|
|
|
page = int(raw[1])
|
|
|
|
|
|
|
|
|
|
|
|
if filterKey is None:
|
|
|
|
|
|
image = await g_pShopManager.getSeedShopImage(page)
|
|
|
|
|
|
else:
|
|
|
|
|
|
image = await g_pShopManager.getSeedShopImage(filterKey, page)
|
|
|
|
|
|
|
2025-03-19 18:00:50 +08:00
|
|
|
|
await MessageUtils.build_message(image).send()
|
2025-03-17 18:07:25 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-17 18:07:25 +08:00
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"购买种子(?P<name>.*?)",
|
|
|
|
|
|
command="我的农场",
|
2025-03-20 18:06:38 +08:00
|
|
|
|
arguments=["buy-seed", "{name}"],
|
2025-03-17 18:07:25 +08:00
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-20 18:06:38 +08:00
|
|
|
|
@diuse_farm.assign("buy-seed")
|
2025-06-06 10:56:22 +08:00
|
|
|
|
async def _(
|
|
|
|
|
|
session: Uninfo, name: Match[str], num: Query[int] = AlconnaQuery("num", 1)
|
|
|
|
|
|
):
|
2025-03-17 18:07:25 +08:00
|
|
|
|
if not name.available:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await MessageUtils.build_message(g_sTranslation["buySeed"]["notSeed"]).finish(
|
|
|
|
|
|
reply_to=True
|
|
|
|
|
|
)
|
2025-03-17 18:07:25 +08:00
|
|
|
|
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-04-07 18:52:27 +08:00
|
|
|
|
return
|
2025-03-17 18:07:25 +08:00
|
|
|
|
|
2025-03-20 18:06:38 +08:00
|
|
|
|
result = await g_pShopManager.buySeed(uid, name.result, num.result)
|
2025-03-19 18:00:50 +08:00
|
|
|
|
await MessageUtils.build_message(result).send(reply_to=True)
|
2025-03-17 18:07:25 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-17 18:07:25 +08:00
|
|
|
|
diuse_farm.shortcut(
|
2025-03-19 18:00:50 +08:00
|
|
|
|
"我的种子",
|
2025-03-17 18:07:25 +08:00
|
|
|
|
command="我的农场",
|
2025-03-20 18:06:38 +08:00
|
|
|
|
arguments=["my-seed"],
|
2025-03-17 18:07:25 +08:00
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-20 18:06:38 +08:00
|
|
|
|
@diuse_farm.assign("my-seed")
|
2025-03-17 18:07:25 +08:00
|
|
|
|
async def _(session: Uninfo):
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-04-07 18:52:27 +08:00
|
|
|
|
return
|
2025-03-19 18:00:50 +08:00
|
|
|
|
|
2025-03-20 18:06:38 +08:00
|
|
|
|
result = await g_pFarmManager.getUserSeedByUid(uid)
|
2025-03-19 18:00:50 +08:00
|
|
|
|
await MessageUtils.build_message(result).send(reply_to=True)
|
2025-03-20 00:45:05 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-20 00:45:05 +08:00
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"播种(?P<name>.*?)",
|
|
|
|
|
|
command="我的农场",
|
|
|
|
|
|
arguments=["sowing", "{name}"],
|
|
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-20 18:06:38 +08:00
|
|
|
|
@diuse_farm.assign("sowing")
|
2025-06-06 10:56:22 +08:00
|
|
|
|
async def _(
|
|
|
|
|
|
session: Uninfo, name: Match[str], num: Query[int] = AlconnaQuery("num", -1)
|
|
|
|
|
|
):
|
2025-03-20 00:45:05 +08:00
|
|
|
|
if not name.available:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await MessageUtils.build_message(g_sTranslation["sowing"]["notSeed"]).finish(
|
|
|
|
|
|
reply_to=True
|
|
|
|
|
|
)
|
2025-03-20 00:45:05 +08:00
|
|
|
|
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-04-07 18:52:27 +08:00
|
|
|
|
return
|
2025-03-20 00:45:05 +08:00
|
|
|
|
|
2025-03-20 18:06:38 +08:00
|
|
|
|
result = await g_pFarmManager.sowing(uid, name.result, num.result)
|
|
|
|
|
|
await MessageUtils.build_message(result).send(reply_to=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"收获",
|
|
|
|
|
|
command="我的农场",
|
|
|
|
|
|
arguments=["harvest"],
|
|
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
2025-03-20 00:45:05 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-20 18:06:38 +08:00
|
|
|
|
@diuse_farm.assign("harvest")
|
|
|
|
|
|
async def _(session: Uninfo):
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-04-07 18:52:27 +08:00
|
|
|
|
return
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
|
|
|
|
|
result = await g_pFarmManager.harvest(uid)
|
|
|
|
|
|
await MessageUtils.build_message(result).send(reply_to=True)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-21 00:25:20 +08:00
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"铲除",
|
|
|
|
|
|
command="我的农场",
|
|
|
|
|
|
arguments=["eradicate"],
|
|
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-21 00:25:20 +08:00
|
|
|
|
@diuse_farm.assign("eradicate")
|
|
|
|
|
|
async def _(session: Uninfo):
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-04-07 18:52:27 +08:00
|
|
|
|
return
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
|
|
|
|
|
result = await g_pFarmManager.eradicate(uid)
|
|
|
|
|
|
await MessageUtils.build_message(result).send(reply_to=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-03-20 18:06:38 +08:00
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"我的作物",
|
|
|
|
|
|
command="我的农场",
|
|
|
|
|
|
arguments=["my-plant"],
|
|
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-20 18:06:38 +08:00
|
|
|
|
@diuse_farm.assign("my-plant")
|
|
|
|
|
|
async def _(session: Uninfo):
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-04-07 18:52:27 +08:00
|
|
|
|
return
|
2025-03-20 18:06:38 +08:00
|
|
|
|
|
|
|
|
|
|
result = await g_pFarmManager.getUserPlantByUid(uid)
|
|
|
|
|
|
await MessageUtils.build_message(result).send(reply_to=True)
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
2025-08-06 17:51:26 +08:00
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"作物加锁(?P<name>)",
|
|
|
|
|
|
command="我的农场",
|
|
|
|
|
|
arguments=["lock-plant", "{name}"],
|
|
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@diuse_farm.assign("lock-plant")
|
|
|
|
|
|
async def _(session: Uninfo, name: Match[str]):
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
|
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
result = await g_pFarmManager.lockUserPlantByUid(uid, name.result, 1)
|
|
|
|
|
|
await MessageUtils.build_message(result).send(reply_to=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"作物解锁(?P<name>)",
|
|
|
|
|
|
command="我的农场",
|
|
|
|
|
|
arguments=["unlock-plant", "{name}"],
|
|
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@diuse_farm.assign("unlock-plant")
|
|
|
|
|
|
async def _(session: Uninfo, name: Match[str]):
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
|
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
result = await g_pFarmManager.lockUserPlantByUid(uid, name.result, 0)
|
|
|
|
|
|
await MessageUtils.build_message(result).send(reply_to=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"出售作物(?P<name>.*?)",
|
|
|
|
|
|
command="我的农场",
|
|
|
|
|
|
arguments=["sell-plant", "{name}"],
|
|
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@diuse_farm.assign("sell-plant")
|
|
|
|
|
|
async def _(
|
|
|
|
|
|
session: Uninfo, name: Match[str], num: Query[int] = AlconnaQuery("num", -1)
|
|
|
|
|
|
):
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
|
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
result = await g_pShopManager.sellPlantByUid(uid, name.result, num.result)
|
|
|
|
|
|
await MessageUtils.build_message(result).send(reply_to=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-07 18:52:27 +08:00
|
|
|
|
reclamation = on_alconna(
|
|
|
|
|
|
Alconna("开垦"),
|
|
|
|
|
|
priority=5,
|
|
|
|
|
|
block=True,
|
2025-06-29 23:35:38 +08:00
|
|
|
|
use_cmd_start=True,
|
2025-04-07 18:52:27 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-04-07 18:52:27 +08:00
|
|
|
|
@reclamation.handle()
|
|
|
|
|
|
async def _(session: Uninfo):
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-04-07 18:52:27 +08:00
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
condition = await g_pFarmManager.reclamationCondition(uid)
|
2025-06-06 10:56:22 +08:00
|
|
|
|
condition += f"\n{g_sTranslation['reclamation']['confirm']}"
|
2025-04-07 18:52:27 +08:00
|
|
|
|
await MessageUtils.build_message(condition).send(reply_to=True)
|
|
|
|
|
|
|
|
|
|
|
|
@waiter(waits=["message"], keep_session=True)
|
|
|
|
|
|
async def check(event: Event):
|
|
|
|
|
|
return event.get_plaintext()
|
|
|
|
|
|
|
|
|
|
|
|
resp = await check.wait(timeout=60)
|
|
|
|
|
|
if resp is None:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await MessageUtils.build_message(g_sTranslation["reclamation"]["timeOut"]).send(
|
|
|
|
|
|
reply_to=True
|
|
|
|
|
|
)
|
2025-04-07 18:52:27 +08:00
|
|
|
|
return
|
|
|
|
|
|
if not resp == "是":
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
res = await g_pFarmManager.reclamation(uid)
|
|
|
|
|
|
await MessageUtils.build_message(res).send(reply_to=True)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-21 18:14:50 +08:00
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"偷菜",
|
|
|
|
|
|
command="我的农场",
|
|
|
|
|
|
arguments=["stealing"],
|
|
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-03-21 18:14:50 +08:00
|
|
|
|
@diuse_farm.assign("stealing")
|
|
|
|
|
|
async def _(session: Uninfo, target: Match[At]):
|
|
|
|
|
|
uid = str(session.user.id)
|
2025-03-21 00:25:20 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-04-07 18:52:27 +08:00
|
|
|
|
return
|
2025-03-21 18:14:50 +08:00
|
|
|
|
|
|
|
|
|
|
if not target.available:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await MessageUtils.build_message(g_sTranslation["stealing"]["noTarget"]).finish(
|
|
|
|
|
|
reply_to=True
|
|
|
|
|
|
)
|
2025-03-21 18:14:50 +08:00
|
|
|
|
|
|
|
|
|
|
tar = target.result
|
2025-04-29 18:11:09 +08:00
|
|
|
|
result = await g_pDBService.user.isUserExist(tar.target)
|
2025-03-21 18:14:50 +08:00
|
|
|
|
|
2025-04-29 18:11:09 +08:00
|
|
|
|
if not result:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await MessageUtils.build_message(
|
|
|
|
|
|
g_sTranslation["stealing"]["targetNotFarm"]
|
|
|
|
|
|
).send()
|
2025-03-21 18:14:50 +08:00
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
result = await g_pFarmManager.stealing(uid, tar.target)
|
|
|
|
|
|
await MessageUtils.build_message(result).send(reply_to=True)
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-04-07 18:52:27 +08:00
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"购买农场币(.*?)",
|
|
|
|
|
|
command="我的农场",
|
|
|
|
|
|
arguments=["buy-point"],
|
|
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-04-07 18:52:27 +08:00
|
|
|
|
@diuse_farm.assign("buy-point")
|
|
|
|
|
|
async def _(session: Uninfo, num: Query[int] = AlconnaQuery("num", 0)):
|
|
|
|
|
|
if num.result <= 0:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await MessageUtils.build_message("请在指令后跟需要购买农场币的数量").finish(
|
|
|
|
|
|
reply_to=True
|
|
|
|
|
|
)
|
2025-04-07 18:52:27 +08:00
|
|
|
|
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-04-07 18:52:27 +08:00
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
result = await g_pFarmManager.buyPointByUid(uid, num.result)
|
|
|
|
|
|
await MessageUtils.build_message(result).send(reply_to=True)
|
2025-04-27 17:00:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"更改农场名(?P<name>)",
|
|
|
|
|
|
command="我的农场",
|
|
|
|
|
|
arguments=["change-name", "{name}"],
|
|
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-04-27 17:00:58 +08:00
|
|
|
|
@diuse_farm.assign("change-name")
|
|
|
|
|
|
async def _(session: Uninfo, name: Match[str]):
|
|
|
|
|
|
if not name.available:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await MessageUtils.build_message(g_sTranslation["changeName"]["noName"]).finish(
|
|
|
|
|
|
reply_to=True
|
|
|
|
|
|
)
|
2025-04-27 17:00:58 +08:00
|
|
|
|
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-04-27 17:00:58 +08:00
|
|
|
|
return
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
safeName = g_pToolManager.sanitize_username(name.result)
|
2025-04-27 17:00:58 +08:00
|
|
|
|
|
2025-05-30 11:22:32 +08:00
|
|
|
|
if safeName == "神秘农夫":
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await MessageUtils.build_message(g_sTranslation["changeName"]["error"]).send(
|
|
|
|
|
|
reply_to=True
|
|
|
|
|
|
)
|
2025-05-30 11:22:32 +08:00
|
|
|
|
return
|
|
|
|
|
|
|
2025-04-29 18:11:09 +08:00
|
|
|
|
result = await g_pDBService.user.updateUserNameByUid(uid, safeName)
|
2025-04-27 17:00:58 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if result:
|
|
|
|
|
|
await MessageUtils.build_message(g_sTranslation["changeName"]["success"]).send(
|
|
|
|
|
|
reply_to=True
|
|
|
|
|
|
)
|
2025-04-27 17:00:58 +08:00
|
|
|
|
else:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await MessageUtils.build_message(g_sTranslation["changeName"]["error1"]).send(
|
|
|
|
|
|
reply_to=True
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-05-26 15:10:12 +08:00
|
|
|
|
|
2025-05-27 18:15:11 +08:00
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"农场签到",
|
|
|
|
|
|
command="我的农场",
|
|
|
|
|
|
arguments=["sign-in"],
|
|
|
|
|
|
prefix=True,
|
2025-05-26 15:10:12 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-05-27 18:15:11 +08:00
|
|
|
|
@diuse_farm.assign("sign-in")
|
2025-05-26 15:10:12 +08:00
|
|
|
|
async def _(session: Uninfo):
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-05-26 15:10:12 +08:00
|
|
|
|
return
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 判断签到是否正常加载
|
2025-05-28 19:48:12 +08:00
|
|
|
|
if not g_bSignStatus:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
await MessageUtils.build_message(g_sTranslation["signIn"]["error"]).send()
|
2025-05-26 15:10:12 +08:00
|
|
|
|
|
2025-05-27 18:15:11 +08:00
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
toDay = g_pToolManager.dateTime().date().today()
|
2025-05-26 15:10:12 +08:00
|
|
|
|
message = ""
|
|
|
|
|
|
status = await g_pDBService.userSign.sign(uid, toDay.strftime("%Y-%m-%d"))
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 如果完成签到
|
2025-05-27 18:15:11 +08:00
|
|
|
|
if status == 1 or status == 2:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
# 获取签到总天数
|
|
|
|
|
|
signDay = await g_pDBService.userSign.getUserSignCountByDate(
|
|
|
|
|
|
uid, toDay.strftime("%Y-%m")
|
|
|
|
|
|
)
|
|
|
|
|
|
exp, point = await g_pDBService.userSign.getUserSignRewardByDate(
|
|
|
|
|
|
uid, toDay.strftime("%Y-%m-%d")
|
|
|
|
|
|
)
|
2025-05-27 18:15:11 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
message += g_sTranslation["signIn"]["success"].format(
|
|
|
|
|
|
day=signDay, exp=exp, num=point
|
|
|
|
|
|
)
|
2025-05-26 15:10:12 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
reward = g_pJsonManager.m_pSign["continuou"].get(f"{signDay}", None)
|
2025-05-26 15:10:12 +08:00
|
|
|
|
|
2025-05-27 18:15:11 +08:00
|
|
|
|
if reward:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
extraPoint = reward.get("point", 0)
|
|
|
|
|
|
extraExp = reward.get("exp", 0)
|
2025-05-27 18:15:11 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
plant = reward.get("plant", {})
|
2025-05-27 18:15:11 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
message += g_sTranslation["signIn"]["grandTotal"].format(
|
|
|
|
|
|
exp=extraExp, num=extraPoint
|
|
|
|
|
|
)
|
2025-05-27 18:15:11 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
vipPoint = reward.get("vipPoint", 0)
|
2025-05-29 18:20:03 +08:00
|
|
|
|
|
|
|
|
|
|
if vipPoint > 0:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
message += g_sTranslation["signIn"]["grandTotal1"].format(num=vipPoint)
|
2025-05-29 18:20:03 +08:00
|
|
|
|
|
2025-05-27 18:15:11 +08:00
|
|
|
|
if plant:
|
|
|
|
|
|
for key, value in plant.items():
|
2025-06-06 10:56:22 +08:00
|
|
|
|
message += g_sTranslation["signIn"]["grandTotal2"].format(
|
|
|
|
|
|
name=key, num=value
|
|
|
|
|
|
)
|
2025-05-27 18:15:11 +08:00
|
|
|
|
else:
|
2025-06-06 10:56:22 +08:00
|
|
|
|
message = g_sTranslation["signIn"]["error1"]
|
2025-05-26 15:10:12 +08:00
|
|
|
|
|
2025-05-27 18:15:11 +08:00
|
|
|
|
await MessageUtils.build_message(message).send()
|
2025-05-26 15:10:12 +08:00
|
|
|
|
|
|
|
|
|
|
# await MessageUtils.alc_forward_msg([info], session.self_id, BotConfig.self_nickname).send(reply_to=True)
|
2025-05-29 18:20:03 +08:00
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-06-29 01:45:24 +08:00
|
|
|
|
soil_upgrade = on_alconna(
|
|
|
|
|
|
Alconna("土地升级", Args["index", int]),
|
|
|
|
|
|
priority=5,
|
|
|
|
|
|
block=True,
|
2025-06-29 23:35:38 +08:00
|
|
|
|
use_cmd_start=True,
|
2025-06-29 01:45:24 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@soil_upgrade.handle()
|
2025-06-29 21:31:09 +08:00
|
|
|
|
async def _(session: Uninfo, index: Query[int] = AlconnaQuery("index", 1)):
|
2025-06-29 01:45:24 +08:00
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
|
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
condition = await g_pFarmManager.soilUpgradeCondition(uid, index.result)
|
|
|
|
|
|
|
|
|
|
|
|
await MessageUtils.build_message(condition).send(reply_to=True)
|
|
|
|
|
|
|
2025-06-30 01:07:57 +08:00
|
|
|
|
if not condition.startswith("将土地升级至:"):
|
|
|
|
|
|
return
|
|
|
|
|
|
|
2025-06-29 01:45:24 +08:00
|
|
|
|
@waiter(waits=["message"], keep_session=True)
|
|
|
|
|
|
async def check(event: Event):
|
|
|
|
|
|
return event.get_plaintext()
|
|
|
|
|
|
|
|
|
|
|
|
resp = await check.wait(timeout=60)
|
|
|
|
|
|
if resp is None:
|
|
|
|
|
|
await MessageUtils.build_message(g_sTranslation["soilInfo"]["timeOut"]).send(
|
|
|
|
|
|
reply_to=True
|
|
|
|
|
|
)
|
|
|
|
|
|
return
|
|
|
|
|
|
if not resp == "是":
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
res = await g_pFarmManager.soilUpgrade(uid, index.result)
|
|
|
|
|
|
await MessageUtils.build_message(res).send(reply_to=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-05-29 18:20:03 +08:00
|
|
|
|
diuse_farm.shortcut(
|
|
|
|
|
|
"农场下阶段(.*?)",
|
|
|
|
|
|
command="我的农场",
|
|
|
|
|
|
arguments=["admin-up"],
|
|
|
|
|
|
prefix=True,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
|
2025-05-29 18:20:03 +08:00
|
|
|
|
@diuse_farm.assign("admin-up")
|
|
|
|
|
|
async def _(session: Uninfo, num: Query[int] = AlconnaQuery("num", 0)):
|
|
|
|
|
|
uid = str(session.user.id)
|
|
|
|
|
|
|
2025-06-06 10:56:22 +08:00
|
|
|
|
if not await g_pToolManager.isRegisteredByUid(uid):
|
2025-05-29 18:20:03 +08:00
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
await g_pDBService.userSoil.nextPhase(uid, num.result)
|
2025-10-10 10:58:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|