Files
WPSBot/games/base.py

167 lines
4.2 KiB
Python
Raw Normal View History

2025-10-28 13:00:35 +08:00
"""游戏基类"""
import logging
from abc import ABC, abstractmethod
from core.database import get_db
logger = logging.getLogger(__name__)
class BaseGame(ABC):
"""游戏基类"""
def __init__(self):
"""初始化游戏"""
self.db = get_db()
@abstractmethod
async def handle(self, command: str, chat_id: int, user_id: int) -> str:
"""处理游戏指令
Args:
command: 完整指令
chat_id: 会话ID
user_id: 用户ID
Returns:
回复消息
"""
raise NotImplementedError
@abstractmethod
def get_help(self) -> str:
"""获取帮助信息
Returns:
帮助文本
"""
raise NotImplementedError
def get_help_message() -> str:
"""获取总体帮助信息"""
help_text = """## 🎮 WPS游戏机器人帮助
### 🎲 骰娘系统
- `.r XdY` - 掷骰子.r 1d20
- `.r XdY+Z` - 带修正掷骰.r 2d6+3
### ✊ 石头剪刀布
- `.rps 石头` - 出石头
- `.rps 剪刀` - 出剪刀
- `.rps ` - 出布
- `.rps stats` - 查看战绩
### 🔮 运势占卜
- `.fortune` - 今日运势
- `.运势` - 今日运势
### 🔢 猜数字游戏
- `.guess start` - 开始游戏
- `.guess 数字` - 猜测数字
- `.guess stop` - 结束游戏
### 📝 问答游戏
- `.quiz` - 随机问题
- `.quiz 答案` - 回答问题
2025-10-28 16:12:32 +08:00
### 🀄 成语接龙
- `.idiom start [成语]` - 开始游戏
- `.idiom [成语]` - 接龙
- `.idiom [成语] @某人` - 接龙并指定下一位
- `.idiom stop` - 结束游戏
- `.idiom status` - 查看状态
2025-10-28 16:25:04 +08:00
- `.idiom reject [词语]` - 拒绝词语加入黑名单仅发起人
- `.idiom blacklist` - 查看黑名单
2025-10-28 16:12:32 +08:00
2025-10-28 17:22:49 +08:00
### ⚫ 五子棋
- `.gomoku challenge` - 发起挑战
- `.gomoku accept` - 接受挑战
2025-10-28 17:22:49 +08:00
- `.gomoku A1` - 落子
- `.gomoku show` - 显示棋盘
- `.gomoku resign` - 认输
- `.gomoku list` - 列出所有对战
- `.gomoku stats` - 查看战绩
2025-10-29 11:32:43 +08:00
### 💎 积分系统
- `.points` - 查看个人积分
- `.积分` - 查看个人积分
- `.checkin` - 每日签到
- `.签到` - 每日签到
- `.打卡` - 每日签到
- `.points leaderboard` - 积分排行榜
### ⚗️ 炼金系统
- `.alchemy` - 消耗10积分进行炼金
- `.炼金` - 消耗10积分进行炼金
- `.alchemy 20` - 消耗20积分进行炼金
- `.alchemy 50` - 消耗50积分进行炼金
- `.alchemy stats` - 查看炼金统计
- `.alchemy records` - 查看炼金记录
### 🎁 积分赠送系统
- `.gift <用户ID> <积分数量> [消息]` - 赠送积分
- `.赠送 <用户ID> <积分数量> [消息]` - 赠送积分
- `. <用户ID> <积分数量> [消息]` - 赠送积分
- `.gift stats` - 查看赠送统计
- `.gift sent` - 查看发送记录
- `.gift received` - 查看接收记录
2025-10-28 13:00:35 +08:00
### 其他
- `.help` - 显示帮助
- `.stats` - 查看个人统计
---
💡 提示@机器人 + 指令即可使用
"""
return help_text
def get_stats_message(user_id: int) -> str:
"""获取用户统计信息"""
db = get_db()
cursor = db.conn.cursor()
# 获取所有游戏统计
cursor.execute(
"SELECT game_type, wins, losses, draws, total_plays FROM game_stats WHERE user_id = ?",
(user_id,)
)
stats = cursor.fetchall()
if not stats:
return "📊 你还没有游戏记录哦~快来玩游戏吧!"
# 构建统计信息
text = "## 📊 你的游戏统计\n\n"
game_names = {
'rps': '✊ 石头剪刀布',
'guess': '🔢 猜数字',
2025-10-28 16:12:32 +08:00
'quiz': '📝 问答游戏',
2025-10-28 17:22:49 +08:00
'idiom': '🀄 成语接龙',
'gomoku': '⚫ 五子棋'
2025-10-28 13:00:35 +08:00
}
for row in stats:
game_type = row[0]
wins = row[1]
losses = row[2]
draws = row[3]
total = row[4]
game_name = game_names.get(game_type, game_type)
win_rate = (wins / total * 100) if total > 0 else 0
text += f"### {game_name}\n"
text += f"- 总局数:{total}\n"
text += f"- 胜利:{wins}\n"
text += f"- 失败:{losses}\n"
if draws > 0:
text += f"- 平局:{draws}\n"
text += f"- 胜率:{win_rate:.1f}%\n\n"
return text