✨ 添加签到功能
🐛 修复默认使用格林威治时间而不是北京时间的BUG
This commit is contained in:
+40
-14
@@ -1,5 +1,3 @@
|
||||
from datetime import date, datetime, timedelta
|
||||
|
||||
from nonebot.adapters import Event, MessageTemplate
|
||||
from nonebot.rule import to_me
|
||||
from nonebot_plugin_alconna import (Alconna, AlconnaMatch, AlconnaQuery, Args,
|
||||
@@ -12,9 +10,12 @@ from zhenxun.configs.config import BotConfig
|
||||
from zhenxun.services.log import logger
|
||||
from zhenxun.utils.message import MessageUtils
|
||||
|
||||
from .config import g_bSignStatus
|
||||
from .dbService import g_pDBService
|
||||
from .farm.farm import g_pFarmManager
|
||||
from .farm.shop import g_pShopManager
|
||||
from .json import g_pJsonManager
|
||||
from .tool import g_pToolManager
|
||||
|
||||
|
||||
async def isRegisteredByUid(uid: str) -> bool:
|
||||
@@ -136,7 +137,7 @@ diuse_farm = on_alconna(
|
||||
Subcommand("buy-point", Args["num?", int], help_text="购买农场币"),
|
||||
#Subcommand("sell-point", Args["num?", int], help_text="转换金币")
|
||||
Subcommand("change-name", Args["name?", str], help_text="更改农场名"),
|
||||
Subcommand("sing-in", help_text="农场签到"),
|
||||
Subcommand("sign-in", help_text="农场签到"),
|
||||
),
|
||||
priority=5,
|
||||
block=True,
|
||||
@@ -168,7 +169,7 @@ async def _(session: Uninfo):
|
||||
|
||||
info = await g_pFarmManager.drawDetailFarmByUid(uid)
|
||||
|
||||
await MessageUtils.alc_forward_msg([info], session.self_id, BotConfig.self_nickname).send(reply_to=True)
|
||||
await MessageUtils.alc_forward_msg([info], session.self_id, BotConfig.self_nickname).send()
|
||||
|
||||
diuse_farm.shortcut(
|
||||
"我的农场币",
|
||||
@@ -446,30 +447,55 @@ async def _(session: Uninfo, name: Match[str]):
|
||||
else:
|
||||
await MessageUtils.build_message("更新用户名失败!").send(reply_to=True)
|
||||
|
||||
reclamation = on_alconna(
|
||||
Alconna("农场签到"),
|
||||
priority=5,
|
||||
block=True,
|
||||
diuse_farm.shortcut(
|
||||
"农场签到",
|
||||
command="我的农场",
|
||||
arguments=["sign-in"],
|
||||
prefix=True,
|
||||
)
|
||||
|
||||
@reclamation.handle()
|
||||
@diuse_farm.assign("sign-in")
|
||||
async def _(session: Uninfo):
|
||||
uid = str(session.user.id)
|
||||
|
||||
if await isRegisteredByUid(uid) == False:
|
||||
return
|
||||
|
||||
toDay = date.today()
|
||||
#判断签到是否正常加载
|
||||
if g_bSignStatus == False:
|
||||
await MessageUtils.build_message("签到功能异常!").send()
|
||||
|
||||
return
|
||||
|
||||
toDay = g_pToolManager.dateTime().date().today()
|
||||
message = ""
|
||||
status = await g_pDBService.userSign.sign(uid, toDay.strftime("%Y-%m-%d"))
|
||||
|
||||
if status == True:
|
||||
message = "签到成功"
|
||||
#如果完成签到
|
||||
if status == 1 or status == 2:
|
||||
#获取签到总天数
|
||||
signDay = await g_pDBService.userSign.getUserSignCountByDate(uid, toDay.strftime("%Y-%m"))
|
||||
|
||||
exp, point = await g_pDBService.userSign.getUserSignRewardByDate(uid, toDay.strftime("%Y-%m-%d"))
|
||||
|
||||
img = await g_pDBService.userSign.drawSignCalendarImage(uid, toDay.year, toDay.month)
|
||||
message += f"签到成功!累计签到天数:{signDay}\n获得经验{exp},获得金币{point}"
|
||||
|
||||
await MessageUtils.build_message(img).send()
|
||||
reward = g_pJsonManager.m_pSign['continuou'].get(f"{signDay}", None)
|
||||
|
||||
if reward:
|
||||
extraPoint = reward.get('point', 0)
|
||||
extraExp = reward.get('exp', 0)
|
||||
|
||||
plant = reward.get('plant', {})
|
||||
|
||||
message += f"\n\n成功领取累计签到奖励:\n额外获得经验{extraExp},额外获得金币{extraPoint}"
|
||||
|
||||
if plant:
|
||||
for key, value in plant.items():
|
||||
message += f"\n获得{key}种子 * {value}"
|
||||
else:
|
||||
message = "签到失败!未知错误"
|
||||
|
||||
await MessageUtils.build_message(message).send()
|
||||
|
||||
# await MessageUtils.alc_forward_msg([info], session.self_id, BotConfig.self_nickname).send(reply_to=True)
|
||||
|
||||
Reference in New Issue
Block a user