功能:实现 Group_Horse_Racing 群赛马插件

- 新增群赛马游戏插件,支持多人参与赛马竞猜

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-03 00:24:25 +08:00
parent 0fd011fa1e
commit ab1b25e239
9 changed files with 633 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
from typing import Tuple
from danding_bot.plugins.danding_points import points_api
from .config import Config
class PointsService:
def __init__(self, config: Config):
self.config = config
async def spend_bet_points(
self, user_id: str, amount: int, reason: str = "赛马下注"
) -> Tuple[bool, int]:
"""Deduct points for betting with retry."""
success, balance = await points_api.spend_points(
user_id, amount, "horse_race", reason
)
if not success:
success, balance = await points_api.spend_points(
user_id, amount, "horse_race", reason
)
return success, balance
async def refund_bet_points(
self, user_id: str, amount: int, reason: str = "取消报名退还"
) -> Tuple[bool, int]:
"""Refund bet points."""
return await points_api.add_points(user_id, amount, "horse_race", reason)
async def payout_winnings(
self, user_id: str, amount: int, odds: float
) -> Tuple[bool, int]:
"""Payout bet winnings."""
payout = int(amount * odds)
reason = f"下注获胜 ×{odds:.2f}"
return await points_api.add_points(user_id, payout, "horse_race", reason)
async def reward_participant(self, user_id: str) -> Tuple[bool, int]:
"""Reward race participant."""
return await points_api.add_points(
user_id,
self.config.PARTICIPANT_REWARD,
"horse_race",
"参赛奖励",
)
async def reward_champion(self, user_id: str) -> Tuple[bool, int]:
"""Reward race champion."""
return await points_api.add_points(
user_id,
self.config.CHAMPION_REWARD,
"horse_race",
"冠军奖励",
)
async def set_points(
self, user_id: str, amount: int, reason: str = "测试设置积分"
) -> Tuple[bool, int]:
"""Set user points (for testing)."""
return await points_api.set_points(user_id, amount, "horse_race", reason)
async def get_balance(self, user_id: str) -> int:
"""Get user balance."""
return await points_api.get_balance(user_id)