docs: 更新 README 和游戏引擎

- 更新 README 中的 Twitch 配置说明
- 更新游戏引擎相关代码
This commit is contained in:
empty
2026-01-01 19:23:21 +08:00
parent 0cd7c9c4d9
commit 1f29010de6
2 changed files with 88 additions and 9 deletions

View File

@@ -942,3 +942,32 @@ class GameEngine:
"""Stop the game engine."""
self._running = False
logger.info("Game engine stopping...")
async def process_command(self, user: str, text: str) -> None:
"""Process a command from Twitch chat."""
# Use the existing process_comment method to handle commands
await self.process_comment(user, text)
async def process_bits(self, user: str, amount: int) -> None:
"""Process Twitch bits and convert to game gold."""
# 1 Bit = 1 Gold conversion rate
gold_added = amount
with get_db_session() as db:
user_obj = self._get_or_create_user(db, user)
user_obj.gold += gold_added
await self._broadcast_event(EventType.USER_UPDATE, {
"user": user,
"gold": user_obj.gold,
"message": f"{user} received {gold_added} gold from {amount} bits!"
})
# Also broadcast a special bits event for UI effects
await self._broadcast_event("bits_received", {
"user": user,
"bits": amount,
"gold": gold_added
})
logger.info(f"Processed bits: {user} -> {amount} bits -> {gold_added} gold")