feat(sign_in): 新增独立每日签到插件,与抽卡签到共用同一份签到数据
- 群聊命令「签到」(别名: 每日签到/打卡),白名单群聊或管理员可用 - 复用 xapi /bot/gacha/sign-in + /bot/points/add,与抽卡/WPF 共用 bot_gacha_daily_sign_in 表 - 积分随机 1-100,流水沿用 gacha_sign/抽卡签到;先到先得,重复签到提示已签到 - 新增 10 个单元测试,ruff 通过;更新 PLUGINS.md / README.md
This commit is contained in:
72
danding_bot/plugins/danding_sign_in/__init__.py
Normal file
72
danding_bot/plugins/danding_sign_in/__init__.py
Normal file
@@ -0,0 +1,72 @@
|
||||
"""独立每日签到插件。
|
||||
|
||||
用户发送「签到」即可完成每日签到并领取积分(每天一次)。
|
||||
与 onmyoji_gacha 抽卡签到、WPF 客户端签到共用 xapi `bot_gacha_daily_sign_in`
|
||||
签到数据:每天每用户仅一次,任一入口先到先得,后到者提示已签到。
|
||||
"""
|
||||
|
||||
from nonebot import on_command, require
|
||||
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, MessageEvent
|
||||
from nonebot.plugin import PluginMetadata
|
||||
|
||||
from .config import Config
|
||||
from .api import SignInAPI
|
||||
from .rules import check_permission
|
||||
from .service import perform_daily_sign_in
|
||||
|
||||
require("danding_bot.plugins.danding_points")
|
||||
from danding_bot.plugins.danding_points import points_api # noqa: E402
|
||||
|
||||
__plugin_meta__ = PluginMetadata(
|
||||
name="每日签到",
|
||||
description="独立每日签到命令,与抽卡签到共用同一份签到数据",
|
||||
usage="发送「签到」即可完成每日签到并领取积分(每天一次)",
|
||||
type="application",
|
||||
config=Config,
|
||||
extra={
|
||||
"required_plugins": ["danding_bot.plugins.danding_points"],
|
||||
},
|
||||
)
|
||||
|
||||
config = Config()
|
||||
sign_in_api = SignInAPI(config)
|
||||
|
||||
sign_in_matcher = on_command("签到", aliases={"每日签到", "打卡"}, priority=5, rule=check_permission())
|
||||
|
||||
|
||||
@sign_in_matcher.handle()
|
||||
async def handle_sign_in(bot: Bot, event: MessageEvent):
|
||||
user_id = str(event.user_id)
|
||||
sender = event.sender
|
||||
user_name = ""
|
||||
if sender:
|
||||
user_name = sender.card if isinstance(event, GroupMessageEvent) else sender.nickname
|
||||
user_name = user_name or "用户"
|
||||
|
||||
result = await perform_daily_sign_in(
|
||||
sign_in_api=sign_in_api,
|
||||
points_api=points_api,
|
||||
user_id=user_id,
|
||||
points_min=config.SIGN_IN_POINTS_MIN,
|
||||
points_max=config.SIGN_IN_POINTS_MAX,
|
||||
source=config.SIGN_IN_SOURCE,
|
||||
reason=config.SIGN_IN_REASON,
|
||||
)
|
||||
|
||||
if not result["success"]:
|
||||
await sign_in_matcher.finish(f"{user_name} ❌ {result['message']}")
|
||||
|
||||
if result["already_signed"]:
|
||||
await sign_in_matcher.finish(
|
||||
f"{user_name} 📅 今天已经签到过啦\n"
|
||||
f"🎁 今日签到积分:{result['points']}\n"
|
||||
f"(抽卡/WPF 签到同样计入每日一次)\n"
|
||||
f"明天再来吧~"
|
||||
)
|
||||
return
|
||||
|
||||
await sign_in_matcher.finish(
|
||||
f"{user_name} 📅 每日签到成功!\n"
|
||||
f"🎁 获得积分:{result['points']}\n"
|
||||
f"💰 当前积分:{result['balance']}"
|
||||
)
|
||||
Reference in New Issue
Block a user