feat: add postgres storage and remote sync

This commit is contained in:
2025-11-07 16:59:28 +08:00
parent c4be264ea5
commit d0ba2b188b
32 changed files with 1101 additions and 1170 deletions

View File

@@ -2,10 +2,17 @@
"""
查看与 BOT 的历史消息
"""
import requests
import json
import os
BOT_TOKEN = "8410096573:AAFLJbWUp2Xog0oeoe7hfBlVqR7ChoSl9Pg"
import requests
from env_loader import load_env
load_env()
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
if not BOT_TOKEN:
raise RuntimeError("请在 .env 中设置 TELEGRAM_BOT_TOKEN")
BASE_URL = f"https://api.telegram.org/bot{BOT_TOKEN}"
def get_updates(offset=None, limit=100):

View File

@@ -2,10 +2,17 @@
"""
检查并配置 Webhook
"""
import requests
import json
import os
BOT_TOKEN = "8410096573:AAFLJbWUp2Xog0oeoe7hfBlVqR7ChoSl9Pg"
import requests
from env_loader import load_env
load_env()
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
if not BOT_TOKEN:
raise RuntimeError("请在 .env 中设置 TELEGRAM_BOT_TOKEN")
BASE_URL = f"https://api.telegram.org/bot{BOT_TOKEN}"
def get_webhook_info():

View File

@@ -9,16 +9,22 @@ Telethon Session 创建脚本(安全版本)
import asyncio
import os
from pathlib import Path
from telethon import TelegramClient
from telethon.errors import SessionPasswordNeededError
# 你的 API 凭证
API_ID = 24660516
API_HASH = "eae564578880a59c9963916ff1bbbd3a"
from env_loader import load_env
# Session 文件保存位置 - 独立的安全目录
SESSION_DIR = Path.home() / "telegram_sessions"
SESSION_PATH = SESSION_DIR / "funstat_bot"
load_env()
API_ID = int(os.getenv("TELEGRAM_API_ID", "0") or 0)
API_HASH = os.getenv("TELEGRAM_API_HASH", "")
SESSION_BASE = os.path.expanduser(os.getenv("TELEGRAM_SESSION_PATH", str(Path.home() / "telegram_sessions" / "funstat_bot")))
SESSION_PATH = Path(SESSION_BASE)
SESSION_DIR = SESSION_PATH.parent
if not API_ID or not API_HASH:
raise RuntimeError("请在 .env 中设置 TELEGRAM_API_ID 和 TELEGRAM_API_HASH")
async def create_session():
"""创建 Telegram session 文件"""
@@ -29,7 +35,7 @@ async def create_session():
print()
# 创建 session 目录
SESSION_DIR.mkdir(exist_ok=True)
SESSION_DIR.mkdir(parents=True, exist_ok=True)
print(f"📁 Session 目录: {SESSION_DIR}")
print()

11
scripts/env_loader.py Normal file
View File

@@ -0,0 +1,11 @@
from pathlib import Path
from dotenv import load_dotenv
def load_env():
base_dir = Path(__file__).resolve().parents[1]
dotenv_path = base_dir / ".env"
if dotenv_path.exists():
load_dotenv(dotenv_path)

View File

@@ -2,11 +2,18 @@
"""
探索 Telegram BOT 的功能
"""
import requests
import json
import os
import time
BOT_TOKEN = "8410096573:AAFLJbWUp2Xog0oeoe7hfBlVqR7ChoSl9Pg"
import requests
from env_loader import load_env
load_env()
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
if not BOT_TOKEN:
raise RuntimeError("请在 .env 中设置 TELEGRAM_BOT_TOKEN")
BASE_URL = f"https://api.telegram.org/bot{BOT_TOKEN}"
def get_bot_info():

View File

@@ -2,12 +2,19 @@
"""
交互式 Telegram BOT 测试工具
"""
import requests
import json
import time
import sys
import time
import os
BOT_TOKEN = "8410096573:AAFLJbWUp2Xog0oeoe7hfBlVqR7ChoSl9Pg"
import requests
from env_loader import load_env
load_env()
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
if not BOT_TOKEN:
raise RuntimeError("请在 .env 中设置 TELEGRAM_BOT_TOKEN")
BASE_URL = f"https://api.telegram.org/bot{BOT_TOKEN}"
# 这里需要你的 Telegram 用户 ID

View File

@@ -3,12 +3,19 @@
测试 funstat BOT 的所有命令
基于截图发现的功能
"""
import requests
import json
import time
import os
import sys
import time
BOT_TOKEN = "8410096573:AAFLJbWUp2Xog0oeoe7hfBlVqR7ChoSl9Pg"
import requests
from env_loader import load_env
load_env()
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
if not BOT_TOKEN:
raise RuntimeError("请在 .env 中设置 TELEGRAM_BOT_TOKEN")
BASE_URL = f"https://api.telegram.org/bot{BOT_TOKEN}"
# 测试用的免费 ID从 BOT 提供)

View File

@@ -2,11 +2,18 @@
"""
测试 BOT 的所有命令并获取响应
"""
import requests
import json
import os
import time
BOT_TOKEN = "8410096573:AAFLJbWUp2Xog0oeoe7hfBlVqR7ChoSl9Pg"
import requests
from env_loader import load_env
load_env()
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
if not BOT_TOKEN:
raise RuntimeError("请在 .env 中设置 TELEGRAM_BOT_TOKEN")
BASE_URL = f"https://api.telegram.org/bot{BOT_TOKEN}"
def get_updates(offset=None):