#!/usr/bin/env python3 """测试funstat BOT的翻页按钮""" import sys sys.path.insert(0, '.') from server import FunstatMCPServer import asyncio async def main(): server = FunstatMCPServer() await server.initialize() print("📤 发送搜索命令...") await server.client.send_message(server.bot_entity, '/search 翻译') # 等待响应 await asyncio.sleep(3) # 获取最新消息 messages = await server.client.get_messages(server.bot_entity, limit=1) msg = messages[0] print(f"\n📨 消息内容:\n{msg.text}\n") # 检查是否有按钮 if msg.reply_markup: print("✅ 发现按钮!") print(f" 类型: {type(msg.reply_markup)}") if hasattr(msg.reply_markup, 'rows'): print(f" 按钮行数: {len(msg.reply_markup.rows)}") for i, row in enumerate(msg.reply_markup.rows): print(f"\n 第 {i+1} 行:") for j, button in enumerate(row.buttons): print(f" 按钮 {j+1}: {button.text}") if hasattr(button, 'data'): print(f" 数据: {button.data}") # 尝试点击第一个按钮 if len(msg.reply_markup.rows) > 0: print("\n🖱️ 尝试点击第一个按钮...") try: await msg.click(0) # 点击第一个按钮 await asyncio.sleep(2) # 获取新消息 new_messages = await server.client.get_messages(server.bot_entity, limit=1) new_msg = new_messages[0] print(f"\n📨 点击后的新消息:\n{new_msg.text}\n") if new_msg.reply_markup: print("✅ 新消息也有按钮") for i, row in enumerate(new_msg.reply_markup.rows): for j, button in enumerate(row.buttons): print(f" 按钮: {button.text}") except Exception as e: print(f"❌ 点击失败: {e}") else: print(" 没有rows属性") else: print("❌ 没有发现按钮") await server.client.disconnect() if __name__ == '__main__': asyncio.run(main())