Files
WPSBot/games/base.py

181 lines
4.9 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积分进行炼金
2025-10-29 17:26:57 +08:00
### ⚡️ 冒险系统
- `.adventure` - 消耗1分钟进行冒险
- `.冒险` - 消耗1分钟进行冒险
- `.adventure 5` - 消耗5分钟进行冒险
- `.adventure abandon` - 放弃当前冒险按最低倍率结算已冒险时间
- `.adventure 放弃` - 放弃当前冒险按最低倍率结算已冒险时间
2025-10-29 17:26:57 +08:00
- `.adventure help` - 查看冒险帮助
2025-10-29 11:32:43 +08:00
### 🎁 积分赠送系统
- `.gift <用户ID> <积分数量> [消息]` - 赠送积分
- `.赠送 <用户ID> <积分数量> [消息]` - 赠送积分
- `. <用户ID> <积分数量> [消息]` - 赠送积分
2025-10-29 23:56:57 +08:00
### 🤖 AI对话系统
- `.ai <问题>` - 向AI提问支持多用户对话等待10秒后回答
- `.aiconfig host=xxx port=xxx model=xxx` - 配置Ollama服务地址和模型
2025-10-30 16:11:50 +08:00
### 🎰 赌场系统
- `.赌场 大小 open <最小> <最大> <赔率>` - 庄家开启大小游戏
- `.赌场 大小 bet </> <金额>` - 下注
- `.赌场 大小 status` - 查看状态
2025-10-30 17:27:15 +08:00
- `.赌场 大小 settle` - 庄家结算系统随机
- `.赌场 大小 cancel` - 庄家放弃游戏返还下注
2025-10-30 16:11:50 +08:00
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