Compare commits

...

35 Commits

Author SHA1 Message Date
Xiaolan Bot
2338c375b9 docs: replace hardcoded Telegram owner id with placeholder 2026-03-04 13:19:10 +08:00
Xiaolan Bot
205de16479 perf(update): pin default remote URL and offload blocking update/currency ops 2026-02-25 16:22:53 +08:00
Xiaolan Bot
0904acad4e refactor(ui): unify message formatting to HTML and clean imports 2026-02-25 16:10:37 +08:00
Xiaolan Bot
c7ebb00145 fix(update): auto-detect remote/branch when AUTO_UPDATE_REMOTE is unset 2026-02-25 15:56:37 +08:00
Xiaolan Bot
214dadad45 feat: add /update command for owner-only self-update and restart 2026-02-25 15:21:47 +08:00
Xiaolan Bot
23feb6ba1b docs: install deps via requirements.txt 2026-02-25 12:47:54 +08:00
Xiaolan Bot
895ffbcb32 fix: replace markdown markers in HTML reminder templates 2026-02-25 11:00:45 +08:00
Xiaolan Bot
14c3a30806 fix(ui): remove missing emoji from chart title and use simpler wording 2026-02-23 01:48:55 +08:00
Xiaolan Bot
ebfc342736 fix(bug): remove local matplotlib import shadowing global plt in stats 2026-02-23 01:37:58 +08:00
Xiaolan Bot
1d0fe1cdf3 fix(bug): remove invalid escape_html import from telegram.helpers 2026-02-23 01:35:26 +08:00
Xiaolan Bot
fb8a5521a9 perf: offload heavy blocking I/O (matplotlib, pandas) to asyncio threads 2026-02-23 00:05:50 +08:00
Xiaolan Bot
2670ca96c7 fix(ui): migrate parse_mode from MarkdownV2 to HTML to prevent parsing crashes 2026-02-22 23:56:36 +08:00
Xiaolan Bot
3711dd362b fix(security): sanitize DB field formatting and fix cron job duplication 2026-02-22 23:52:50 +08:00
Xiaolan Bot
81840dfa31 chore: Add requirements.txt and EXCHANGE_API_KEY startup warning. 2026-02-22 23:45:13 +08:00
Xiaolan Bot
31b1235d20 fix(stats): Optimize chart UI, dateparser timezone, and pandas apply performance. Improve font download stability. 2026-02-22 23:43:34 +08:00
Xiaolan Bot
54d46d7e6b Polish stats chart layout and readability 2026-02-22 22:18:43 +08:00
Xiaolan Bot
ee1a5b59b0 feat: redesign stats chart with donut + comparison bars 2026-02-22 22:01:06 +08:00
Xiaolan Bot
f064f751f0 fix: harden callback payload parsing in add/edit flows 2026-02-22 11:53:22 +08:00
Xiaolan Bot
5eebf4bf66 fix: restore clear helper and unify notes/skip expiry handling 2026-02-22 11:44:13 +08:00
Xiaolan Bot
210af75e2c fix: guard add-sub conversation against expired state 2026-02-22 11:39:25 +08:00
Xiaolan Bot
d212d73c2a refactor: centralize enum validation for unit and renewal type 2026-02-22 11:33:41 +08:00
Xiaolan Bot
052966e07c fix: validate name/notes constraints in edit flow 2026-02-22 11:30:22 +08:00
Xiaolan Bot
095e88cad3 refactor: add input length guards for add/edit/import flows 2026-02-22 11:07:42 +08:00
Xiaolan Bot
276bb5fc83 fix: restore get_subs_list_keyboard helper 2026-02-22 02:54:56 +08:00
Xiaolan Bot
decb9c12c1 hardening: remove broad session clears and validate add flow inputs 2026-02-22 02:43:26 +08:00
Xiaolan Bot
ec06c5fac3 chore: tighten conversation entry callback patterns 2026-02-22 02:22:26 +08:00
Xiaolan Bot
ced65fc4da chore: tighten conversation fallback callback patterns 2026-02-22 02:17:00 +08:00
Xiaolan Bot
36b136289c hardening: close low-risk gaps and improve import validation 2026-02-22 02:11:26 +08:00
Xiaolan Bot
98a863f567 docs: add comprehensive README for open-source usage 2026-02-22 02:07:50 +08:00
Xiaolan Bot
15f9ceb841 refactor: use tempfile for import/export/stats artifacts 2026-02-22 01:48:44 +08:00
Xiaolan Bot
8601e78e17 hardening: validate ownership on entry points and failed updates 2026-02-22 01:41:46 +08:00
Xiaolan Bot
530d81b565 refactor: harden field mapping and sqlite boolean toggles 2026-02-22 01:33:02 +08:00
Xiaolan Bot
8354e38e89 fix: tighten callback pattern for id-based category routing 2026-02-22 01:27:11 +08:00
Xiaolan Bot
97bcee7258 fix: make category callbacks id-based and tighten ownership checks 2026-02-22 01:26:24 +08:00
Xiaolan Bot
db8257fdde fix: harden subscription callbacks and settings updates 2026-02-22 01:17:20 +08:00
4 changed files with 928 additions and 218 deletions

View File

@@ -1,2 +1,5 @@
TELEGRAM_TOKEN=""
EXCHANGE_API_KEY=""
UPDATE_OWNER_ID=""
AUTO_UPDATE_REMOTE="https://git.llc/zimk/SubMind.git"
AUTO_UPDATE_BRANCH="main"

148
README.md
View File

@@ -1 +1,147 @@
power by gemini
# SubMind
一个基于 Telegram 的订阅管理机器人,帮助你记录订阅、设置提醒、查看支出统计并导入/导出数据。
## 功能特性
- 添加订阅(名称、费用、货币、分类、到期日、周期、续费方式、备注)
- 📋 列出订阅并查看详情
- 🗂️ 按分类浏览订阅
- ✏️ 编辑订阅信息
- 🗑️ 删除订阅
- 🔔 提醒设置(到期日提醒、提前 N 天提醒、手动续费一键确认)
- 📊 统计图(按分类汇总月均支出)
- 📥 CSV 导入
- 📤 CSV 导出
- 💱 多货币换算(支持缓存汇率)
## 技术栈
- Python 3.10+
- [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot)
- SQLite
- pandas + matplotlib
- dateparser
## 快速开始
### 1) 克隆项目
```bash
git clone https://github.com/zkysimon/SubMind.git
cd SubMind
```
### 2) 安装依赖
建议使用虚拟环境:
```bash
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -U pip
pip install -r requirements.txt
```
### 3) 配置环境变量
复制并填写 `.env`
```bash
cp .env.example .env
```
`.env` 示例:
```env
TELEGRAM_TOKEN="<YOUR_TELEGRAM_BOT_TOKEN>"
EXCHANGE_API_KEY="<YOUR_EXCHANGE_API_KEY>"
UPDATE_OWNER_ID="<YOUR_TELEGRAM_USER_ID>"
AUTO_UPDATE_REMOTE="https://git.llc/zimk/SubMind.git"
AUTO_UPDATE_BRANCH="main"
```
说明:
- `TELEGRAM_TOKEN` 必填。
- `EXCHANGE_API_KEY` 可选(不填时不做在线汇率转换)。
- `UPDATE_OWNER_ID` 可选(建议配置为你的 Telegram 用户 ID仅该用户可执行 `/update`)。
- `AUTO_UPDATE_REMOTE` 可选(默认 `https://git.llc/zimk/SubMind.git`)。
- `AUTO_UPDATE_BRANCH` 可选(默认 `main`)。
### 4) 运行
```bash
python SubMind.py
```
首次启动会自动初始化数据库(默认 `submind.db`)。
## Bot 命令
- `/start` 开始使用
- `/add_sub` 添加订阅
- `/list_subs` 查看所有订阅
- `/list_categories` 按分类查看
- `/stats` 查看统计图
- `/import` 导入 CSV
- `/export` 导出 CSV
- `/set_currency <CODE>` 设置主货币(例如 `USD``CNY`
- `/update` 拉取最新代码、安装依赖并自动重启(仅 `UPDATE_OWNER_ID` 指定用户可用)
- `/help` 帮助
- `/cancel` 取消当前流程
## CSV 导入格式
导入文件需包含以下列:
- `name`
- `cost`
- `currency`
- `category`
- `next_due`
- `frequency_unit``day` / `week` / `month` / `year`
- `frequency_value`(正整数)
- `renewal_type``auto` / `manual`
- `notes`(可选)
示例:
```csv
name,cost,currency,category,next_due,frequency_unit,frequency_value,renewal_type,notes
Netflix,15.99,USD,影音,2026-03-01,month,1,auto,
VPS,60,CNY,开发,2026-03-12,month,1,manual,生产环境
```
## 数据与迁移
- 使用 SQLite文件`submind.db`)。
- 启动时自动执行兼容性检查和必要字段补齐。
- 建议升级前先备份数据库:
```bash
cp submind.db submind.db.bak
```
## 常见问题
### 1) 统计图中文乱码怎么办?
程序会尝试下载中文字体到 `fonts/` 目录;若网络不可达,可手动放置字体文件。
### 2) 为什么汇率没变化?
请检查 `EXCHANGE_API_KEY` 是否配置正确。未配置时会使用原货币金额。
### 3) 旧消息按钮点不动?
更新后建议重新执行 `/list_categories``/list_subs` 刷新最新按钮。
## 安全说明
- 项目已对订阅编辑/提醒等关键路径做用户归属校验(`user_id`)。
- 数据库操作使用参数化查询,并对可编辑字段做白名单约束。
## License
可按你的开源策略补充(例如 MIT
---
如果这个项目对你有帮助,欢迎 Star ⭐

File diff suppressed because it is too large Load Diff

7
requirements.txt Normal file
View File

@@ -0,0 +1,7 @@
python-telegram-bot>=20.0
pandas
matplotlib
python-dateutil
dateparser
python-dotenv
requests