blob: 7c4a828651cdec6a8c82369ef086de1613e34657 [file] [log] [blame] [raw]
#!/usr/bin/env python3
"""
Bot名字配置功能演示脚本
展示如何为不同的Bot实例配置不同的名字和行为
"""
import sys
from pathlib import Path
# 添加src目录到Python路径
current_dir = Path(__file__).parent
project_root = current_dir.parent
src_dir = project_root / "src"
sys.path.insert(0, str(src_dir))
from claude_agent.utils.config import get_config_manager
from claude_agent.telegram.message_handler import GroupParticipationManager
def demo_configuration_override():
"""演示配置覆盖功能"""
print("🤖 Bot名字配置功能演示")
print("=" * 60)
# 测试不同配置文件
configs_to_test = [
("local", "本地开发配置"),
("chatbot", "聊天机器人配置"),
("helpbot", "助手机器人配置"),
("default", "默认配置")
]
print("\n📋 各配置文件的Bot名字设置:")
print("-" * 60)
for config_name, description in configs_to_test:
try:
config = get_config_manager(config_name)
telegram_config = config.get_telegram_config()
group_config = telegram_config.get('group_participation', {})
bot_names = group_config.get('bot_names', [])
participation_range = group_config.get('random_participation_range', [1, 10])
print(f"\n🔧 {description} ({config_name}.toml):")
print(f" Bot名字: {bot_names}")
print(f" 随机参与范围: {participation_range}")
except Exception as e:
print(f"❌ {config_name} 配置加载失败: {e}")
print("\n" + "=" * 60)
def demo_message_detection():
"""演示消息检测功能"""
print("\n🔍 消息检测功能演示")
print("=" * 60)
# 创建不同配置的参与管理器
managers = {
"ChatBot": GroupParticipationManager(
bot_names=['chatbot', 'ChatBot', '小聊', '聊天机器人'],
participation_range=[3, 8]
),
"HelpBot": GroupParticipationManager(
bot_names=['helpbot', 'HelpBot', '助手', '小助手', 'help'],
participation_range=[10, 20]
),
"Claude": GroupParticipationManager(
bot_names=['claude', 'Claude', '克劳德', 'AI'],
participation_range=[5, 12]
)
}
# 测试消息
test_messages = [
"hey chatbot, how are you?",
"I need help from the 小聊",
"Claude can you help me?",
"助手你好,请帮助我",
"helpbot please assist",
"this is just a normal message",
"AI能帮我吗?",
"克劳德你在吗?",
"聊天机器人,你好!"
]
print("\n📝 不同消息的检测结果:")
print("-" * 60)
for msg in test_messages:
print(f"\n💬 消息: \"{msg}\"")
for bot_name, manager in managers.items():
detected = manager.is_name_mentioned(msg)
emoji = "✅" if detected else "❌"
print(f" {emoji} {bot_name}: {detected}")
def demo_participation_ranges():
"""演示随机参与范围功能"""
print("\n🎲 随机参与范围演示")
print("=" * 60)
# 创建不同配置的管理器
configs = [
("活跃Bot", [2, 5]),
("普通Bot", [5, 10]),
("保守Bot", [10, 20])
]
for name, range_config in configs:
manager = GroupParticipationManager(participation_range=range_config)
print(f"\n🤖 {name} (范围: {range_config}):")
# 模拟5次重置,显示随机阈值
thresholds = []
for i in range(5):
manager.reset_counter(f"test_chat_{i}")
threshold = manager._trigger_thresholds[f"test_chat_{i}"]
thresholds.append(threshold)
print(f" 生成的阈值样本: {thresholds}")
print(f" 平均值: {sum(thresholds)/len(thresholds):.1f}")
def demo_real_world_scenario():
"""演示真实场景应用"""
print("\n🌍 真实场景应用演示")
print("=" * 60)
print("\n📚 使用场景说明:")
print("1. 聊天群组Bot - 更活跃,经常参与对话")
print("2. 技术支持Bot - 专注于帮助和支持")
print("3. 通用助手Bot - 平衡的参与度")
print("\n⚙️ 配置建议:")
print("""
# configs/chatbot.toml - 聊天群组Bot
[telegram.group_participation]
bot_names = ["chatbot", "小聊", "机器人"]
random_participation_range = [3, 8] # 更频繁参与
# configs/support.toml - 技术支持Bot
[telegram.group_participation]
bot_names = ["support", "助手", "客服", "help"]
random_participation_range = [10, 20] # 更保守参与
# configs/assistant.toml - 通用助手Bot
[telegram.group_participation]
bot_names = ["assistant", "AI", "智能助手"]
random_participation_range = [5, 12] # 平衡参与
""")
print("\n🚀 启动不同Bot的命令:")
print(" CLAUDE_CONFIG=chatbot python scripts/start_telegram_bot.py")
print(" CLAUDE_CONFIG=support python scripts/start_telegram_bot.py")
print(" CLAUDE_CONFIG=assistant python scripts/start_telegram_bot.py")
def main():
"""主演示函数"""
try:
demo_configuration_override()
demo_message_detection()
demo_participation_ranges()
demo_real_world_scenario()
print("\n" + "=" * 60)
print("✅ Bot名字配置功能演示完成!")
print("\n💡 关键特性:")
print(" - 每个Bot实例可以有独立的名字列表")
print(" - 可配置随机参与的频率范围")
print(" - 支持中英文混合名字检测")
print(" - 完全基于配置文件,无需修改代码")
except Exception as e:
print(f"\n❌ 演示过程中出现错误: {e}")
if __name__ == "__main__":
main()