{"id":34569956,"url":"https://github.com/moderras/walletbot","last_synced_at":"2026-05-28T03:01:59.532Z","repository":{"id":304514841,"uuid":"1019011018","full_name":"ModerRAS/WalletBot","owner":"ModerRAS","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-13T16:16:44.000Z","size":41,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-13T16:31:03.832Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ModerRAS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-13T14:45:08.000Z","updated_at":"2025-07-13T16:16:47.000Z","dependencies_parsed_at":"2025-07-13T16:31:19.923Z","dependency_job_id":"d857d2f4-c0ac-4b60-90c6-a1f59d90b6ab","html_url":"https://github.com/ModerRAS/WalletBot","commit_stats":null,"previous_names":["moderras/walletbot"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/ModerRAS/WalletBot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModerRAS%2FWalletBot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModerRAS%2FWalletBot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModerRAS%2FWalletBot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModerRAS%2FWalletBot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ModerRAS","download_url":"https://codeload.github.com/ModerRAS/WalletBot/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModerRAS%2FWalletBot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33592074,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-28T02:00:06.440Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-24T09:16:47.888Z","updated_at":"2026-05-28T03:01:59.527Z","avatar_url":"https://github.com/ModerRAS.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WalletBot 钱包机器人\n\n一个基于 Rust 和 Teloxide 的 Telegram 钱包管理机器人。\n\n## 功能特性\n\n- 📱 **智能消息解析**: 自动识别并解析钱包交易消息\n- 💰 **实时余额计算**: 智能计算钱包余额并自动更新\n- 🗄️ **数据库存储**: 使用 SQLite 存储交易记录和钱包信息\n- 🔄 **重复消息处理**: 防止重复处理相同的消息\n- 📊 **支持多种交易类型**: 支持出账、入账等多种交易类型\n- 🛡️ **错误处理**: 完善的错误处理和重试机制\n\n## 快速开始\n\n### 环境要求\n\n- Rust 1.70+\n- Telegram Bot Token\n\n### 安装\n\n```bash\ngit clone https://github.com/your-username/WalletBot.git\ncd WalletBot\ncargo build --release\n```\n\n### 配置\n\n1. 复制配置文件：\n```bash\ncp config.example .env\n```\n\n2. 编辑 `.env` 文件，设置你的 Telegram Bot Token：\n```\nTELEGRAM_BOT_TOKEN=your_bot_token_here\nDATABASE_URL=wallet.db\nBOT_NAME=WalletBot\nMAX_RETRY_ATTEMPTS=3\nPROCESSING_TIMEOUT=30\n```\n\n### 运行\n\n```bash\ncargo run\n```\n\n## 集成测试\n\n本项目包含了完整的集成测试系统，使用 Mock 对象来模拟 Telegram API。\n\n### 运行测试\n\n```bash\n# 运行所有集成测试\ncargo test --test integration_tests\n\n# 查看详细输出\ncargo test --test integration_tests -- --nocapture\n\n# 运行特定测试\ncargo test --test integration_tests test_message_parser\n```\n\n### 测试覆盖范围\n\n#### 基础功能测试\n- ✅ **消息解析器测试**: 测试钱包消息格式解析\n- ✅ **数据库操作测试**: 测试钱包创建、更新、交易记录\n- ✅ **Mock Bot API测试**: 测试消息发送、编辑、删除\n\n#### 业务逻辑测试\n- ✅ **完整消息流程测试**: 测试端到端的消息处理流程\n- ✅ **错误处理测试**: 测试各种无效消息格式的处理\n- ✅ **重复消息处理测试**: 测试消息去重机制\n\n#### 性能和并发测试\n- ✅ **性能测试**: 测试消息解析和数据库操作的性能\n- ✅ **并发操作测试**: 测试多线程环境下的安全性\n\n### 测试结果示例\n\n```\nrunning 8 tests\n✅ 并发操作测试通过\n✅ 性能测试结果:\n  - 1000次消息解析耗时: 28.3446ms\n  - 100次数据库操作耗时: 1.0065758s\n  - 平均单次解析耗时: 28.344µs\n  - 平均单次数据库操作耗时: 10.065758ms\n✅ 重复消息处理测试通过\n✅ 完整消息处理流程测试通过\n✅ Mock Bot API测试通过\n✅ 数据库操作测试通过\n✅ 消息解析器测试通过\n✅ 错误处理测试通过\n\ntest result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out\n```\n\n## 使用方法\n\n### 支持的消息格式\n\n```\n#钱包名称 #月份 #年份\n#交易类型 金额元\n```\n\n#### 示例\n\n```\n#支付宝 #12月 #2024年\n#出账 150.00元\n```\n\n机器人会自动计算余额并更新消息：\n\n```\n#支付宝 #12月 #2024年\n#出账 150.00元\n#总额 1000.00元\n```\n\n### 支持的命令\n\n- `/start` - 开始使用机器人\n- `/help` - 显示详细帮助信息\n- `/status` - 查看机器人运行状态  \n- `/reprocess` - 重新处理消息（回复特定消息使用）\n\n## 🎯 实际使用指南\n\n### 第一次使用\n\n1. **配置并启动机器人**\n   ```bash\n   # 复制配置文件\n   cp config.example .env\n   \n   # 编辑 .env 文件，设置你的 Bot Token\n   # TELEGRAM_BOT_TOKEN=your_token_here\n   \n   # 启动机器人\n   cargo run --release\n   ```\n\n2. **机器人启动成功后会显示**\n   ```\n   ✅ Bot connected successfully:\n     - Username: @your_bot_username  \n     - Name: WalletBot\n     - ID: 123456789\n   🎯 Starting message processing...\n   💡 Bot is now ready to receive messages!\n   ```\n\n3. **在 Telegram 中开始使用**\n   - 找到你的机器人\n   - 发送 `/start` 获取欢迎消息\n   - 发送 `/help` 查看使用说明\n\n### 交易记录流程\n\n1. **发送交易消息**\n   ```\n   #支付宝 #12月 #2024年\n   #出账 150.00元\n   ```\n\n2. **机器人自动处理**\n   - ✅ 解析消息格式\n   - 💾 记录到数据库  \n   - 📊 计算新余额\n   - ✏️ 编辑原消息添加总额\n   - 📨 发送确认消息\n\n3. **处理结果**\n   - 原消息被编辑为：\n     ```\n     #支付宝 #12月 #2024年\n     #出账 150.00元\n     #总额 850.00元\n     ```\n   - 收到确认消息：\n     ```\n     ✅ 交易已记录\n     📊 钱包：支付宝\n     💰 当前余额：850.00元\n     ```\n\n### 支持的交易类型 [[memory:3291148]]\n\n- `#出账` / `#支出` - 资金流出（减少余额）\n- `#入账` / `#收入` - 资金流入（增加余额）\n\n### 错误处理\n\n- **格式错误**: 发送详细的使用说明\n- **重复消息**: 发送\"消息已处理\"提示  \n- **处理失败**: 发送错误提示，建议重试\n\n### 多聊天支持\n\n钱包数据按聊天/频道完全隔离 [[memory:3291148]]：\n- 私聊、群聊、频道中的同名钱包余额独立\n- 每个聊天环境有独立的消息处理状态\n- 支持无限个聊天同时使用\n- `/help` - 显示帮助信息\n- `/status` - 查看机器人状态\n- `/reprocess` - 重新处理消息（回复目标消息）\n\n## 架构设计\n\n### 模块结构\n\n```\nsrc/\n├── bot/              # 机器人核心\n│   ├── handler.rs    # 消息处理器\n│   ├── commands.rs   # 命令处理\n│   └── traits.rs     # Bot API 抽象\n├── database/         # 数据库相关\n│   ├── models.rs     # 数据模型\n│   └── operations.rs # 数据库操作\n├── parser/           # 消息解析\n│   ├── message.rs    # 消息解析器\n│   └── regex.rs      # 正则表达式\n├── calculator/       # 余额计算\n│   └── balance.rs    # 余额计算器\n├── config/           # 配置管理\n│   └── settings.rs   # 配置设置\n├── error.rs          # 错误处理\n├── retry.rs          # 重试机制\n├── utils.rs          # 工具函数\n└── main.rs           # 主入口\n```\n\n### 测试架构\n\n```\ntests/\n└── integration_tests.rs  # 集成测试\n    ├── MockBotApi        # Mock Telegram API\n    ├── 基础功能测试        # 消息解析、数据库、Mock API\n    ├── 业务逻辑测试        # 完整流程、错误处理、去重\n    └── 性能并发测试        # 性能基准、并发安全\n```\n\n## 开发指南\n\n### 添加新功能\n\n1. 在相应模块中添加功能代码\n2. 在 `tests/integration_tests.rs` 中添加测试用例\n3. 运行测试确保不会破坏现有功能\n\n### 测试驱动开发\n\n```rust\n#[tokio::test]\n#[serial]\nasync fn test_new_feature() -\u003e Result\u003c()\u003e {\n    let db = create_test_db().await?;\n    let mock_bot = MockBotApi::new();\n    \n    // 测试逻辑\n    \n    println!(\"✅ 新功能测试通过\");\n    Ok(())\n}\n```\n\n### 性能优化\n\n- 使用 `cargo test --test integration_tests test_performance` 检查性能\n- 优化数据库查询和消息解析逻辑\n- 监控并发操作的安全性\n\n## 贡献指南\n\n1. Fork 本项目\n2. 创建功能分支 (`git checkout -b feature/amazing-feature`)\n3. 提交更改 (`git commit -m 'Add amazing feature'`)\n4. 推送到分支 (`git push origin feature/amazing-feature`)\n5. 创建 Pull Request\n\n## 许可证\n\n本项目采用 MIT 许可证。详见 [LICENSE](LICENSE) 文件。\n\n## 支持\n\n如果您遇到问题或有建议，请：\n\n1. 查看 [集成测试文档](INTEGRATION_TESTS.md)\n2. 创建 Issue 描述问题\n3. 提交 Pull Request 修复问题\n\n---\n\n**注意**: 这是一个演示项目，用于展示 Rust 中的集成测试实现。在生产环境中使用前，请确保正确配置所有安全设置。 ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoderras%2Fwalletbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoderras%2Fwalletbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoderras%2Fwalletbot/lists"}